fix: goctl unit test (#3636)

This commit is contained in:
kesonan
2023-10-17 19:15:32 +08:00
committed by GitHub
parent 87b7a1120d
commit d84dfe1b20
6 changed files with 29 additions and 21 deletions

View File

@@ -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)
}