// Copyright 2020-2026 Project Capsule Authors // SPDX-License-Identifier: Apache-2.0 //nolint:dupl package api_test import ( "testing" "github.com/projectcapsule/capsule/pkg/api" "github.com/stretchr/testify/assert" ) func TestAllowedListSpec_ExactMatch(t *testing.T) { type tc struct { In []string True []string False []string } for _, tc := range []tc{ { []string{"foo", "bar", "bizz", "buzz"}, []string{"foo", "bar", "bizz", "buzz"}, []string{"bing", "bong"}, }, { []string{"one", "two", "three"}, []string{"one", "two", "three"}, []string{"a", "b", "c"}, }, { nil, nil, []string{"any", "value"}, }, } { a := api.AllowedListSpec{ Exact: tc.In, } for _, ok := range tc.True { assert.True(t, a.ExactMatch(ok)) } for _, ko := range tc.False { assert.False(t, a.ExactMatch(ko)) } } } func TestAllowedListSpec_RegexMatch(t *testing.T) { type tc struct { Regex string True []string False []string } for _, tc := range []tc{ {`first-\w+-pattern`, []string{"first-date-pattern", "first-year-pattern"}, []string{"broken", "first-year", "second-date-pattern"}}, {``, nil, []string{"any", "value"}}, } { a := api.AllowedListSpec{ Regex: tc.Regex, } for _, ok := range tc.True { assert.True(t, a.RegexMatch(ok)) } for _, ko := range tc.False { assert.False(t, a.RegexMatch(ko)) } } }