Skip to content

Commit 0443a72

Browse files
authored
test: add e2e test for syncing CR (#33)
* test: add e2e test for syncing CR --------- Signed-off-by: Ashish Tiwari <ashishjaitiwari15112000@gmail.com>
1 parent d94ffe3 commit 0443a72

78 files changed

Lines changed: 536 additions & 251 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/e2e-test-ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ concurrency:
3434

3535
jobs:
3636
changes:
37-
if: |
38-
contains(github.event.pull_request.labels.*.name, 'ci-e2e-test')
37+
if: contains(github.event.pull_request.labels.*.name, 'ci-e2e-test')
3938
runs-on: buildjet-2vcpu-ubuntu-2204
4039
outputs:
4140
docs: ${{ steps.filter.outputs.docs }}

.github/workflows/unit-test-ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ on:
2828
- release/1.8
2929
jobs:
3030
changes:
31-
if: |
32-
contains(github.event.pull_request.labels.*.name, 'ci-unit-test')
31+
if: contains(github.event.pull_request.labels.*.name, 'ci-unit-test')
3332
runs-on: ubuntu-latest
3433
outputs:
3534
docs: ${{ steps.filter.outputs.docs }}

test/e2e/scaffold/k8s.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"time"
2929

3030
"github.com/api7/api7-ingress-controller/pkg/apisix"
31+
v2 "github.com/api7/api7-ingress-controller/pkg/kube/apisix/apis/config/v2"
3132
"github.com/api7/api7-ingress-controller/pkg/log"
3233
"github.com/api7/api7-ingress-controller/pkg/metrics"
3334
v1 "github.com/api7/api7-ingress-controller/pkg/types/apisix/v1"
@@ -820,3 +821,25 @@ func (s *Scaffold) RunDigDNSClientFromK8s(args ...string) (string, error) {
820821
kubectlArgs = append(kubectlArgs, args...)
821822
return s.RunKubectlAndGetOutput(kubectlArgs...)
822823
}
824+
825+
func (s *Scaffold) GetApisixResourceStatus(resourceName string, resourceType string) (*v2.ApisixStatus, error) {
826+
kubectlArgs := []string{
827+
"get", resourceType, resourceName, "-o", "json",
828+
}
829+
output, err := s.RunKubectlAndGetOutput(kubectlArgs...)
830+
if err != nil {
831+
return nil, err
832+
}
833+
var upstream v2.ApisixUpstream
834+
err = json.Unmarshal([]byte(output), &upstream)
835+
if err != nil {
836+
return nil, err
837+
}
838+
return &upstream.Status, nil
839+
}
840+
841+
func (s *Scaffold) AssertCRSync(resourceName, resourceType, message string) {
842+
routeStatus, err := s.GetApisixResourceStatus(resourceName, resourceType)
843+
assert.Nil(ginkgo.GinkgoT(), err)
844+
assert.Equal(ginkgo.GinkgoT(), message, routeStatus.Conditions[0].Message)
845+
}

test/e2e/suite-annotations/authorization.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/api7/api7-ingress-controller/test/e2e/scaffold"
2626
)
2727

28-
var _ = ginkgo.Describe("suite-annotations: authorization annotations", func() {
28+
var _ = ginkgo.PDescribe("suite-annotations: authorization annotations", func() {
2929
suites := func(scaffoldFunc func() *scaffold.Scaffold) {
3030
s := scaffoldFunc()
3131

test/e2e/suite-annotations/cors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/api7/api7-ingress-controller/test/e2e/scaffold"
2626
)
2727

28-
var _ = ginkgo.Describe("suite-annotations: cors annotations", func() {
28+
var _ = ginkgo.PDescribe("suite-annotations: cors annotations", func() {
2929
s := scaffold.NewDefaultScaffold()
3030

3131
ginkgo.It("enable in ingress networking/v1", func() {

test/e2e/suite-annotations/csrf.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/api7/api7-ingress-controller/test/e2e/scaffold"
2626
)
2727

28-
var _ = ginkgo.Describe("suite-annotations: csrf annotations", func() {
28+
var _ = ginkgo.PDescribe("suite-annotations: csrf annotations", func() {
2929
s := scaffold.NewDefaultScaffold()
3030

3131
ginkgo.It("enable csrf in ingress networking/v1", func() {

test/e2e/suite-annotations/forward_auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/api7/api7-ingress-controller/test/e2e/scaffold"
2626
)
2727

28-
var _ = ginkgo.Describe("suite-annotations: froward-auth annotations", func() {
28+
var _ = ginkgo.PDescribe("suite-annotations: froward-auth annotations", func() {
2929
s := scaffold.NewDefaultScaffold()
3030

3131
ginkgo.JustBeforeEach(func() {

test/e2e/suite-annotations/http_method.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/api7/api7-ingress-controller/test/e2e/scaffold"
2626
)
2727

28-
var _ = ginkgo.Describe("suite-annotations: allow-http-methods annotations", func() {
28+
var _ = ginkgo.PDescribe("suite-annotations: allow-http-methods annotations", func() {
2929
s := scaffold.NewDefaultScaffold()
3030

3131
ginkgo.It("enable in ingress networking/v1", func() {
@@ -101,7 +101,7 @@ spec:
101101
})
102102
})
103103

104-
var _ = ginkgo.Describe("suite-annotations: blocklist-http-methods annotations", func() {
104+
var _ = ginkgo.PDescribe("suite-annotations: blocklist-http-methods annotations", func() {
105105
s := scaffold.NewDefaultScaffold()
106106

107107
ginkgo.It("enable in ingress networking/v1", func() {

test/e2e/suite-annotations/iprestriction.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/api7/api7-ingress-controller/test/e2e/scaffold"
2626
)
2727

28-
var _ = ginkgo.Describe("suite-annotations: allowlist-source-range annotations", func() {
28+
var _ = ginkgo.PDescribe("suite-annotations: allowlist-source-range annotations", func() {
2929
s := scaffold.NewDefaultScaffold()
3030

3131
ginkgo.It("enable in ingress networking/v1", func() {
@@ -89,7 +89,7 @@ spec:
8989
})
9090
})
9191

92-
var _ = ginkgo.Describe("suite-annotations: blocklist-source-range annotations", func() {
92+
var _ = ginkgo.PDescribe("suite-annotations: blocklist-source-range annotations", func() {
9393
s := scaffold.NewDefaultScaffold()
9494

9595
ginkgo.It("enable in ingress networking/v1", func() {

test/e2e/suite-annotations/plugin_conifg.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func _assert(s *scaffold.Scaffold, ing string) {
7575
resp.Body().Contains("This is the epilogue")
7676
}
7777

78-
var _ = ginkgo.Describe("suite-annotations: annotations.networking/v1 with ApisixPluginConfig", func() {
78+
var _ = ginkgo.PDescribe("suite-annotations: annotations.networking/v1 with ApisixPluginConfig", func() {
7979
s := scaffold.NewDefaultScaffold()
8080
ginkgo.It("networking/v1", func() {
8181
backendSvc, backendPorts := s.DefaultHTTPBackend()
@@ -106,7 +106,7 @@ spec:
106106
})
107107
})
108108

109-
var _ = ginkgo.Describe("suite-annotations: annotations.networking/v1beta1 with ApisixPluginConfig", func() {
109+
var _ = ginkgo.PDescribe("suite-annotations: annotations.networking/v1beta1 with ApisixPluginConfig", func() {
110110
s := scaffold.NewDefaultScaffold()
111111
ginkgo.It("networking/v1beta1", func() {
112112
_createAPC(s)

0 commit comments

Comments
 (0)