improve function comment and move env var restoration to main test

pull/5228/head
Marcin Niemira 2019-08-30 00:07:13 +10:00
parent 8a02235668
commit 6dac0467c7
No known key found for this signature in database
GPG Key ID: 5395D4A81A3FA475
2 changed files with 15 additions and 15 deletions

View File

@ -55,7 +55,7 @@ func isInBlock(ip string, block string) (bool, error) {
return false, errors.Wrapf(err, "Error ip not in block")
}
// ExcludeIP will exclude the ip from the http(s)_proxy
// ExcludeIP takes ip or CIDR as string and excludes the it from the http(s)_proxy
func ExcludeIP(ip string) error {
if netIP := net.ParseIP(ip); netIP == nil {
if _, _, err := net.ParseCIDR(ip); err != nil {

View File

@ -162,14 +162,14 @@ func TestIsIPExcluded(t *testing.T) {
{"foo", "1.2.3.4", false},
}
for _, tc := range testCases {
originalEnv := os.Getenv("NO_PROXY")
defer func() { // revert to pre-test env var
err := os.Setenv("NO_PROXY", originalEnv)
if err != nil {
t.Fatalf("Error reverting env NO_PROXY to its original value (%s) var after test ", originalEnv)
}
}()
t.Run(fmt.Sprintf("exclude %s NO_PROXY(%v)", tc.ip, tc.env), func(t *testing.T) {
originalEnv := os.Getenv("NO_PROXY")
defer func() { // revert to pre-test env var
err := os.Setenv("NO_PROXY", originalEnv)
if err != nil {
t.Fatalf("Error reverting env NO_PROXY to its original value (%s) var after test ", originalEnv)
}
}()
if err := os.Setenv("NO_PROXY", tc.env); err != nil {
t.Errorf("Error during setting env: %v", err)
}
@ -192,15 +192,15 @@ func TestExcludeIP(t *testing.T) {
{"foo", "", true},
{"foo", "1.2.3.4", true},
}
originalEnv := os.Getenv("NO_PROXY")
defer func() { // revert to pre-test env var
err := os.Setenv("NO_PROXY", originalEnv)
if err != nil {
t.Fatalf("Error reverting env NO_PROXY to its original value (%s) var after test ", originalEnv)
}
}()
for _, tc := range testCases {
t.Run(fmt.Sprintf("exclude %s NO_PROXY(%s)", tc.ip, tc.env), func(t *testing.T) {
originalEnv := os.Getenv("NO_PROXY")
defer func() { // revert to pre-test env var
err := os.Setenv("NO_PROXY", originalEnv)
if err != nil {
t.Fatalf("Error reverting env NO_PROXY to its original value (%s) var after test ", originalEnv)
}
}()
if err := os.Setenv("NO_PROXY", tc.env); err != nil {
t.Errorf("Error during setting env: %v", err)
}