Skip to content

Commit 1b6ae5c

Browse files
committed
feat: add e2e tests and fix ApisixUpstream validation logic in CRD
1 parent d67d1f4 commit 1b6ae5c

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed

api/v2/apisixupstream_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
// ApisixUpstreamSpec describes the specification of ApisixUpstream.
22-
// +kubebuilder:validation:XValidation:rule="has(self.externalNodes)!=has(discovery)"
22+
// +kubebuilder:validation:XValidation:rule="has(self.externalNodes)!=has(self.discovery)"
2323
type ApisixUpstreamSpec struct {
2424
// IngressClassName is the name of an IngressClass cluster resource.
2525
// controller implementations use this field to know whether they should be

config/crd/bases/apisix.apache.org_apisixupstreams.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ spec:
556556
type: string
557557
type: object
558558
x-kubernetes-validations:
559-
- rule: has(self.externalNodes)!=has(discovery)
559+
- rule: has(self.externalNodes)!=has(self.discovery)
560560
type: object
561561
served: true
562562
storage: true

test/e2e/apisix/upstream.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
13+
package apisix
14+
15+
import (
16+
. "github.com/onsi/ginkgo/v2"
17+
. "github.com/onsi/gomega"
18+
19+
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
20+
)
21+
22+
var _ = Describe("Test ApisixUpstream", func() {
23+
var (
24+
s = scaffold.NewScaffold(&scaffold.Options{
25+
ControllerName: "apisix.apache.org/apisix-ingress-controller",
26+
})
27+
err error
28+
)
29+
30+
Context("Test ApisixUpstream validation", func() {
31+
It("validation of externalNodes and discovery", func() {
32+
const apisixUpstreamSpec0 = `
33+
apiVersion: apisix.apache.org/v2
34+
kind: ApisixUpstream
35+
metadata:
36+
name: default-upstream
37+
spec:
38+
ingressClassName: apisix
39+
externalNodes:
40+
- type: Service
41+
name: httpbin-service-e2e-test
42+
discovery:
43+
serviceName: xx
44+
type: nacos
45+
`
46+
const apisixUpstreamSpec1 = `
47+
apiVersion: apisix.apache.org/v2
48+
kind: ApisixUpstream
49+
metadata:
50+
name: default-upstream
51+
spec:
52+
ingressClassName: apisix
53+
`
54+
err = s.CreateResourceFromString(apisixUpstreamSpec0)
55+
Expect(err).Should(HaveOccurred())
56+
Expect(err.Error()).Should(ContainSubstring("failed rule: has(self.externalNodes)!=has(self.discovery)"))
57+
58+
err = s.CreateResourceFromString(apisixUpstreamSpec1)
59+
Expect(err).Should(HaveOccurred())
60+
Expect(err.Error()).Should(ContainSubstring("failed rule: has(self.externalNodes)!=has(self.discovery)"))
61+
62+
})
63+
64+
It("", func() {})
65+
66+
It("", func() {})
67+
68+
It("", func() {})
69+
70+
It("", func() {})
71+
72+
It("", func() {})
73+
})
74+
})

0 commit comments

Comments
 (0)