Mercurial > hg
annotate tests/test-sshserver.py @ 35752:047581ddb6ce
sshserver: add a couple of tests for argument parsing
I noticed that we didn't have any unit tests covering wire protocol argument
parsing.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Fri, 19 Jan 2018 14:25:09 -0800 |
parents | |
children | 7764ff13318e |
rev | line source |
---|---|
35752
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
1 from __future__ import absolute_import, print_function |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
2 |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
3 import io |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
4 import unittest |
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 import silenttestrunner |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
7 |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
8 from mercurial import ( |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
9 sshserver, |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
10 wireproto, |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
11 ) |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
12 |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
13 class SSHServerGetArgsTests(unittest.TestCase): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
14 def testparseknown(self): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
15 tests = [ |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
16 ('* 0\nnodes 0\n', ['', {}]), |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
17 ('* 0\nnodes 40\n1111111111111111111111111111111111111111\n', |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
18 ['1111111111111111111111111111111111111111', {}]), |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
19 ] |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
20 for input, expected in tests: |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
21 self.assertparse('known', input, expected) |
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 def assertparse(self, cmd, input, expected): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
24 server = mockserver(input) |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
25 _func, spec = wireproto.commands[cmd] |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
26 self.assertEqual(server.getargs(spec), expected) |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
27 |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
28 def mockserver(inbytes): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
29 ui = mockui(inbytes) |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
30 repo = mockrepo(ui) |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
31 return sshserver.sshserver(ui, repo) |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
32 |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
33 class mockrepo(object): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
34 def __init__(self, ui): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
35 self.ui = ui |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
36 |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
37 class mockui(object): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
38 def __init__(self, inbytes): |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
39 self.fin = io.BytesIO(inbytes) |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
40 self.fout = io.BytesIO() |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
41 self.ferr = io.BytesIO() |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
42 |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
43 if __name__ == '__main__': |
047581ddb6ce
sshserver: add a couple of tests for argument parsing
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
44 silenttestrunner.main(__name__) |