From 124278e57883d95393caa423934fe5db9b125522 Mon Sep 17 00:00:00 2001 From: huskykurt Date: Thu, 15 Dec 2022 08:36:27 +0900 Subject: [PATCH] add test for util/Match function (#289) Signed-off-by: huskykurt --- config-reloader/util/util.go | 2 +- config-reloader/util/util_test.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/config-reloader/util/util.go b/config-reloader/util/util.go index e0aa8e97..fe606f9b 100644 --- a/config-reloader/util/util.go +++ b/config-reloader/util/util.go @@ -24,7 +24,7 @@ import ( const ( maskFile = 0664 - maskDirectory = 0775 + maskDirectory = 0775 MacroLabels = "$labels" ContainerLabel = "_container" ) diff --git a/config-reloader/util/util_test.go b/config-reloader/util/util_test.go index bc92ed35..e5dde9ef 100644 --- a/config-reloader/util/util_test.go +++ b/config-reloader/util/util_test.go @@ -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 {