родитель
08fd49fe60
коммит
6b15a72895
1 изменённых файлов: 27 добавлений и 1 удалений
|
@ -122,7 +122,33 @@ func TestUnsetenv(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: add back TestClearenv() and fix the errors it finds
|
||||
func TestClearenv(t *testing.T) {
|
||||
const testKey = "GO_TEST_CLEARENV"
|
||||
const testValue = "1"
|
||||
|
||||
// reset env
|
||||
defer func(origEnv []string) {
|
||||
for _, pair := range origEnv {
|
||||
// Environment variables on Windows can begin with =
|
||||
// https://blogs.msdn.com/b/oldnewthing/archive/2010/05/06/10008132.aspx
|
||||
i := strings.Index(pair[1:], "=") + 1
|
||||
if err := Setenv(pair[:i], pair[i+1:]); err != nil {
|
||||
t.Errorf("Setenv(%q, %q) failed during reset: %v", pair[:i], pair[i+1:], err)
|
||||
}
|
||||
}
|
||||
}(Environ())
|
||||
|
||||
if err := Setenv(testKey, testValue); err != nil {
|
||||
t.Fatalf("Setenv(%q, %q) failed: %v", testKey, testValue, err)
|
||||
}
|
||||
if _, ok := LookupEnv(testKey); !ok {
|
||||
t.Errorf("Setenv(%q, %q) didn't set $%s", testKey, testValue, testKey)
|
||||
}
|
||||
Clearenv()
|
||||
if val, ok := LookupEnv(testKey); ok {
|
||||
t.Errorf("Clearenv() didn't clear $%s, remained with value %q", testKey, val)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLookupEnv(t *testing.T) {
|
||||
const smallpox = "SMALLPOX" // No one has smallpox.
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче