Skip to content

Commit bd8833c

Browse files
committed
test: spec should be empty for not convertible AR
1 parent f2faab9 commit bd8833c

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

apis/gateway/v1beta1/apirule_conversion_test.go

+23-5
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ var _ = Describe("APIRule Conversion", func() {
359359

360360
})
361361

362-
It("should store rules in annotation", func() {
362+
It("should store spec in annotation", func() {
363363
var headerConfig, cookieConfig runtime.RawExtension
364364
_ = convertOverJson(map[string]string{
365365
"header1": "value1",
@@ -369,9 +369,19 @@ var _ = Describe("APIRule Conversion", func() {
369369
"cookie1": "value2",
370370
}, &cookieConfig)
371371

372+
namespace := "test-namespace"
373+
var port uint32 = 8080
374+
372375
apiRuleV1beta1 := v1beta1.APIRule{
373376
Status: testV1StatusOK,
374377
Spec: v1beta1.APIRuleSpec{
378+
Host: &host1string,
379+
Gateway: ptr.To("gateway-test"),
380+
Service: &v1beta1.Service{
381+
Name: ptr.To("service-test"),
382+
Port: &port,
383+
Namespace: &namespace,
384+
},
375385
Rules: []v1beta1.Rule{
376386
{
377387
Path: "/path1",
@@ -407,7 +417,7 @@ var _ = Describe("APIRule Conversion", func() {
407417

408418
// then
409419
Expect(err).ToNot(HaveOccurred())
410-
Expect(apiRuleV2alpha1.Annotations["gateway.kyma-project.io/v1beta1-rules"]).To(BeEquivalentTo(`[{"path":"/path1","service":{"name":"service","port":null},"methods":["GET","POST"],"accessStrategies":[{"handler":"jwt"}],"mutators":[{"handler":"header","config":{"header1":"value1"}},{"handler":"cookie","config":{"cookie1":"value2"}}]}]`))
420+
Expect(apiRuleV2alpha1.Annotations["gateway.kyma-project.io/v1beta1-spec"]).To(BeEquivalentTo(`{"host":"host1","service":{"name":"service-test","namespace":"test-namespace","port":8080},"gateway":"gateway-test","rules":[{"path":"/path1","service":{"name":"service","port":null},"methods":["GET","POST"],"accessStrategies":[{"handler":"jwt"}],"mutators":[{"handler":"header","config":{"header1":"value1"}},{"handler":"cookie","config":{"cookie1":"value2"}}]}]}`))
411421
})
412422

413423
})
@@ -808,13 +818,13 @@ var _ = Describe("APIRule Conversion", func() {
808818
}
809819
Expect(correctMutators).To(Equal(2))
810820
})
811-
It("should convert rules from annotation", func() {
821+
It("should convert spec from annotation", func() {
812822
// given
813823
apiRuleV2alpha1 := v2alpha1.APIRule{
814824
ObjectMeta: metav1.ObjectMeta{
815825
Annotations: map[string]string{
816826
"gateway.kyma-project.io/original-version": "v1beta1",
817-
"gateway.kyma-project.io/v1beta1-rules": `spec: [{"path":"/path1","service":{"name":"service","port":null},"methods":["GET","POST"],"accessStrategies":[{"handler":"jwt"}],"mutators":[{"handler":"header","config":{"header1":"value1"}},{"handler":"cookie","config":{"cookie1":"value2"}}]}]`,
827+
"gateway.kyma-project.io/v1beta1-spec": `{"host":"host1","service":{"name":"service-test","namespace":"test-namespace","port":8080},"gateway":"gateway-test","rules":[{"path":"/path1","service":{"name":"service","port":null},"methods":["GET","POST"],"accessStrategies":[{"handler":"jwt"}],"mutators":[{"handler":"header","config":{"header1":"value1"}},{"handler":"cookie","config":{"cookie1":"value2"}}]}]}`,
818828
},
819829
},
820830
}
@@ -823,10 +833,18 @@ var _ = Describe("APIRule Conversion", func() {
823833

824834
// when
825835
err := apiRuleBeta1.ConvertFrom(&apiRuleV2alpha1)
826-
836+
var port uint32 = 8080
827837
// then
828838
Expect(err).ToNot(HaveOccurred())
829839
Expect(apiRuleBeta1.Spec.Rules).To(HaveLen(1))
840+
Expect(apiRuleBeta1.Spec.Host).To(Equal(ptr.To(host1string)))
841+
Expect(apiRuleBeta1.Spec.Service).To(Equal(ptr.To(v1beta1.Service{
842+
Name: ptr.To("service-test"),
843+
Namespace: ptr.To("test-namespace"),
844+
Port: &port,
845+
})))
846+
Expect(*apiRuleBeta1.Spec.Gateway).To(Equal("gateway-test"))
847+
Expect(apiRuleBeta1.Spec.Rules[0].Path).To(Equal("/path1"))
830848
})
831849
})
832850
})

0 commit comments

Comments
 (0)