|
29 | 29 |
|
30 | 30 |
|
31 | 31 | class CliInvocationTests(unittest.TestCase):
|
32 |
| - runner = CliRunner() |
33 |
| - |
34 |
| - @in_tempdir |
35 |
| - def test_gradle_invocation(self): |
36 |
| - args = ['--arg1', 'task1'] |
37 |
| - create_artifacts( |
38 |
| - Artifact( |
39 |
| - 'gradlew', |
40 |
| - content=scripts.with_expected_arguments_and_artifacts( |
41 |
| - ['./gradlew'] + args, |
42 |
| - {'GRADLE_OPTS': 'opts'}, |
43 |
| - ('sdk1/build/output/file1', 'content1'), |
44 |
| - ('sdk1/build/outputss/file2', 'content2'), |
45 |
| - ), |
46 |
| - mode=0o744)) |
47 |
| - result = self.runner.invoke(cli, [ |
48 |
| - '--artifact-patterns', '**/build/output', 'gradle', '--gradle-opts', |
49 |
| - 'opts', '--' |
50 |
| - ] + args) |
51 |
| - self.assertEqual(result.exit_code, 0) |
52 |
| - |
53 |
| - artifacts = pathlib.Path('_artifacts') |
54 |
| - self.assertTrue(artifacts.exists()) |
55 |
| - |
56 |
| - output_file = artifacts / 'sdk1_build_outputss' / 'file2' |
57 |
| - self.assertFalse(output_file.exists()) |
58 |
| - |
59 |
| - output_file = artifacts / 'sdk1_build_output' / 'file1' |
60 |
| - self.assertTrue(output_file.is_file()) |
61 |
| - |
62 |
| - with output_file.open() as f: |
63 |
| - self.assertEqual(f.read(), 'content1') |
64 |
| - |
65 |
| - @in_tempdir |
66 |
| - def test_smoke_test_when_build_fails_should_fail(self): |
67 |
| - create_artifacts( |
68 |
| - Artifact('gradlew', content=scripts.with_exit(1), mode=0o744)) |
69 |
| - result = self.runner.invoke(cli, ['smoke_tests']) |
70 |
| - self.assertNotEqual(result.exit_code, 0) |
71 |
| - |
72 |
| - @in_tempdir |
73 |
| - def test_smoke_test_when_build_succeeds_and_tests_fails_should_fail(self): |
74 |
| - create_artifacts( |
75 |
| - Artifact('gradlew', content=scripts.with_exit(0), mode=0o744), |
76 |
| - Artifact('test-apps/gradlew', content=scripts.with_exit(1), mode=0o744), |
77 |
| - ) |
78 |
| - result = self.runner.invoke(cli, ['smoke_tests']) |
79 |
| - self.assertNotEqual(result.exit_code, 0) |
80 |
| - |
81 |
| - @in_tempdir |
82 |
| - def test_smoke_test_when_build_succeeds_and_tests_succeed_should_succeed(self): |
83 |
| - create_artifacts( |
84 |
| - Artifact('gradlew', content=scripts.with_exit(0), mode=0o744), |
85 |
| - Artifact('test-apps/gradlew', content=scripts.with_exit(0), mode=0o744), |
86 |
| - ) |
87 |
| - result = self.runner.invoke(cli, ['smoke_tests']) |
88 |
| - self.assertEqual(result.exit_code, 0) |
89 |
| - |
90 |
| - @in_tempdir |
91 |
| - def test_smoke_test_no_buildType_should_invoke_gradle_with_release_build_type(self): |
92 |
| - create_artifacts( |
93 |
| - Artifact( |
94 |
| - 'gradlew', |
95 |
| - content=scripts.with_expected_arguments( |
96 |
| - ['./gradlew', 'publishAllToBuildDir']), |
97 |
| - mode=0o744), |
98 |
| - Artifact( |
99 |
| - 'test-apps/gradlew', |
100 |
| - content=scripts.with_expected_arguments( |
101 |
| - ['./gradlew', 'connectedCheck', '-PtestBuildType=release'], { |
102 |
| - 'GRADLE_OPTS': |
103 |
| - '-Dmaven.repo.local={}'.format( |
104 |
| - os.path.join(os.getcwd(), 'build', 'm2repository')) |
105 |
| - }), |
106 |
| - mode=0o744), |
107 |
| - ) |
108 |
| - result = self.runner.invoke(cli, ['smoke_tests']) |
109 |
| - self.assertEqual(result.exit_code, 0) |
110 |
| - |
111 |
| - @in_tempdir |
112 |
| - def test_smoke_test_with_buildType_should_invoke_gradle_with_release_build_type(self): |
113 |
| - create_artifacts( |
114 |
| - Artifact( |
115 |
| - 'gradlew', |
116 |
| - content=scripts.with_expected_arguments( |
117 |
| - ['./gradlew', 'publishAllToBuildDir']), |
118 |
| - mode=0o744), |
119 |
| - Artifact( |
120 |
| - 'test-apps/gradlew', |
121 |
| - content=scripts.with_expected_arguments( |
122 |
| - ['./gradlew', 'connectedCheck', '-PtestBuildType=debug'], { |
123 |
| - 'GRADLE_OPTS': |
124 |
| - '-Dmaven.repo.local={}'.format( |
125 |
| - os.path.join(os.getcwd(), 'build', 'm2repository')) |
126 |
| - }), |
127 |
| - mode=0o744), |
128 |
| - ) |
129 |
| - result = self.runner.invoke(cli, ['smoke_tests', '--app-build-variant', 'debug']) |
130 |
| - self.assertEqual(result.exit_code, 0) |
131 |
| - |
| 32 | + runner = CliRunner() |
| 33 | + |
| 34 | + @in_tempdir |
| 35 | + def test_gradle_invocation(self): |
| 36 | + args = ['--arg1', 'task1'] |
| 37 | + create_artifacts( |
| 38 | + Artifact( |
| 39 | + 'gradlew', |
| 40 | + content=scripts.with_expected_arguments_and_artifacts( |
| 41 | + ['./gradlew'] + args, |
| 42 | + {'GRADLE_OPTS': 'opts'}, |
| 43 | + ('sdk1/build/output/file1', 'content1'), |
| 44 | + ('sdk1/build/outputss/file2', 'content2'), |
| 45 | + ), |
| 46 | + mode=0o744)) |
| 47 | + result = self.runner.invoke(cli, [ |
| 48 | + '--artifact-patterns', '**/build/output', 'gradle', '--gradle-opts', |
| 49 | + 'opts', '--' |
| 50 | + ] + args) |
| 51 | + self.assertEqual(result.exit_code, 0) |
| 52 | + |
| 53 | + artifacts = pathlib.Path('_artifacts') |
| 54 | + self.assertTrue(artifacts.exists()) |
| 55 | + |
| 56 | + output_file = artifacts / 'sdk1_build_outputss' / 'file2' |
| 57 | + self.assertFalse(output_file.exists()) |
| 58 | + |
| 59 | + output_file = artifacts / 'sdk1_build_output' / 'file1' |
| 60 | + self.assertTrue(output_file.is_file()) |
| 61 | + |
| 62 | + with output_file.open() as f: |
| 63 | + self.assertEqual(f.read(), 'content1') |
| 64 | + |
| 65 | + @in_tempdir |
| 66 | + def test_smoke_test_when_build_fails_should_fail(self): |
| 67 | + create_artifacts( |
| 68 | + Artifact('gradlew', content=scripts.with_exit(1), mode=0o744)) |
| 69 | + result = self.runner.invoke(cli, ['smoke_tests']) |
| 70 | + self.assertNotEqual(result.exit_code, 0) |
| 71 | + |
| 72 | + @in_tempdir |
| 73 | + def test_smoke_test_when_build_succeeds_and_tests_fails_should_fail(self): |
| 74 | + create_artifacts( |
| 75 | + Artifact('gradlew', content=scripts.with_exit(0), mode=0o744), |
| 76 | + Artifact('test-apps/gradlew', content=scripts.with_exit(1), mode=0o744), |
| 77 | + ) |
| 78 | + result = self.runner.invoke(cli, ['smoke_tests']) |
| 79 | + self.assertNotEqual(result.exit_code, 0) |
| 80 | + |
| 81 | + @in_tempdir |
| 82 | + def test_smoke_test_when_build_succeeds_and_tests_succeed_should_succeed( |
| 83 | + self): |
| 84 | + create_artifacts( |
| 85 | + Artifact('gradlew', content=scripts.with_exit(0), mode=0o744), |
| 86 | + Artifact('test-apps/gradlew', content=scripts.with_exit(0), mode=0o744), |
| 87 | + ) |
| 88 | + result = self.runner.invoke(cli, ['smoke_tests']) |
| 89 | + self.assertEqual(result.exit_code, 0) |
| 90 | + |
| 91 | + @in_tempdir |
| 92 | + def test_smoke_test_no_buildType_should_invoke_gradle_with_release_build_type( |
| 93 | + self): |
| 94 | + create_artifacts( |
| 95 | + Artifact( |
| 96 | + 'gradlew', |
| 97 | + content=scripts.with_expected_arguments( |
| 98 | + ['./gradlew', 'publishAllToBuildDir']), |
| 99 | + mode=0o744), |
| 100 | + Artifact( |
| 101 | + 'test-apps/gradlew', |
| 102 | + content=scripts.with_expected_arguments( |
| 103 | + ['./gradlew', 'connectedCheck', '-PtestBuildType=release'], { |
| 104 | + 'GRADLE_OPTS': |
| 105 | + '-Dmaven.repo.local={}'.format( |
| 106 | + os.path.join(os.getcwd(), 'build', 'm2repository')) |
| 107 | + }), |
| 108 | + mode=0o744), |
| 109 | + ) |
| 110 | + result = self.runner.invoke(cli, ['smoke_tests']) |
| 111 | + self.assertEqual(result.exit_code, 0) |
| 112 | + |
| 113 | + @in_tempdir |
| 114 | + def test_smoke_test_with_buildType_should_invoke_gradle_with_release_build_type( |
| 115 | + self): |
| 116 | + create_artifacts( |
| 117 | + Artifact( |
| 118 | + 'gradlew', |
| 119 | + content=scripts.with_expected_arguments( |
| 120 | + ['./gradlew', 'publishAllToBuildDir']), |
| 121 | + mode=0o744), |
| 122 | + Artifact( |
| 123 | + 'test-apps/gradlew', |
| 124 | + content=scripts.with_expected_arguments( |
| 125 | + ['./gradlew', 'connectedCheck', '-PtestBuildType=debug'], { |
| 126 | + 'GRADLE_OPTS': |
| 127 | + '-Dmaven.repo.local={}'.format( |
| 128 | + os.path.join(os.getcwd(), 'build', 'm2repository')) |
| 129 | + }), |
| 130 | + mode=0o744), |
| 131 | + ) |
| 132 | + result = self.runner.invoke(cli, |
| 133 | + ['smoke_tests', '--app-build-variant', 'debug']) |
| 134 | + self.assertEqual(result.exit_code, 0) |
0 commit comments