-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #743 from qiuming520/main
test: add testcase for utils
- Loading branch information
Showing
4 changed files
with
1,967 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// nolint:dupl | ||
package utils | ||
|
||
import "testing" | ||
|
||
// TestGetCIDRs tests the GetCIDRs function. | ||
func TestGetCIDRs(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
obj map[string]interface{} | ||
expected string | ||
}{ | ||
{ | ||
name: "nil input", | ||
obj: nil, | ||
expected: "", | ||
}, | ||
{ | ||
name: "empty map", | ||
obj: map[string]interface{}{}, | ||
expected: "", | ||
}, | ||
{ | ||
name: "missing spec", | ||
obj: map[string]interface{}{ | ||
"foo": "bar", | ||
}, | ||
expected: "", | ||
}, | ||
{ | ||
name: "spec is not a map", | ||
obj: map[string]interface{}{ | ||
"spec": "not-a-map", | ||
}, | ||
expected: "", | ||
}, | ||
{ | ||
name: "spec without cidr", | ||
obj: map[string]interface{}{ | ||
"spec": map[string]interface{}{ | ||
"foo": "bar", | ||
}, | ||
}, | ||
expected: "", | ||
}, | ||
{ | ||
name: "spec with cidr", | ||
obj: map[string]interface{}{ | ||
"spec": map[string]interface{}{ | ||
"cidr": "192.168.1.0/24", | ||
}, | ||
}, | ||
expected: "192.168.1.0/24", | ||
}, | ||
{ | ||
name: "spec with cidr as empty string", | ||
obj: map[string]interface{}{ | ||
"spec": map[string]interface{}{ | ||
"cidr": "", | ||
}, | ||
}, | ||
expected: "", | ||
}, | ||
{ | ||
name: "cidr is not a string", | ||
obj: map[string]interface{}{ | ||
"spec": map[string]interface{}{ | ||
"cidr": 12345, | ||
}, | ||
}, | ||
expected: "", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := GetCIDRs(tt.obj) | ||
if result != tt.expected { | ||
t.Errorf("expected %q, got %q", tt.expected, result) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.