Skip to content

Commit

Permalink
add test for util/Match function (vmware#289)
Browse files Browse the repository at this point in the history
Signed-off-by: huskykurt <[email protected]>
  • Loading branch information
huskykurt authored and kurt.ryu committed Dec 14, 2022
1 parent f0131e0 commit 124278e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config-reloader/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

const (
maskFile = 0664
maskDirectory = 0775
maskDirectory = 0775
MacroLabels = "$labels"
ContainerLabel = "_container"
)
Expand Down
23 changes: 23 additions & 0 deletions config-reloader/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,29 @@ func TestLabelsParseNotOk(t *testing.T) {
}
}

func TestMatch(t *testing.T) {
containerLabels := map[string]string{"key": "value"}
containerName := "container-name"

var labels map[string]string = nil
assert.True(t, Match(labels, containerLabels, containerName))

labels = map[string]string{"_container": containerName}
assert.True(t, Match(labels, containerLabels, containerName))

labels = map[string]string{"a": "a"}
assert.False(t, Match(labels, containerLabels, containerName))

labels = map[string]string{"key": "value"}
assert.True(t, Match(labels, containerLabels, containerName))

labels = map[string]string{"key": "value", "_container": "container-name"}
assert.True(t, Match(labels, containerLabels, containerName))

labels = map[string]string{"a": "a", "key": "value", "_container": "container-name"}
assert.False(t, Match(labels, containerLabels, containerName))
}

func TestEnsureDirExits(t *testing.T) {

type testDirConfig struct {
Expand Down

0 comments on commit 124278e

Please sign in to comment.