-
Notifications
You must be signed in to change notification settings - Fork 24
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 #153 from kubescape/bug_fix/repo_scan
add if for cases that the apiVersion is not string
- Loading branch information
Showing
2 changed files
with
56 additions
and
1 deletion.
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
50 changes: 50 additions & 0 deletions
50
objectsenvelopes/hostsensor/hostsensordataenvelope_test.go
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 |
---|---|---|
@@ -1 +1,51 @@ | ||
package hostsensor | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestIsTypeTypeHostSensor(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
object map[string]interface{} | ||
want bool | ||
}{ | ||
{ | ||
name: "valid apiVersion", | ||
object: map[string]interface{}{ | ||
"apiVersion": "hostdata.kubescape.cloud/v1", | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "apiVersion does not match GroupHostSensor", | ||
object: map[string]interface{}{ | ||
"apiVersion": "someOtherGroup/v1", | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "apiVersion is an integer", | ||
object: map[string]interface{}{ | ||
"apiVersion": 12345, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "missing apiVersion", | ||
object: map[string]interface{}{ | ||
"someOtherKey": "someValue", | ||
}, | ||
want: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := IsTypeTypeHostSensor(tt.object); got != tt.want { | ||
t.Errorf("%q: IsTypeTypeHostSensor() = %v, want %v", tt.name, got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|