Merge pull request #16787 from evanj/evan.jones/rm-unsetenv

osutil: remove unused Unsetenv function
This commit is contained in:
Benjamin Wang 2023-11-04 12:36:44 +00:00 committed by GitHub
commit d38f7dceb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 45 deletions

View File

@ -15,27 +15,7 @@
// Package osutil implements operating system-related utility functions.
package osutil
import (
"os"
"strings"
)
var (
// support to override setting SIG_DFL so tests don't terminate early
setDflSignal = dflSignal
)
func Unsetenv(key string) error {
envs := os.Environ()
os.Clearenv()
for _, e := range envs {
strs := strings.SplitN(e, "=", 2)
if strs[0] == key {
continue
}
if err := os.Setenv(strs[0], strs[1]); err != nil {
return err
}
}
return nil
}

View File

@ -17,7 +17,6 @@ package osutil
import (
"os"
"os/signal"
"reflect"
"syscall"
"testing"
"time"
@ -27,30 +26,6 @@ import (
func init() { setDflSignal = func(syscall.Signal) {} }
func TestUnsetenv(t *testing.T) {
tests := []string{
"data",
"space data",
"equal=data",
}
for i, tt := range tests {
key := "ETCD_UNSETENV_TEST"
if os.Getenv(key) != "" {
t.Fatalf("#%d: cannot get empty %s", i, key)
}
env := os.Environ()
if err := os.Setenv(key, tt); err != nil {
t.Fatalf("#%d: cannot set %s: %v", i, key, err)
}
if err := Unsetenv(key); err != nil {
t.Errorf("#%d: unsetenv %s error: %v", i, key, err)
}
if g := os.Environ(); !reflect.DeepEqual(g, env) {
t.Errorf("#%d: env = %+v, want %+v", i, g, env)
}
}
}
func waitSig(t *testing.T, c <-chan os.Signal, sig os.Signal) {
select {
case s := <-c: