Adding more unit test

pull/4229/head
Medya Gh 2019-05-15 17:30:27 -07:00
parent 88a14890a8
commit a2590ecdb2
2 changed files with 30 additions and 0 deletions

View File

@ -67,6 +67,9 @@ func IsIPExcluded(ip string) bool {
// updateEnv appends an ip to the environment variable
func updateEnv(ip string, env string) error {
if ip == "" {
return fmt.Errorf("IP %s is blank. ", ip)
}
if !isValidEnv(env) {
return fmt.Errorf("%s is not a valid env var name for proxy settings", env)
}

View File

@ -72,5 +72,32 @@ func TestIsInBlock(t *testing.T) {
})
}
}
func TestUpdateEnv(t *testing.T) {
var testCases = []struct {
ip string
env string
wantErr bool
}{
{"192.168.0.13", "NO_PROXY", false},
{"", "NO_PROXY", true},
{"", "", true},
{"192.168.0.13", "", true},
{"192.168.0.13", "NPROXY", true},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%s in %s", tc.ip, tc.env), func(t *testing.T) {
gotErr := false
err := updateEnv(tc.ip, tc.env)
if err != nil {
gotErr = true
}
if gotErr != tc.wantErr {
t.Errorf("updateEnv(%v,%v) got error is %v ; want error is %v", tc.ip, tc.env, gotErr, tc.wantErr)
}
})
}
}