Skip to content

Commit

Permalink
Update pwd code in unit-test (#826)
Browse files Browse the repository at this point in the history
* Update pwd code in unit-test

Signed-off-by: Ian Lewis <[email protected]>

* Break wd check into separate function

Signed-off-by: Ian Lewis <[email protected]>

Signed-off-by: Ian Lewis <[email protected]>
  • Loading branch information
Ian Lewis authored Sep 8, 2022
1 parent 11f701a commit 65d43c9
Showing 1 changed file with 21 additions and 11 deletions.
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

0 comments on commit 65d43c9

Please sign in to comment.