def test_clean_build(self): plugin = godeps.GodepsPlugin('test-part', self.options, self.project_options) os.makedirs(plugin.options.source) plugin.pull() os.makedirs(plugin._gopath_bin) os.makedirs(plugin._gopath_pkg) os.makedirs(plugin.builddir) plugin.build() self.assertTrue(os.path.exists(plugin._gopath)) self.assertTrue(os.path.exists(plugin._gopath_src)) self.assertTrue(os.path.exists(plugin._gopath_pkg)) self.assertTrue(os.path.exists(plugin._gopath_bin)) plugin.clean_build() self.assertTrue(os.path.exists(plugin._gopath)) self.assertTrue(os.path.exists(plugin._gopath_src)) self.assertFalse(os.path.exists(plugin._gopath_pkg)) self.assertFalse(os.path.exists(plugin._gopath_bin))
def test_pull(self): plugin = godeps.GodepsPlugin('test-part', self.options, self.project_options) os.makedirs(plugin.options.source) plugin.pull() self.assertEqual(2, self.run_mock.call_count) self.run_mock.assert_has_calls([ mock.call(['go', 'get', 'github.com/rogpeppe/godeps'], cwd=plugin._gopath_src, env=mock.ANY), mock.call([ 'godeps', '-t', '-u', os.path.join(plugin.sourcedir, self.options.godeps_file) ], cwd=plugin._gopath_src, env=mock.ANY), ]) self.assertTrue(os.path.exists(plugin._gopath)) self.assertTrue(os.path.exists(plugin._gopath_src)) self.assertFalse(os.path.exists(plugin._gopath_pkg)) self.assertFalse(os.path.exists(plugin._gopath_bin)) sourcedir = os.path.join(plugin._gopath_src, 'github.com', 'foo', 'bar') self.assertTrue(os.path.islink(sourcedir)) self.assertEqual(plugin.sourcedir, os.readlink(sourcedir))
def test_build(self): plugin = godeps.GodepsPlugin('test-part', self.options, self.project_options) os.makedirs(plugin.options.source) plugin.pull() os.makedirs(plugin._gopath_bin) os.makedirs(plugin.builddir) self.run_mock.reset_mock() open(os.path.join(plugin._gopath_bin, 'test-binary'), 'w').close() open(os.path.join(plugin._gopath_bin, 'godeps'), 'w').close() plugin.build() self.assertEqual(1, self.run_mock.call_count) self.run_mock.assert_has_calls([ mock.call(['go', 'install', './github.com/foo/bar/...'], cwd=plugin._gopath_src, env=mock.ANY), ]) self.assertTrue(os.path.exists(plugin._gopath)) self.assertTrue(os.path.exists(plugin._gopath_src)) self.assertTrue(os.path.exists(plugin._gopath_bin)) self.assertTrue( os.path.exists( os.path.join(plugin.installdir, 'bin', 'test-binary'))) # Assert that the godeps binary was NOT copied self.assertFalse( os.path.exists(os.path.join(plugin.installdir, 'bin', 'godeps')))
def test_build_packages(self): self.options.go_channel = "" plugin = godeps.GodepsPlugin("test-part", self.options, self.project) self.assertThat(plugin.build_packages, Contains("golang-go")) self.assertThat(plugin.build_snaps, Not(Contains("go/latest/stable")))
def test_build(self): plugin = godeps.GodepsPlugin("test-part", self.options, self.project) os.makedirs(plugin.options.source) plugin.pull() os.makedirs(plugin._gopath_bin) os.makedirs(plugin.builddir) self.run_mock.reset_mock() open(os.path.join(plugin._gopath_bin, "test-binary"), "w").close() open(os.path.join(plugin._gopath_bin, "godeps"), "w").close() plugin.build() self.assertThat(self.run_mock.call_count, Equals(1)) self.run_mock.assert_has_calls([ mock.call( ["go", "install", "./github.com/foo/bar/..."], cwd=plugin._gopath_src, env=mock.ANY, ) ]) self.assertTrue(os.path.exists(plugin._gopath)) self.assertTrue(os.path.exists(plugin._gopath_src)) self.assertTrue(os.path.exists(plugin._gopath_bin)) self.assertTrue( os.path.exists( os.path.join(plugin.installdir, "bin", "test-binary"))) # Assert that the godeps binary was NOT copied self.assertFalse( os.path.exists(os.path.join(plugin.installdir, "bin", "godeps")))
def test_pull(self): plugin = godeps.GodepsPlugin("test-part", self.options, self.project) os.makedirs(plugin.options.source) plugin.pull() self.assertThat(self.run_mock.call_count, Equals(2)) self.run_mock.assert_has_calls([ mock.call( ["go", "get", "github.com/rogpeppe/godeps"], cwd=plugin._gopath_src, env=mock.ANY, ), mock.call( [ "godeps", "-t", "-u", os.path.join(plugin.sourcedir, self.options.godeps_file), ], cwd=plugin._gopath_src, env=mock.ANY, ), ]) self.assertTrue(os.path.exists(plugin._gopath)) self.assertTrue(os.path.exists(plugin._gopath_src)) self.assertFalse(os.path.exists(plugin._gopath_pkg)) self.assertFalse(os.path.exists(plugin._gopath_bin)) sourcedir = os.path.join(plugin._gopath_src, "github.com", "foo", "bar") self.assertTrue(os.path.islink(sourcedir)) self.assertThat(os.readlink(sourcedir), Equals(plugin.sourcedir))
def test_clean_pull(self): plugin = godeps.GodepsPlugin("test-part", self.options, self.project) os.makedirs(plugin.options.source) plugin.pull() self.assertTrue(os.path.exists(plugin._gopath)) plugin.clean_pull() self.assertFalse(os.path.exists(plugin._gopath))
def test_build_environment(self): plugin = godeps.GodepsPlugin("test-part", self.options, self.project_options) os.makedirs(plugin.options.source) os.makedirs(os.path.join(plugin.installdir, "lib")) os.makedirs(os.path.join(plugin.installdir, "usr", "lib")) os.makedirs(os.path.join(plugin.project.stage_dir, "lib")) os.makedirs(os.path.join(plugin.project.stage_dir, "usr", "lib")) plugin.pull() self.assertThat(self.run_mock.call_count, Equals(2)) for call_args in self.run_mock.call_args_list: env = call_args[1]["env"] self.assertTrue("GOPATH" in env, "Expected environment to include GOPATH") self.assertThat(env["GOPATH"], Equals(plugin._gopath)) self.assertTrue("PATH" in env, "Expected environment to include PATH") self.assertTrue( os.path.join(plugin._gopath, "bin") in env["PATH"], "Expected $PATH to include $GOPATH/bin", ) self.assertTrue("CGO_LDFLAGS" in env, "Expected environment to include CGO_LDFLAGS") expected_flags = [ "-L{}/lib".format(plugin.installdir), "-L{}/usr/lib".format(plugin.installdir), "-L{}/lib".format(plugin.project.stage_dir), "-L{}/usr/lib".format(plugin.project.stage_dir), ] for flag in expected_flags: self.assertTrue( flag in env["CGO_LDFLAGS"], "Expected $CGO_LDFLAGS to include {!r}, but it was " '"{}"'.format(flag, env["CGO_LDFLAGS"]), )
def test_build_environment(self): plugin = godeps.GodepsPlugin( 'test-part', self.options, self.project_options) os.makedirs(plugin.options.source) os.makedirs(os.path.join(plugin.installdir, 'lib')) os.makedirs(os.path.join(plugin.installdir, 'usr', 'lib')) os.makedirs(os.path.join(plugin.project.stage_dir, 'lib')) os.makedirs(os.path.join(plugin.project.stage_dir, 'usr', 'lib')) plugin.pull() self.assertEqual(2, self.run_mock.call_count) for call_args in self.run_mock.call_args_list: env = call_args[1]['env'] self.assertTrue( 'GOPATH' in env, 'Expected environment to include GOPATH') self.assertEqual(env['GOPATH'], plugin._gopath) self.assertTrue( 'PATH' in env, 'Expected environment to include PATH') self.assertTrue( os.path.join(plugin._gopath, 'bin') in env['PATH'], 'Expected $PATH to include $GOPATH/bin') self.assertTrue( 'CGO_LDFLAGS' in env, 'Expected environment to include CGO_LDFLAGS') expected_flags = [ '-L{}/lib'.format(plugin.installdir), '-L{}/usr/lib'.format(plugin.installdir), '-L{}/lib'.format(plugin.project.stage_dir), '-L{}/usr/lib'.format(plugin.project.stage_dir), ] for flag in expected_flags: self.assertTrue( flag in env['CGO_LDFLAGS'], 'Expected $CGO_LDFLAGS to include {!r}, but it was ' '"{}"'.format(flag, env['CGO_LDFLAGS']))
def test_unsupported_base_using_snap(self): plugin = godeps.GodepsPlugin("test-part", self.options, self.project) self.assertThat(plugin.build_packages, Not(Contains("golang-go"))) self.assertThat(plugin.build_snaps, Contains("go/latest/stable"))