コード例 #1
0
ファイル: test_godeps.py プロジェクト: snapcore/snapcraft
    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/1.15/stable")))
コード例 #2
0
ファイル: test_godeps.py プロジェクト: snapcore/snapcraft
    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")))
コード例 #3
0
ファイル: test_godeps.py プロジェクト: snapcore/snapcraft
    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))
コード例 #4
0
ファイル: test_godeps.py プロジェクト: snapcore/snapcraft
    def test_build_environment(self):
        plugin = godeps.GodepsPlugin("test-part", self.options, self.project)

        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(6))
        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"]),
                )
コード例 #5
0
ファイル: test_godeps.py プロジェクト: snapcore/snapcraft
    def test_clean_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._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))
コード例 #6
0
ファイル: test_godeps.py プロジェクト: snapcore/snapcraft
    def test_pull(self):
        plugin = godeps.GodepsPlugin("test-part", self.options, self.project)

        os.makedirs(plugin.options.source)

        plugin.pull()

        assert self.run_mock.mock_calls == [
            mock.call(
                ["go", "get", "-d", "github.com/rogpeppe/godeps"],
                cwd=plugin._gopath_src,
                env=mock.ANY,
            ),
            mock.call(
                [
                    "git", "checkout",
                    "4e9e0ee19b60b13eb79915933f44d8ed5f268bdd"
                ],
                cwd=plugin._gopath_src + "/github.com/pelletier/go-toml",
                env=mock.ANY,
            ),
            mock.call(
                [
                    "git", "checkout",
                    "d6ce6262d87e3a4e153e86023ff56ae771554a41"
                ],
                cwd=plugin._gopath_src + "/github.com/kisielk/gotool",
                env=mock.ANY,
            ),
            mock.call(
                [
                    "git", "checkout",
                    "1937f90a1bb43667aff4059b1bab13eb15121e8e"
                ],
                cwd=plugin._gopath_src + "/golang.org/x/tools",
                env=mock.ANY,
            ),
            mock.call(
                ["go", "install", "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))