Skip to content

Commit

Permalink
chore: add plugin test (#1574)
Browse files Browse the repository at this point in the history
  • Loading branch information
starsz authored Mar 11, 2021
1 parent 61c9b4a commit 611ab09
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
27 changes: 27 additions & 0 deletions api/test/e2enew/plugin/plugin_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package plugin

import (
"testing"

"github.com/onsi/ginkgo"
)

func TestPlugin(t *testing.T) {
ginkgo.RunSpecs(t, "plugin suite")
}
84 changes: 84 additions & 0 deletions api/test/e2enew/plugin/plugin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package plugin

import (
"net/http"

"github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/extensions/table"

"e2enew/base"
)

var _ = ginkgo.Describe("Plugin Basic", func() {
table.DescribeTable("test plugin basic", func(testCase base.HttpTestCase) {
base.RunTestCase(testCase)
},
table.Entry("get all plugins", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodGet,
Path: "/apisix/admin/plugins",
Query: "all=true",
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
ExpectBody: []string{"request-id", "syslog", "echo", "proxy-mirror"},
Sleep: base.SleepTime,
}),
table.Entry("get all plugins", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodGet,
Path: "/apisix/admin/plugins",
Query: "all=false",
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
ExpectBody: []string{"request-id", "syslog", "echo", "proxy-mirror"},
Sleep: base.SleepTime,
}),
)

table.DescribeTable("test schema basic", func(testCase base.HttpTestCase) {
base.RunTestCase(testCase)
},
table.Entry("get consumer schema", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodGet,
Path: "/apisix/admin/schema/plugins/jwt-auth",
Query: "schema_type=consumer",
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
ExpectBody: "{\"dependencies\":{\"algorithm\":{\"oneOf\":[{\"properties\":{\"algorithm\":" +
"{\"default\":\"HS256\",\"enum\":[\"HS256\",\"HS512\"]}}},{\"properties\":{\"algorithm\":" +
"{\"enum\":[\"RS256\"]},\"private_key\":{\"type\":\"string\"},\"public_key\":{\"type\":\"string\"}}," +
"\"required\":[\"private_key\",\"public_key\"]}]}},\"properties\":{\"algorithm\":{\"default\":" +
"\"HS256\",\"enum\":[\"HS256\",\"HS512\",\"RS256\"],\"type\":\"string\"},\"base64_secret\"" +
":{\"default\":false,\"type\":\"boolean\"},\"exp\":{\"default\":86400,\"minimum\":1,\"type\":" +
"\"integer\"},\"key\":{\"type\":\"string\"},\"secret\":{\"type\":\"string\"}}," +
"\"required\":[\"key\"],\"type\":\"object\"}",
Sleep: base.SleepTime,
}),
table.Entry("get require-id plugin", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodGet,
Path: "/apisix/admin/schema/plugins/jwt-auth",
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
ExpectBody: "{\"$comment\":\"this is a mark for our injected plugin schema\",\"additionalProperties\":false,\"properties\":{\"disable\":{\"type\":\"boolean\"}},\"type\":\"object\"}",
Sleep: base.SleepTime,
}),
)
})

0 comments on commit 611ab09

Please sign in to comment.