Skip to content

Commit

Permalink
test: e2e test builds go-licenses in temp dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobgy committed Feb 24, 2022
1 parent 80f1b34 commit 1214633
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,19 @@ func TestCsvCommandE2E(t *testing.T) {
if err != nil {
t.Fatal(err)
}
// This builds and installs go-licenses CLI to $(go env GOPATH)/bin.
cmd := exec.Command("go", "install", ".")
// This builds go-licenses CLI to temporary dir.
tempDir, err := ioutil.TempDir("", "")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tempDir)
goLicensesPath := filepath.Join(tempDir, "go-licenses")
cmd := exec.Command("go", "build", "-o", goLicensesPath)
_, err = cmd.Output()
if err != nil {
t.Fatal(err)
}
t.Logf("Built go-licenses binary in %s.", goLicensesPath)
for _, tc := range tests {
t.Run(tc.workdir, func(t *testing.T) {
err := os.Chdir(filepath.Join(originalWorkDir, tc.workdir))
Expand All @@ -59,7 +66,7 @@ func TestCsvCommandE2E(t *testing.T) {
if err != nil {
t.Fatalf("downloading go modules:\n%s", string(log))
}
cmd = exec.Command("go-licenses", "csv", ".")
cmd = exec.Command(goLicensesPath, "csv", ".")
// Capture stderr to buffer.
var stderr bytes.Buffer
cmd.Stderr = &stderr
Expand Down

0 comments on commit 1214633

Please sign in to comment.