policy parse tests

feature/regexp_matching
Karolis Rusenas 2018-09-04 21:25:44 +01:00
parent 7241701933
commit 701f417741
1 changed files with 44 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package policy
import (
"reflect"
"testing"
"github.com/keel-hq/keel/types"
@ -47,3 +48,46 @@ func Test_getPolicyFromLabels(t *testing.T) {
})
}
}
func mustParseGlob(g string) *GlobPolicy {
glb, err := NewGlobPolicy(g)
if err != nil {
panic(err)
}
return glb
}
func TestGetPolicy(t *testing.T) {
type args struct {
policyName string
options *Options
}
tests := []struct {
name string
args args
want Policy
}{
{
name: "patch",
args: args{policyName: "patch", options: &Options{}},
want: NewSemverPolicy(SemverPolicyTypePatch),
},
{
name: "glob:foo-*",
args: args{policyName: "glob:foo-*", options: &Options{}},
want: mustParseGlob("glob:foo-*"),
},
{
name: "force match",
args: args{policyName: "force", options: &Options{MatchTag: true}},
want: NewForcePolicy(true),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetPolicy(tt.args.policyName, tt.args.options); !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetPolicy() = %v, want %v", got, tt.want)
}
})
}
}