2019-05-15 18:27:02 -07:00
|
|
|
package v1alpha1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"gotest.tools/assert"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
var defaultResourceDescriptionName = "defaultResourceDescription"
|
|
|
|
var defaultResourceDescription = ResourceDescription{
|
2019-05-21 15:43:43 -07:00
|
|
|
Kinds: []string{"Deployment"},
|
|
|
|
Name: &defaultResourceDescriptionName,
|
2019-05-15 18:27:02 -07:00
|
|
|
Selector: &metav1.LabelSelector{
|
|
|
|
MatchLabels: map[string]string{"LabelForSelector": "defaultResourceDescription"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_EmptyRule(t *testing.T) {
|
|
|
|
emptyRule := Rule{
|
|
|
|
Name: "defaultRule",
|
|
|
|
ResourceDescription: defaultResourceDescription,
|
|
|
|
}
|
|
|
|
err := emptyRule.Validate()
|
|
|
|
assert.Assert(t, err != nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_ResourceDescription(t *testing.T) {
|
|
|
|
err := defaultResourceDescription.Validate()
|
|
|
|
assert.NilError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_ResourceDescription_EmptyKind(t *testing.T) {
|
|
|
|
resourceDescription := ResourceDescription{
|
|
|
|
Name: &defaultResourceDescriptionName,
|
|
|
|
Selector: &metav1.LabelSelector{
|
|
|
|
MatchLabels: map[string]string{"LabelForSelector": "defaultResourceDescription"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
err := resourceDescription.Validate()
|
|
|
|
assert.Assert(t, err != nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_ResourceDescription_EmptyNameAndSelector(t *testing.T) {
|
|
|
|
resourceDescription := ResourceDescription{
|
2019-05-21 15:43:43 -07:00
|
|
|
Kinds: []string{"Deployment"},
|
2019-05-15 18:27:02 -07:00
|
|
|
}
|
|
|
|
err := resourceDescription.Validate()
|
2019-06-05 13:43:07 +03:00
|
|
|
assert.NilError(t, err)
|
2019-05-15 18:27:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func Test_Patch_EmptyPath(t *testing.T) {
|
|
|
|
patch := Patch{
|
|
|
|
Operation: "add",
|
|
|
|
Value: "true",
|
|
|
|
}
|
|
|
|
err := patch.Validate()
|
|
|
|
assert.Assert(t, err != nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_Patch_EmptyValueWithAdd(t *testing.T) {
|
|
|
|
patch := Patch{
|
|
|
|
Path: "/metadata/labels/is-mutated",
|
|
|
|
Operation: "add",
|
|
|
|
}
|
|
|
|
err := patch.Validate()
|
|
|
|
assert.Assert(t, err != nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_Patch_UnsupportedOperation(t *testing.T) {
|
|
|
|
patch := Patch{
|
|
|
|
Path: "/metadata/labels/is-mutated",
|
|
|
|
Operation: "overwrite",
|
|
|
|
Value: "true",
|
|
|
|
}
|
|
|
|
err := patch.Validate()
|
|
|
|
assert.Assert(t, err != nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_Generation_EmptyCopyFrom(t *testing.T) {
|
|
|
|
generation := Generation{
|
|
|
|
Kind: "ConfigMap",
|
|
|
|
Name: "comfigmapGenerator",
|
|
|
|
}
|
|
|
|
err := generation.Validate()
|
|
|
|
assert.Assert(t, err != nil)
|
|
|
|
}
|