@@ -3,14 +3,9 @@ package applier_test
33import (
44 "testing"
55
6- "github.com/stretchr/testify/assert"
76 "github.com/stretchr/testify/require"
8- corev1 "k8s.io/api/core/v1"
9- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
107 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
118 "k8s.io/utils/ptr"
12- "pkg.package-operator.run/boxcutter/probing"
13- "sigs.k8s.io/controller-runtime/pkg/client"
149
1510 ocv1ac "github.com/operator-framework/operator-controller/applyconfigurations/api/v1"
1611 "github.com/operator-framework/operator-controller/internal/operator-controller/applier"
@@ -1036,82 +1031,3 @@ func Test_PhaseSort(t *testing.T) {
10361031 })
10371032 }
10381033}
1039-
1040- func Test_FieldValueProbe (t * testing.T ) {
1041- for _ , tc := range []struct {
1042- name string
1043- obj client.Object
1044- probe applier.FieldValueProbe
1045- expectedResult probing.Result
1046- }{
1047- {
1048- name : "True result with found key and equal value" ,
1049- obj : & corev1.Service {
1050- TypeMeta : metav1.TypeMeta {Kind : "Service" , APIVersion : "v1" },
1051- ObjectMeta : metav1.ObjectMeta {Name : "my-service" , Namespace : "my-namespace" },
1052- },
1053- probe : applier.FieldValueProbe {
1054- FieldPath : "metadata.name" ,
1055- Value : "my-service" ,
1056- },
1057- expectedResult : probing.Result {
1058- Status : probing .StatusTrue ,
1059- Messages : []string {
1060- `value at key "metadata.name" == "my-service"` ,
1061- },
1062- },
1063- },
1064- {
1065- name : "False result with unfound key" ,
1066- obj : & corev1.Service {
1067- TypeMeta : metav1.TypeMeta {Kind : "Service" , APIVersion : "v1" },
1068- ObjectMeta : metav1.ObjectMeta {Name : "my-service" , Namespace : "my-namespace" },
1069- },
1070- probe : applier.FieldValueProbe {
1071- FieldPath : "spec.foo" ,
1072- Value : "my-service" ,
1073- },
1074- expectedResult : probing.Result {
1075- Status : probing .StatusFalse ,
1076- Messages : []string {
1077- `missing key: "spec.foo"` ,
1078- },
1079- },
1080- },
1081- {
1082- name : "False result with found key and unequal value" ,
1083- obj : & corev1.Service {
1084- TypeMeta : metav1.TypeMeta {Kind : "Service" , APIVersion : "v1" },
1085- ObjectMeta : metav1.ObjectMeta {Name : "my-service" , Namespace : "my-namespace" },
1086- },
1087- probe : applier.FieldValueProbe {
1088- FieldPath : "metadata.namespace" ,
1089- Value : "bar" ,
1090- },
1091- expectedResult : probing.Result {
1092- Status : probing .StatusFalse ,
1093- Messages : []string {
1094- `value at key "metadata.namespace" != "bar"; expected: "bar" got: "my-namespace"` ,
1095- },
1096- },
1097- },
1098- {
1099- name : "Unknown result unstructured conversion failure" ,
1100- obj : nil ,
1101- probe : applier.FieldValueProbe {
1102- FieldPath : "metadata.name" ,
1103- Value : "my-service" ,
1104- },
1105- expectedResult : probing.Result {
1106- Status : probing .StatusUnknown ,
1107- Messages : []string {
1108- "failed to convert to unstructured: object is nil" ,
1109- },
1110- },
1111- },
1112- } {
1113- t .Run (tc .name , func (t * testing.T ) {
1114- assert .Equal (t , tc .expectedResult , tc .probe .Probe (tc .obj ))
1115- })
1116- }
1117- }
0 commit comments