Skip to content

Commit

Permalink
Fixed unit tests failing in Windows environment
Browse files Browse the repository at this point in the history
  • Loading branch information
nao1215 committed Sep 18, 2022
1 parent 005ad1b commit 05a1602
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
42 changes: 34 additions & 8 deletions cmd/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,39 @@ func Test_check(t *testing.T) {
stdout []string
}{
{
name: "not go install command in $GOBIN",
gobin: "./testdata/check_fail",
args: args{},
want: 1,
stdout: []string{},
},
}

if runtime.GOOS == "windows" {
tests = append(tests, struct {
name string
gobin string
args args
want int
stdout []string
}{
name: "detect old version command",
gobin: "./testdata/check_success_for_windows",
args: args{},
want: 0,
stdout: []string{
" $ gup update gal posixer ",
"",
},
})
} else {
tests = append(tests, struct {
name string
gobin string
args args
want int
stdout []string
}{
name: "detect old version command",
gobin: "./testdata/check_success",
args: args{},
Expand All @@ -35,14 +68,7 @@ func Test_check(t *testing.T) {
" $ gup update subaru gal posixer ",
"",
},
},
{
name: "not go install command in $GOBIN",
gobin: "./testdata/check_fail",
args: args{},
want: 1,
stdout: []string{},
},
})
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
16 changes: 13 additions & 3 deletions cmd/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,22 @@ func Test_removeLoop(t *testing.T) {
t.Fatal(err)
}

newFile, err := os.Create("./testdata/delete/posixer")
src := ""
dest := ""
if runtime.GOOS == "windows" {
src = "./testdata/check_success_for_windows/posixer.exe"
dest = "./testdata/delete/posixer.exe"
} else {
src = "./testdata/check_success/posixer"
dest = "./testdata/delete/posixer"

}
newFile, err := os.Create(dest)
if err != nil {
t.Fatal(err)
}

oldFile, err := os.Open("./testdata/check_success/posixer")
oldFile, err := os.Open(src)
if err != nil {
t.Fatal(err)
}
Expand All @@ -265,7 +275,7 @@ func Test_removeLoop(t *testing.T) {
t.Fatal(err)
}
defer func() {
os.Remove("./testdata/delete/posixer")
os.Remove(dest)
}()

funcDefer, err := mockStdin(t, tt.input)
Expand Down

0 comments on commit 05a1602

Please sign in to comment.