Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
check error for os.Setenv in parse_test.go (#472)
Browse files Browse the repository at this point in the history
Add some missing error checks for the os.SetEnv() 
method in mockgen/parse_test.go.

Fixes: #473
  • Loading branch information
antcs authored Aug 18, 2020
1 parent 11d9cab commit 7b53c4d
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions mockgen/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ func TestParsePackageImport(t *testing.T) {
} {
t.Run(testCase.name, func(t *testing.T) {
for key, value := range testCase.envs {
os.Setenv(key, value)
if err := os.Setenv(key, value); err != nil {
t.Fatalf("unable to set environment variable %q to %q: %v", key, value, err)
}
}
pkgPath, err := parsePackageImport(filepath.Clean(testCase.dir))
if err != testCase.err {
Expand Down Expand Up @@ -195,8 +197,16 @@ func TestParsePackageImport_FallbackGoPath(t *testing.T) {
if err != nil {
t.Error(err)
}
os.Setenv("GOPATH", goPath)
os.Setenv("GO111MODULE", "on")
key := "GOPATH"
value := goPath
if err := os.Setenv(key, value); err != nil {
t.Fatalf("unable to set environment variable %q to %q: %v", key, value, err)
}
key = "GO111MODULE"
value = "on"
if err := os.Setenv(key, value); err != nil {
t.Fatalf("unable to set environment variable %q to %q: %v", key, value, err)
}
pkgPath, err := parsePackageImport(srcDir)
expected := "example.com/foo"
if pkgPath != expected {
Expand Down Expand Up @@ -237,8 +247,16 @@ func TestParsePackageImport_FallbackMultiGoPath(t *testing.T) {
}()

goPaths := strings.Join(goPathList, string(os.PathListSeparator))
os.Setenv("GOPATH", goPaths)
os.Setenv("GO111MODULE", "on")
key := "GOPATH"
value := goPaths
if err := os.Setenv(key, value); err != nil {
t.Fatalf("unable to set environment variable %q to %q: %v", key, value, err)
}
key = "GO111MODULE"
value = "on"
if err := os.Setenv(key, value); err != nil {
t.Fatalf("unable to set environment variable %q to %q: %v", key, value, err)
}
pkgPath, err := parsePackageImport(srcDir)
expected := "example.com/foo"
if pkgPath != expected {
Expand Down

0 comments on commit 7b53c4d

Please sign in to comment.