fix: goctl unit test (#3636)
This commit is contained in:
9
tools/goctl/pkg/env/env.go
vendored
9
tools/goctl/pkg/env/env.go
vendored
@@ -7,6 +7,7 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/zeromicro/go-zero/tools/goctl/internal/version"
|
||||
sortedmap "github.com/zeromicro/go-zero/tools/goctl/pkg/collection"
|
||||
@@ -111,6 +112,14 @@ func Get(key string) string {
|
||||
return GetOr(key, "")
|
||||
}
|
||||
|
||||
// Set sets the environment variable for testing
|
||||
func Set(t *testing.T, key, value string) {
|
||||
goctlEnv.SetKV(key, value)
|
||||
t.Cleanup(func() {
|
||||
goctlEnv.Remove(key)
|
||||
})
|
||||
}
|
||||
|
||||
func GetOr(key, def string) string {
|
||||
return goctlEnv.GetStringOr(key, def)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user