Skip to content

Commit

Permalink
More temp dir tests
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Koch <[email protected]>
  • Loading branch information
hugelgupf committed Feb 23, 2024
1 parent 6ad4c77 commit e098f5c
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions cmd/mkuimage/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ func hasTempDir(t *testing.T, output string) {
}
}

func dirExists(name string) func(t *testing.T, output string) {
return func(t *testing.T, output string) {
t.Helper()
if fi, err := os.Stat(name); err != nil {
t.Error(err)
} else if !fi.IsDir() {
t.Errorf("Stat(%s) = %v, want directory", name, fi)
}
}
}

func TestUrootCmdline(t *testing.T) {
wd, err := os.Getwd()
if err != nil {
Expand Down Expand Up @@ -71,6 +82,7 @@ func TestUrootCmdline(t *testing.T) {
if err = os.WriteFile(filepath.Join(sampledir, "bar"), nil, 0o644); err != nil {
t.Fatal(err)
}
tempDir := filepath.Join(t.TempDir(), "tempdir")

type testCase struct {
name string
Expand Down Expand Up @@ -212,6 +224,45 @@ func TestUrootCmdline(t *testing.T) {
"github.com/u-root/u-root/cmds/core/echo",
},
},
{
name: "build invalid",
args: []string{
"-build=source",
"github.com/u-root/u-root/cmds/core/init",
"github.com/u-root/u-root/cmds/core/echo",
},
exitCode: 1,
},
{
name: "build invalid",
args: []string{
"-build=source",
"github.com/u-root/u-root/cmds/core/init",
"github.com/u-root/u-root/cmds/core/echo",
},
exitCode: 1,
},
{
name: "arch invalid preserves temp dir",
env: []string{"GOARCH=doesnotexist"},
args: []string{
"--defaultsh=echo",
"github.com/u-root/u-root/cmds/core/echo",
"github.com/u-root/u-root/cmds/core/init",
},
exitCode: 1,
wantOutput: hasTempDir,
},
{
name: "specify temp dir",
args: []string{
"--temp-dir=" + tempDir,
"github.com/u-root/u-root/cmds/core/echo",
"github.com/u-root/u-root/cmds/core/init",
},
exitCode: 1,
wantOutput: dirExists(tempDir),
},
}

for _, tt := range append(noCmdTests, bareTests...) {
Expand Down

0 comments on commit e098f5c

Please sign in to comment.