-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: exclude node by label Signed-off-by: chenk <[email protected]> * feat: exclude node by label Signed-off-by: chenk <[email protected]> --------- Signed-off-by: chenk <[email protected]>
- Loading branch information
1 parent
f725fa7
commit 250729b
Showing
2 changed files
with
46 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
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,43 @@ | ||
package trivyk8s | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aquasecurity/trivy-kubernetes/pkg/artifacts" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIgnoreNodeByLabel(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
ignoredLabels map[string]string | ||
artifact *artifacts.Artifact | ||
want bool | ||
}{ | ||
{ | ||
name: "no ignore labels", | ||
ignoredLabels: map[string]string{}, | ||
artifact: &artifacts.Artifact{Labels: map[string]string{"a": "b"}}, | ||
want: false, | ||
}, | ||
{ | ||
name: "matching ignore labels", | ||
ignoredLabels: map[string]string{"a": "b"}, | ||
artifact: &artifacts.Artifact{Labels: map[string]string{"a": "b"}}, | ||
want: true, | ||
}, | ||
{ | ||
name: "non matching ignore labels", | ||
ignoredLabels: map[string]string{"a": "b", "c": "d"}, | ||
artifact: &artifacts.Artifact{Labels: map[string]string{"a": "b"}}, | ||
want: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := ignoreNodeByLabel(tt.artifact, tt.ignoredLabels) | ||
assert.Equal(t, got, tt.want) | ||
}) | ||
} | ||
} |