Skip to content

Commit

Permalink
add TestVersioned
Browse files Browse the repository at this point in the history
Follow-up to LK4D4#87

Signed-off-by: Akihiro Suda <[email protected]>
  • Loading branch information
AkihiroSuda committed Jan 10, 2020
1 parent d385c05 commit a583118
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/vndr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,59 @@ func main(){})
t.Errorf("expected to clean some ignore files, list of files are kept %s", kept)
}
}

func TestVersioned(t *testing.T) {
vndrBin, err := exec.LookPath("vndr")
if err != nil {
t.Fatal(err)
}
tmp, err := ioutil.TempDir("", "test-vndr-")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmp)
repoDir := filepath.Join(tmp, "src", testRepo)
if err := os.MkdirAll(repoDir, 0700); err != nil {
t.Fatal(err)
}
content := []byte(`github.com/coreos/go-systemd/v22 v22.0.0
github.com/godbus/dbus/v5 v5.0.3
`)
if err := ioutil.WriteFile(filepath.Join(repoDir, "main.go"),
[]byte(`package foo
import (
"github.com/coreos/go-systemd/v22/dbus"
)
func Foo() (*dbus.Conn, error) {
return dbus.New()
}
`), 0644); err != nil {
t.Fatal(err)
}
vendorConf := filepath.Join(repoDir, "vendor.conf")
if err := ioutil.WriteFile(vendorConf, content, 0666); err != nil {
t.Fatal(err)
}
vndrCmd := exec.Command(vndrBin, "-verbose")
vndrCmd.Dir = repoDir
setGopath(vndrCmd, tmp)

out, err := vndrCmd.CombinedOutput()
t.Logf("Output of vndr:\n%s", out)
if err != nil {
t.Fatal(err)
}
// https://github.com/coreos/go-systemd/blob/v22.0.0/go.mod appears in this path
systemdV22GoModPath := filepath.Join(repoDir, "vendor/github.com/coreos/go-systemd/v22/go.mod")
systemdV22GoMod, err := ioutil.ReadFile(systemdV22GoModPath)
if err != nil {
t.Fatal(err)
}
t.Logf("content of %s:\n%s", systemdV22GoModPath, string(systemdV22GoMod))
systemdV22GoModHeader := "module github.com/coreos/go-systemd/v22"
if !strings.Contains(string(systemdV22GoMod), systemdV22GoModHeader) {
t.Fatalf("expected %s to contain %q", systemdV22GoModPath, systemdV22GoModHeader)
}
}

0 comments on commit a583118

Please sign in to comment.