tests/test-sshserver.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Thu, 16 Feb 2023 04:02:36 +0100
changeset 50140 ff12f42415f5
parent 49037 642e31cb55f0
child 51483 13c004b54cbe
permissions -rw-r--r--
localrepo: stop doing special dirstate backup at transaction open Since the dirstate writes are already managed by the transaction, we already do a backup of the dirstate when necessary (and even trigger one to keep `hg rollback` happy). We needs some special code to deal with the initial empty checkout, but it is not too complicated. Managing variable filename (as dirstate-v2 uses) at the "journalfile" level, is complex and fragile (which is consistent with the fact these files are not journal…). If we no longer do it, our life is significantly simpler. In some sense, we apply the xkcd-1134¹ solution to our savebackup/restorebackup problem. [1] https://xkcd.com/1134/ (the change to test-hardlink are expect as decreasing the number of duplicated backup drive the hardlink count down)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35752
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
     1
import io
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
     2
import unittest
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
     3
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
     4
import silenttestrunner
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
     5
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
     6
from mercurial import (
35899
1bf5263fe5cc wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35772
diff changeset
     7
    wireprotoserver,
37785
b4d85bc122bd wireproto: rename wireproto to wireprotov1server (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37123
diff changeset
     8
    wireprotov1server,
35752
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
     9
)
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    10
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41285
diff changeset
    11
from mercurial.utils import procutil
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41285
diff changeset
    12
37123
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36252
diff changeset
    13
35752
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    14
class SSHServerGetArgsTests(unittest.TestCase):
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    15
    def testparseknown(self):
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    16
        tests = [
36250
7a46f0735904 py3: add b'' to test-sshserver.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36103
diff changeset
    17
            (b'* 0\nnodes 0\n', [b'', {}]),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41285
diff changeset
    18
            (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41285
diff changeset
    19
                b'* 0\nnodes 40\n1111111111111111111111111111111111111111\n',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41285
diff changeset
    20
                [b'1111111111111111111111111111111111111111', {}],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41285
diff changeset
    21
            ),
35752
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    22
        ]
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    23
        for input, expected in tests:
36250
7a46f0735904 py3: add b'' to test-sshserver.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36103
diff changeset
    24
            self.assertparse(b'known', input, expected)
35752
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    25
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    26
    def assertparse(self, cmd, input, expected):
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    27
        server = mockserver(input)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41285
diff changeset
    28
        proto = wireprotoserver.sshv1protocolhandler(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41285
diff changeset
    29
            server._ui, server._fin, server._fout
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41285
diff changeset
    30
        )
37785
b4d85bc122bd wireproto: rename wireproto to wireprotov1server (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37123
diff changeset
    31
        _func, spec = wireprotov1server.commands[cmd]
36252
3b3a987bbbaa wireprotoserver: move SSH server operation to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36250
diff changeset
    32
        self.assertEqual(proto.getargs(spec), expected)
35752
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    33
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41285
diff changeset
    34
35752
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    35
def mockserver(inbytes):
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    36
    ui = mockui(inbytes)
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    37
    repo = mockrepo(ui)
35899
1bf5263fe5cc wireprotoserver: move sshserver into module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35772
diff changeset
    38
    return wireprotoserver.sshserver(ui, repo)
35752
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    39
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41285
diff changeset
    40
49037
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
    41
class mockrepo:
35752
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    42
    def __init__(self, ui):
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    43
        self.ui = ui
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    44
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41285
diff changeset
    45
49037
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
    46
class mockui:
35752
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    47
    def __init__(self, inbytes):
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    48
        self.fin = io.BytesIO(inbytes)
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    49
        self.fout = io.BytesIO()
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    50
        self.ferr = io.BytesIO()
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    51
41285
cf8677cd7286 ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents: 37785
diff changeset
    52
    def protectfinout(self):
cf8677cd7286 ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents: 37785
diff changeset
    53
        return self.fin, self.fout
cf8677cd7286 ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents: 37785
diff changeset
    54
cf8677cd7286 ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents: 37785
diff changeset
    55
    def restorefinout(self, fin, fout):
cf8677cd7286 ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents: 37785
diff changeset
    56
        pass
cf8677cd7286 ui: proxy protect/restorestdio() calls to update internal flag
Yuya Nishihara <yuya@tcha.org>
parents: 37785
diff changeset
    57
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41285
diff changeset
    58
35752
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    59
if __name__ == '__main__':
35772
7764ff13318e test-sshserver: stabilize for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 35752
diff changeset
    60
    # Don't call into msvcrt to set BytesIO to binary mode
37123
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36252
diff changeset
    61
    procutil.setbinary = lambda fp: True
35752
047581ddb6ce sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    62
    silenttestrunner.main(__name__)