summaryrefslogtreecommitdiff
path: root/registry-scanner/pkg/image/matchfunc_test.go
blob: 11929b1d5f58ca502a3d78ff81757aad2c2192ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package image

import (
	"regexp"
	"testing"

	"github.com/stretchr/testify/assert"
)

func Test_MatchFuncAny(t *testing.T) {
	assert.True(t, MatchFuncAny("whatever", nil))
}

func Test_MatchFuncNone(t *testing.T) {
	assert.False(t, MatchFuncNone("whatever", nil))
}

func Test_MatchFuncRegexp(t *testing.T) {
	t.Run("Test with valid expression", func(t *testing.T) {
		re := regexp.MustCompile("[a-z]+")
		assert.True(t, MatchFuncRegexp("lemon", re))
		assert.False(t, MatchFuncRegexp("31337", re))
	})
	t.Run("Test with invalid type", func(t *testing.T) {
		assert.False(t, MatchFuncRegexp("lemon", "[a-z]+"))
	})
}