Adding more unit test
parent
88a14890a8
commit
a2590ecdb2
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue