Skip to content

Commit

Permalink
feat: basic support Apache APISIX 2.10 (#2149)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzp2010 authored Oct 3, 2021
1 parent fd5afe4 commit 321a195
Show file tree
Hide file tree
Showing 21 changed files with 1,015 additions and 153 deletions.
322 changes: 312 additions & 10 deletions api/conf/schema.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions api/internal/core/entity/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ type Service struct {
Script string `json:"script,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
EnableWebsocket bool `json:"enable_websocket,omitempty"`
Hosts []string `json:"hosts,omitempty"`
}

type Script struct {
Expand Down
2 changes: 1 addition & 1 deletion api/test/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ services:

apisix:
hostname: apisix_server1
image: apache/apisix:2.9-alpine
image: apache/apisix:2.10.0-alpine
restart: always
volumes:
- ./apisix_config.yaml:/usr/local/apisix/conf/config.yaml:ro
Expand Down
126 changes: 125 additions & 1 deletion api/test/e2enew/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import (
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"

"github.com/apisix/manager-api/test/e2enew/base"
"github.com/onsi/ginkgo/extensions/table"

"github.com/apisix/manager-api/test/e2enew/base"
)

var _ = ginkgo.Describe("create service without plugin", func() {
Expand Down Expand Up @@ -614,3 +615,126 @@ var _ = ginkgo.Describe("test service delete", func() {
ExpectStatus: http.StatusNotFound,
}))
})

var _ = ginkgo.Describe("test service with hosts", func() {
var createServiceBody = map[string]interface{}{
"name": "testservice",
"upstream": map[string]interface{}{
"type": "roundrobin",
"nodes": []map[string]interface{}{
{
"host": base.UpstreamIp,
"port": 1980,
"weight": 1,
},
},
},
"hosts": []string{
"test.com",
"test1.com",
},
}
_createServiceBody, err := json.Marshal(createServiceBody)
gomega.Expect(err).To(gomega.BeNil())

var createRouteBody = map[string]interface{}{
"id": "r1",
"name": "route1",
"uri": "/hello",
"upstream": map[string]interface{}{
"type": "roundrobin",
"nodes": map[string]interface{}{
base.UpstreamIp + ":1980": 1,
},
},
"service_id": "s1",
}
_createRouteBody, err := json.Marshal(createRouteBody)
gomega.Expect(err).To(gomega.BeNil())

table.DescribeTable("test service with hosts",
func(tc func() base.HttpTestCase) {
base.RunTestCase(tc())
},
table.Entry("create service with hosts params", func() base.HttpTestCase {
return base.HttpTestCase{
Desc: "create service with hosts params",
Object: base.ManagerApiExpect(),
Method: http.MethodPut,
Path: "/apisix/admin/services/s1",
Headers: map[string]string{"Authorization": base.GetToken()},
Body: string(_createServiceBody),
ExpectStatus: http.StatusOK,
}
}),
table.Entry("create route use service s1", func() base.HttpTestCase {
return base.HttpTestCase{
Desc: "create route use service s1",
Object: base.ManagerApiExpect(),
Method: http.MethodPut,
Path: "/apisix/admin/routes/r1",
Body: string(_createRouteBody),
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
}
}),
table.Entry("hit route by test.com", func() base.HttpTestCase {
return base.HttpTestCase{
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/hello",
Headers: map[string]string{
"Host": "test.com",
},
ExpectStatus: http.StatusOK,
ExpectBody: "hello world",
Sleep: base.SleepTime,
}
}),
table.Entry("hit route by test1.com", func() base.HttpTestCase {
return base.HttpTestCase{
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/hello",
Headers: map[string]string{
"Host": "test1.com",
},
ExpectStatus: http.StatusOK,
ExpectBody: "hello world",
Sleep: base.SleepTime,
}
}),
table.Entry("hit route by test2.com", func() base.HttpTestCase {
return base.HttpTestCase{
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/hello",
Headers: map[string]string{
"Host": "test2.com",
},
ExpectStatus: http.StatusNotFound,
Sleep: base.SleepTime,
}
}),
table.Entry("delete route", func() base.HttpTestCase {
return base.HttpTestCase{
Desc: "delete route first",
Object: base.ManagerApiExpect(),
Method: http.MethodDelete,
Path: "/apisix/admin/routes/r1",
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
}
}),
table.Entry("delete service", func() base.HttpTestCase {
return base.HttpTestCase{
Desc: "delete service success",
Object: base.ManagerApiExpect(),
Method: http.MethodDelete,
Path: "/apisix/admin/services/s1",
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
}
}),
)
})
118 changes: 104 additions & 14 deletions web/cypress/fixtures/plugin-dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@
"conn": 1,
"burst": 0,
"default_conn_delay": 0.1,
"rejected_code": 503,
"key": "remote_addr"
}
},
Expand All @@ -472,41 +471,47 @@
"data": {
"conn": 1,
"default_conn_delay": 0.1,
"rejected_code": 503,
"key": "remote_addr"
}
},
{
"shouldValid": false,
"data": {
"burst": 0,
"conn": 1,
"burst": -1,
"default_conn_delay": 0.1,
"rejected_code": 503,
"key": "remote_addr"
}
},
{
"shouldValid": false,
"data": {
"conn": -1,
"burst": 0,
"burst": 1,
"default_conn_delay": 0.1,
"rejected_code": 503,
"key": "remote_addr"
}
},
{
"shouldValid": true,
"shouldValid": false,
"data": {
"conn": 100,
"burst": 50,
"default_conn_delay": 0.1,
"rejected_code": 503,
"default_conn_delay": -1,
"key": "server_addr"
}
},
{
"shouldValid": false,
"shouldValid": true,
"data": {
"conn": 5,
"burst": 1,
"default_conn_delay": 0.1,
"key": "consumer_name"
}
},
{
"shouldValid": true,
"data": {
"conn": 5,
"burst": 1,
Expand All @@ -516,7 +521,7 @@
}
},
{
"shouldValid": false,
"shouldValid": true,
"data": {
"conn": 5,
"burst": 1,
Expand All @@ -528,11 +533,61 @@
{
"shouldValid": true,
"data": {
"conn": 2,
"conn": 5,
"burst": 1,
"default_conn_delay": 0.1,
"key": "remote_addr"
}
},
{
"shouldValid": true,
"data": {
"conn": 5,
"burst": 1,
"default_conn_delay": 0.1,
"key": "server_addr"
}
},
{
"shouldValid": true,
"data": {
"conn": 5,
"burst": 1,
"default_conn_delay": 0.1,
"key": "server_addr",
"rejected_code": 503,
"rejected_msg": "test"
}
},
{
"shouldValid": false,
"data": {
"conn": 5,
"burst": 1,
"default_conn_delay": 0.1,
"key": "server_addr",
"rejected_code": 600
}
},
{
"shouldValid": false,
"data": {
"conn": 5,
"burst": 1,
"default_conn_delay": 0.1,
"key": "server_addr",
"rejected_msg": ""
}
},
{
"shouldValid": false,
"data": {
"conn": 5,
"burst": 1,
"default_conn_delay": 0.1,
"key": "server_addr",
"allow_degradation": 1
}
}
],
"limit-count": [
Expand Down Expand Up @@ -797,22 +852,36 @@
}
],
"proxy-mirror": [
{
"shouldValid": true,
"data": {
"host": "http://127.0.0.1"
}
},
{
"shouldValid": false,
"data": {
"host": "127.0.0.1:1999"
}
},
{
"shouldValid": false,
"data": {
"host": "http://127.0.0.1:1999/invalid_uri"
}
},
{
"shouldValid": true,
"data": {
"host": "http://127.0.0.1"
"host": "http://127.0.0.1",
"sample_ratio": 0.1
}
},
{
"shouldValid": false,
"data": {
"host": "http://127.0.0.1:1999/invalid_uri"
"host": "http://127.0.0.1",
"sample_ratio": 2
}
}
],
Expand Down Expand Up @@ -951,6 +1020,20 @@
"bypass_missing": true,
"whitelist": ["*.xx.com", "yy.com"]
}
},
{
"shouldValid": false,
"data": {
"whitelist": ["*.xx.com", "yy.com"],
"message": ""
}
},
{
"shouldValid": false,
"data": {
"whitelist": ["*.xx.com", "yy.com"],
"blacklist": ["*.xx.com", "yy.com"]
}
}
],
"request-id": [
Expand Down Expand Up @@ -1327,6 +1410,13 @@
"data": {
"block_rules": ["aa"]
}
},
{
"shouldValid": true,
"data": {
"block_rules": ["aa"],
"case_insensitive": true
}
}
],
"zipkin": [
Expand Down
Loading

0 comments on commit 321a195

Please sign in to comment.