def test_generate_script_golden(self): config_name = 'cloudbuild_ok.yaml' config = os.path.join(self.testdata_dir, config_name) expected_output_script = os.path.join(self.testdata_dir, config_name + '_golden.sh') cloudbuild = local_cloudbuild.CloudBuild( output_script='test_generate_script', run=False, steps=[ local_cloudbuild.Step( args=['/bin/sh', '-c', 'printenv MESSAGE'], dir_='', env=['MESSAGE=Hello World!'], name='debian', ), local_cloudbuild.Step( args=['/bin/sh', '-c', 'printenv MESSAGE'], dir_='', env=['MESSAGE=Goodbye\\n And Farewell!', 'UNUSED=unused'], name='debian', ) ], substitutions=local_cloudbuild.DEFAULT_SUBSTITUTIONS, ) actual = local_cloudbuild.generate_script(cloudbuild) self.maxDiff = 2**16 # Compare output against golden with open(expected_output_script, 'r', encoding='utf8') as expected: self.assertEqual(actual, expected.read())
def test_generate_script_unused_user_substitution(self): cloudbuild = local_cloudbuild.CloudBuild( output_script='', run=False, steps=[], substitutions={'_FOO': '_foo'}, ) with self.assertRaisesRegex(ValueError, 'User substitution variables'): actual = local_cloudbuild.generate_script(cloudbuild)
def test_generate_script_unused_user_substitution(): cloudbuild = local_cloudbuild.CloudBuild( output_script='', run=False, steps=[], substitutions={'_FOO': '_foo'}, ) with pytest.raises(ValueError, match='User substitution variables'): local_cloudbuild.generate_script(cloudbuild)
def test_write_script(tmpdir): contents = 'The contents\n' output_script_filename = tmpdir.join('test_write_script') cloudbuild = local_cloudbuild.CloudBuild( output_script=str(output_script_filename), run=False, steps=[], substitutions={}, ) local_cloudbuild.write_script(cloudbuild, contents) with output_script_filename.open('r', encoding='utf8') as output_script: actual = output_script.read() assert actual == contents
def test_write_script(self): with tempfile.TemporaryDirectory( prefix='local_cloudbuild_test_') as tempdir: contents = 'The contents\n' output_script_filename = os.path.join(tempdir, 'test_write_script') cloudbuild = local_cloudbuild.CloudBuild( output_script=output_script_filename, run=False, steps=[], ) local_cloudbuild.write_script(cloudbuild, contents) with open(output_script_filename, 'r', encoding='utf8') as output_script: actual = output_script.read() self.assertEqual(actual, contents)