Skip to content
This repository has been archived by the owner on Jan 20, 2023. It is now read-only.

Commit

Permalink
fixup: add test for log processing
Browse files Browse the repository at this point in the history
Signed-off-by: Angel Misevski <amisevsk@redhat.com>
  • Loading branch information
amisevsk committed Feb 12, 2020
1 parent e9b8aac commit 391364a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions utils/dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package utils

import (
"regexp"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -50,6 +52,19 @@ func TestGetExtensionCollisionsMulti(t *testing.T) {
assert.NotContains(t, output, "yyy")
}

func TestConvertCollisionsToLog(t *testing.T) {
collisions := map[string][]string{
"ext1": []string{"plugin_a", "plugin_b"},
"ext2": []string{"plugin_c", "plugin_d", "plugin_e"},
}
output := ConvertCollisionsToLog(collisions)
for _, test := range []string{
".*ext1.*", ".*ext2.*", ".*plugin_a.*", ".*plugin_b.*", ".*plugin_c.*", ".*plugin_d.*", ".*plugin_e.*",
} {
assertMatchSliceRegexp(t, output, test)
}
}

func generateMetaWithExtensions(id string, exts ...string) model.PluginMeta {
return model.PluginMeta{
ID: id,
Expand All @@ -58,3 +73,14 @@ func generateMetaWithExtensions(id string, exts ...string) model.PluginMeta {
},
}
}

func assertMatchSliceRegexp(t *testing.T, slice []string, pattern string) {
re := regexp.MustCompile(pattern)
match := false
for _, str := range slice {
if re.MatchString(str) {
match = true
}
}
assert.Truef(t, match, "Expected '%s' to be logged but got:\n%s", pattern, strings.Join(slice, "\n"))
}

0 comments on commit 391364a

Please sign in to comment.