@@ -14,7 +14,7 @@ def __init__(self, returncode, out=b"", err=b""):
14
14
self .err = err
15
15
16
16
def communicate (self ):
17
- return ( self .out , self .err )
17
+ return self .out , self .err
18
18
19
19
20
20
class TestGoRuntimeValidator (TestCase ):
@@ -30,38 +30,50 @@ def test_runtime_validate_unsupported_language_fail_open(self):
30
30
validator = GoRuntimeValidator (runtime = "go2.x" )
31
31
validator .validate (runtime_path = "/usr/bin/go2" )
32
32
33
+ @parameterized .expand (
34
+ [
35
+ ("go1.11.2" , (1 , 11 )),
36
+ ("go1.11rc.2" , (1 , 11 )),
37
+ ("go1.16beta1" , (1 , 16 )),
38
+ ("go%$" , (0 , 0 )),
39
+ ("unknown" , (0 , 0 )),
40
+ ]
41
+ )
42
+ def test_get_go_versions (self , version_string , version_parts ):
43
+ self .assertEqual (self .validator .get_go_versions (version_string ), version_parts )
44
+
33
45
@parameterized .expand (
34
46
[(b"go version go1.11.2 test" ,), (b"go version go1.11rc.2 test" ,), (b"go version go1.16beta1 test" ,)]
35
47
)
36
48
def test_runtime_validate_supported_version_runtime (self , go_version_output ):
37
49
with mock .patch ("subprocess.Popen" ) as mock_subprocess :
38
50
mock_subprocess .return_value = MockSubProcess (0 , out = go_version_output )
39
51
self .validator .validate (runtime_path = "/usr/bin/go" )
40
- self .assertTrue (mock_subprocess .call_count , 1 )
52
+ self .assertEqual (mock_subprocess .call_count , 1 )
41
53
42
54
def test_runtime_validate_supported_higher_than_min_version_runtime (self ):
43
55
with mock .patch ("subprocess.Popen" ) as mock_subprocess :
44
56
mock_subprocess .return_value = MockSubProcess (0 , out = b"go version go1.12 test" )
45
57
self .validator .validate (runtime_path = "/usr/bin/go" )
46
- self .assertTrue (mock_subprocess .call_count , 1 )
58
+ self .assertEqual (mock_subprocess .call_count , 1 )
47
59
48
60
def test_runtime_validate_mismatch_nonzero_exit (self ):
49
61
with mock .patch ("subprocess.Popen" ) as mock_subprocess :
50
62
mock_subprocess .return_value = MockSubProcess (1 )
51
63
with self .assertRaises (MisMatchRuntimeError ):
52
64
self .validator .validate (runtime_path = "/usr/bin/go" )
53
- self .assertTrue (mock_subprocess .call_count , 1 )
65
+ self .assertEqual (mock_subprocess .call_count , 1 )
54
66
55
67
def test_runtime_validate_mismatch_invalid_version (self ):
56
68
with mock .patch ("subprocess.Popen" ) as mock_subprocess :
57
69
mock_subprocess .return_value = MockSubProcess (0 , out = b"go version" )
58
70
with self .assertRaises (MisMatchRuntimeError ):
59
71
self .validator .validate (runtime_path = "/usr/bin/go" )
60
- self .assertTrue (mock_subprocess .call_count , 1 )
72
+ self .assertEqual (mock_subprocess .call_count , 1 )
61
73
62
74
def test_runtime_validate_mismatch_minor_version (self ):
63
75
with mock .patch ("subprocess.Popen" ) as mock_subprocess :
64
76
mock_subprocess .return_value = MockSubProcess (0 , out = b"go version go1.10.2 test" )
65
77
with self .assertRaises (MisMatchRuntimeError ):
66
78
self .validator .validate (runtime_path = "/usr/bin/go" )
67
- self .assertTrue (mock_subprocess .call_count , 1 )
79
+ self .assertEqual (mock_subprocess .call_count , 1 )
0 commit comments