get policy test moved

feature/regexp_matching
Karolis Rusenas 2018-09-04 21:10:57 +01:00
parent aa447f6f56
commit 4e50f7ecdd
2 changed files with 49 additions and 42 deletions

View File

@ -0,0 +1,49 @@
package policy
import (
"testing"
"github.com/keel-hq/keel/types"
)
func Test_getPolicyFromLabels(t *testing.T) {
type args struct {
labels map[string]string
}
tests := []struct {
name string
args args
want string
want1 bool
}{
{
name: "policy all",
args: args{labels: map[string]string{types.KeelPolicyLabel: "all"}},
want1: true,
want: "all",
},
{
name: "policy minor",
args: args{labels: map[string]string{types.KeelPolicyLabel: "minor"}},
want1: true,
want: "minor",
},
{
name: "legacy policy minor",
args: args{labels: map[string]string{"keel.observer/policy": "minor"}},
want1: true,
want: "minor",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, got1 := getPolicyFromLabels(tt.args.labels)
if got != tt.want {
t.Errorf("getPolicyFromLabels() got = %v, want %v", got, tt.want)
}
if got1 != tt.want1 {
t.Errorf("getPolicyFromLabels() got1 = %v, want %v", got1, tt.want1)
}
})
}
}

View File

@ -1,42 +0,0 @@
package policies
import (
"reflect"
"testing"
"github.com/keel-hq/keel/types"
)
func TestGetPolicy(t *testing.T) {
type args struct {
labels map[string]string
}
tests := []struct {
name string
args args
want types.PolicyType
}{
{
name: "policy all",
args: args{labels: map[string]string{types.KeelPolicyLabel: "all"}},
want: types.PolicyTypeAll,
},
{
name: "policy minor",
args: args{labels: map[string]string{types.KeelPolicyLabel: "minor"}},
want: types.PolicyTypeMinor,
},
{
name: "legacy policy minor",
args: args{labels: map[string]string{"keel.observer/policy": "minor"}},
want: types.PolicyTypeMinor,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetPolicy(tt.args.labels); !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetPolicy() = %v, want %v", got, tt.want)
}
})
}
}