Skip to content

Update pwd code in unit-test #826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions internal/builders/go/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io"
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"testing"
Expand All @@ -23,6 +22,26 @@ func errCmp(e1, e2 error) bool {
return errors.Is(e1, e2) || errors.Is(e2, e1)
}

func checkWorkingDir(t *testing.T, wd, expected string) {
var expectedWd string
var err error
if expected != "" {
expectedWd, err = filepath.Abs(expected)
if err != nil {
t.Errorf("Abs: %v", err)
}
} else {
expectedWd, err = os.Getwd()
if err != nil {
t.Errorf("Getwd: %v", err)
}
}

if expectedWd != wd {
t.Errorf(cmp.Diff(wd, expectedWd))
}
}

func Test_runBuild(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -309,16 +328,7 @@ func Test_runBuild(t *testing.T) {
t.Errorf(cmp.Diff(cmd, commands))
}

var expectedWd string
if tt.workingDir == "" {
expectedWd = os.Getenv("PWD")
} else {
expectedWd = path.Join(os.Getenv("PWD"), tt.workingDir)
}

if expectedWd != wd {
t.Errorf(cmp.Diff(wd, expectedWd))
}
checkWorkingDir(t, wd, tt.workingDir)

sorted := cmpopts.SortSlices(func(a, b string) bool { return a < b })
if !cmp.Equal(env, tt.envs, sorted) {
Expand Down