Skip to content

Commit 321a195

Browse files
authored
feat: basic support Apache APISIX 2.10 (#2149)
1 parent fd5afe4 commit 321a195

File tree

21 files changed

+1015
-153
lines changed

21 files changed

+1015
-153
lines changed

api/conf/schema.json

Lines changed: 312 additions & 10 deletions
Large diffs are not rendered by default.

api/internal/core/entity/entity.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ type Service struct {
254254
Script string `json:"script,omitempty"`
255255
Labels map[string]string `json:"labels,omitempty"`
256256
EnableWebsocket bool `json:"enable_websocket,omitempty"`
257+
Hosts []string `json:"hosts,omitempty"`
257258
}
258259

259260
type Script struct {

api/test/docker/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ services:
127127

128128
apisix:
129129
hostname: apisix_server1
130-
image: apache/apisix:2.9-alpine
130+
image: apache/apisix:2.10.0-alpine
131131
restart: always
132132
volumes:
133133
- ./apisix_config.yaml:/usr/local/apisix/conf/config.yaml:ro

api/test/e2enew/service/service_test.go

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ import (
2424
"github.com/onsi/ginkgo"
2525
"github.com/onsi/gomega"
2626

27-
"github.com/apisix/manager-api/test/e2enew/base"
2827
"github.com/onsi/ginkgo/extensions/table"
28+
29+
"github.com/apisix/manager-api/test/e2enew/base"
2930
)
3031

3132
var _ = ginkgo.Describe("create service without plugin", func() {
@@ -614,3 +615,126 @@ var _ = ginkgo.Describe("test service delete", func() {
614615
ExpectStatus: http.StatusNotFound,
615616
}))
616617
})
618+
619+
var _ = ginkgo.Describe("test service with hosts", func() {
620+
var createServiceBody = map[string]interface{}{
621+
"name": "testservice",
622+
"upstream": map[string]interface{}{
623+
"type": "roundrobin",
624+
"nodes": []map[string]interface{}{
625+
{
626+
"host": base.UpstreamIp,
627+
"port": 1980,
628+
"weight": 1,
629+
},
630+
},
631+
},
632+
"hosts": []string{
633+
"test.com",
634+
"test1.com",
635+
},
636+
}
637+
_createServiceBody, err := json.Marshal(createServiceBody)
638+
gomega.Expect(err).To(gomega.BeNil())
639+
640+
var createRouteBody = map[string]interface{}{
641+
"id": "r1",
642+
"name": "route1",
643+
"uri": "/hello",
644+
"upstream": map[string]interface{}{
645+
"type": "roundrobin",
646+
"nodes": map[string]interface{}{
647+
base.UpstreamIp + ":1980": 1,
648+
},
649+
},
650+
"service_id": "s1",
651+
}
652+
_createRouteBody, err := json.Marshal(createRouteBody)
653+
gomega.Expect(err).To(gomega.BeNil())
654+
655+
table.DescribeTable("test service with hosts",
656+
func(tc func() base.HttpTestCase) {
657+
base.RunTestCase(tc())
658+
},
659+
table.Entry("create service with hosts params", func() base.HttpTestCase {
660+
return base.HttpTestCase{
661+
Desc: "create service with hosts params",
662+
Object: base.ManagerApiExpect(),
663+
Method: http.MethodPut,
664+
Path: "/apisix/admin/services/s1",
665+
Headers: map[string]string{"Authorization": base.GetToken()},
666+
Body: string(_createServiceBody),
667+
ExpectStatus: http.StatusOK,
668+
}
669+
}),
670+
table.Entry("create route use service s1", func() base.HttpTestCase {
671+
return base.HttpTestCase{
672+
Desc: "create route use service s1",
673+
Object: base.ManagerApiExpect(),
674+
Method: http.MethodPut,
675+
Path: "/apisix/admin/routes/r1",
676+
Body: string(_createRouteBody),
677+
Headers: map[string]string{"Authorization": base.GetToken()},
678+
ExpectStatus: http.StatusOK,
679+
}
680+
}),
681+
table.Entry("hit route by test.com", func() base.HttpTestCase {
682+
return base.HttpTestCase{
683+
Object: base.APISIXExpect(),
684+
Method: http.MethodGet,
685+
Path: "/hello",
686+
Headers: map[string]string{
687+
"Host": "test.com",
688+
},
689+
ExpectStatus: http.StatusOK,
690+
ExpectBody: "hello world",
691+
Sleep: base.SleepTime,
692+
}
693+
}),
694+
table.Entry("hit route by test1.com", func() base.HttpTestCase {
695+
return base.HttpTestCase{
696+
Object: base.APISIXExpect(),
697+
Method: http.MethodGet,
698+
Path: "/hello",
699+
Headers: map[string]string{
700+
"Host": "test1.com",
701+
},
702+
ExpectStatus: http.StatusOK,
703+
ExpectBody: "hello world",
704+
Sleep: base.SleepTime,
705+
}
706+
}),
707+
table.Entry("hit route by test2.com", func() base.HttpTestCase {
708+
return base.HttpTestCase{
709+
Object: base.APISIXExpect(),
710+
Method: http.MethodGet,
711+
Path: "/hello",
712+
Headers: map[string]string{
713+
"Host": "test2.com",
714+
},
715+
ExpectStatus: http.StatusNotFound,
716+
Sleep: base.SleepTime,
717+
}
718+
}),
719+
table.Entry("delete route", func() base.HttpTestCase {
720+
return base.HttpTestCase{
721+
Desc: "delete route first",
722+
Object: base.ManagerApiExpect(),
723+
Method: http.MethodDelete,
724+
Path: "/apisix/admin/routes/r1",
725+
Headers: map[string]string{"Authorization": base.GetToken()},
726+
ExpectStatus: http.StatusOK,
727+
}
728+
}),
729+
table.Entry("delete service", func() base.HttpTestCase {
730+
return base.HttpTestCase{
731+
Desc: "delete service success",
732+
Object: base.ManagerApiExpect(),
733+
Method: http.MethodDelete,
734+
Path: "/apisix/admin/services/s1",
735+
Headers: map[string]string{"Authorization": base.GetToken()},
736+
ExpectStatus: http.StatusOK,
737+
}
738+
}),
739+
)
740+
})

web/cypress/fixtures/plugin-dataset.json

Lines changed: 104 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@
463463
"conn": 1,
464464
"burst": 0,
465465
"default_conn_delay": 0.1,
466-
"rejected_code": 503,
467466
"key": "remote_addr"
468467
}
469468
},
@@ -472,41 +471,47 @@
472471
"data": {
473472
"conn": 1,
474473
"default_conn_delay": 0.1,
475-
"rejected_code": 503,
476474
"key": "remote_addr"
477475
}
478476
},
479477
{
480478
"shouldValid": false,
481479
"data": {
482-
"burst": 0,
480+
"conn": 1,
481+
"burst": -1,
483482
"default_conn_delay": 0.1,
484-
"rejected_code": 503,
485483
"key": "remote_addr"
486484
}
487485
},
488486
{
489487
"shouldValid": false,
490488
"data": {
491489
"conn": -1,
492-
"burst": 0,
490+
"burst": 1,
493491
"default_conn_delay": 0.1,
494-
"rejected_code": 503,
495492
"key": "remote_addr"
496493
}
497494
},
498495
{
499-
"shouldValid": true,
496+
"shouldValid": false,
500497
"data": {
501498
"conn": 100,
502499
"burst": 50,
503-
"default_conn_delay": 0.1,
504-
"rejected_code": 503,
500+
"default_conn_delay": -1,
505501
"key": "server_addr"
506502
}
507503
},
508504
{
509-
"shouldValid": false,
505+
"shouldValid": true,
506+
"data": {
507+
"conn": 5,
508+
"burst": 1,
509+
"default_conn_delay": 0.1,
510+
"key": "consumer_name"
511+
}
512+
},
513+
{
514+
"shouldValid": true,
510515
"data": {
511516
"conn": 5,
512517
"burst": 1,
@@ -516,7 +521,7 @@
516521
}
517522
},
518523
{
519-
"shouldValid": false,
524+
"shouldValid": true,
520525
"data": {
521526
"conn": 5,
522527
"burst": 1,
@@ -528,11 +533,61 @@
528533
{
529534
"shouldValid": true,
530535
"data": {
531-
"conn": 2,
536+
"conn": 5,
532537
"burst": 1,
533538
"default_conn_delay": 0.1,
534539
"key": "remote_addr"
535540
}
541+
},
542+
{
543+
"shouldValid": true,
544+
"data": {
545+
"conn": 5,
546+
"burst": 1,
547+
"default_conn_delay": 0.1,
548+
"key": "server_addr"
549+
}
550+
},
551+
{
552+
"shouldValid": true,
553+
"data": {
554+
"conn": 5,
555+
"burst": 1,
556+
"default_conn_delay": 0.1,
557+
"key": "server_addr",
558+
"rejected_code": 503,
559+
"rejected_msg": "test"
560+
}
561+
},
562+
{
563+
"shouldValid": false,
564+
"data": {
565+
"conn": 5,
566+
"burst": 1,
567+
"default_conn_delay": 0.1,
568+
"key": "server_addr",
569+
"rejected_code": 600
570+
}
571+
},
572+
{
573+
"shouldValid": false,
574+
"data": {
575+
"conn": 5,
576+
"burst": 1,
577+
"default_conn_delay": 0.1,
578+
"key": "server_addr",
579+
"rejected_msg": ""
580+
}
581+
},
582+
{
583+
"shouldValid": false,
584+
"data": {
585+
"conn": 5,
586+
"burst": 1,
587+
"default_conn_delay": 0.1,
588+
"key": "server_addr",
589+
"allow_degradation": 1
590+
}
536591
}
537592
],
538593
"limit-count": [
@@ -797,22 +852,36 @@
797852
}
798853
],
799854
"proxy-mirror": [
855+
{
856+
"shouldValid": true,
857+
"data": {
858+
"host": "http://127.0.0.1"
859+
}
860+
},
800861
{
801862
"shouldValid": false,
802863
"data": {
803864
"host": "127.0.0.1:1999"
804865
}
805866
},
867+
{
868+
"shouldValid": false,
869+
"data": {
870+
"host": "http://127.0.0.1:1999/invalid_uri"
871+
}
872+
},
806873
{
807874
"shouldValid": true,
808875
"data": {
809-
"host": "http://127.0.0.1"
876+
"host": "http://127.0.0.1",
877+
"sample_ratio": 0.1
810878
}
811879
},
812880
{
813881
"shouldValid": false,
814882
"data": {
815-
"host": "http://127.0.0.1:1999/invalid_uri"
883+
"host": "http://127.0.0.1",
884+
"sample_ratio": 2
816885
}
817886
}
818887
],
@@ -951,6 +1020,20 @@
9511020
"bypass_missing": true,
9521021
"whitelist": ["*.xx.com", "yy.com"]
9531022
}
1023+
},
1024+
{
1025+
"shouldValid": false,
1026+
"data": {
1027+
"whitelist": ["*.xx.com", "yy.com"],
1028+
"message": ""
1029+
}
1030+
},
1031+
{
1032+
"shouldValid": false,
1033+
"data": {
1034+
"whitelist": ["*.xx.com", "yy.com"],
1035+
"blacklist": ["*.xx.com", "yy.com"]
1036+
}
9541037
}
9551038
],
9561039
"request-id": [
@@ -1327,6 +1410,13 @@
13271410
"data": {
13281411
"block_rules": ["aa"]
13291412
}
1413+
},
1414+
{
1415+
"shouldValid": true,
1416+
"data": {
1417+
"block_rules": ["aa"],
1418+
"case_insensitive": true
1419+
}
13301420
}
13311421
],
13321422
"zipkin": [

0 commit comments

Comments
 (0)