tests/test-sshserver.py
author C. Masloch <pushbx@ulukai.org>
Wed, 20 Apr 2022 19:24:39 +0200
changeset 49473 cfff73cab721
parent 49037 642e31cb55f0
child 51483 13c004b54cbe
permissions -rw-r--r--
rebase: add boolean config item rebase.store-source This allows to use rebase without recording a rebase_source extra field. This is useful for example to build a mirror converted from another SCM (such as svn) by converting only new revisions, and then incrementally add them to the destination by pulling from the newly converted (unrelated) repo and rebasing the new revisions onto the last old already stored changeset. Without this patch the rebased changesets would always receive some rebase_source that would depend on the particular history of the conversion process, instead of only depending on the original source revisions. This is used to implement a hg mirror repo of SvarDOS (a partially nonfree but completely redistributable DOS distribution) in the scripts at https://hg.pushbx.org/ecm/svardos.scr/ In particular, cre.sh creates an svn mirror, upd.sh recreates an entire hg repo from the svn mirror (which takes too long to do in a regular job), and akt.sh uses hg convert with the config item convert.svn.startrev to incrementally convert only the two most recent revisions already found in the mirror destination plus any possible new revisions. If any are found, the temporary repo's changesets are pulled into the destination (as changesets from an unrelated repository). Then the changesets corresponding to the new revisions are rebased onto the prior final changeset. (Finally, the two remaining duplicates of the prior head and its parent are stripped from the destination repository.) Without this patch, the particular rebase_source extra field would depend on the order and times at which akt.sh was used, instead of only depending on the source repository. In other words, whatever sequence of upd.sh and akt.sh is used at whatever times, it is desired that the final output repositories always match each other exactly.
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__)