Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rewrite e2e test(server_info_test) with ginkgo #1550

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions api/test/e2enew/server_info/server_info_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 server_info

import (
"testing"
"time"

"github.com/onsi/ginkgo"

"e2enew/base"
)

func TestRoute(t *testing.T) {
ginkgo.RunSpecs(t, "server info suite")
}

var _ = ginkgo.AfterSuite(func() {
time.Sleep(base.SleepTime)
})
Original file line number Diff line number Diff line change
Expand Up @@ -14,127 +14,114 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package e2e
package server_info

import (
"net/http"
"testing"
"time"

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

"e2enew/base"
)

func TestServerInfo_Get(t *testing.T) {
// wait for apisix report
time.Sleep(2 * time.Second)
testCases := []HttpTestCase{
{
Desc: "get server info",
Object: ManagerApiExpect(t),
var _ = ginkgo.Describe("server info test", func() {
table.DescribeTable("get server info",
func(tc base.HttpTestCase) {
time.Sleep(2 * time.Second)
base.RunTestCase(tc)
},
table.Entry("get server info(apisix-server1)", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Path: "/apisix/admin/server_info/apisix-server1",
Method: http.MethodGet,
Headers: map[string]string{"Authorization": token},
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
ExpectBody: "\"hostname\":\"apisix_server1\"",
},
{
Desc: "get server info",
Object: ManagerApiExpect(t),
}),
table.Entry("get server info(apisix-server2)", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Path: "/apisix/admin/server_info/apisix-server2",
Method: http.MethodGet,
Headers: map[string]string{"Authorization": token},
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
ExpectBody: "\"hostname\":\"apisix_server2\"",
},
}
}),
)

for _, tc := range testCases {
testCaseCheck(tc, t)
}
}

func TestServerInfo_List(t *testing.T) {
testCases := []HttpTestCase{
{
Desc: "list all server info",
Object: ManagerApiExpect(t),
table.DescribeTable("get server info list",
func(tc base.HttpTestCase) {
base.RunTestCase(tc)
},
table.Entry("list all server info", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Path: "/apisix/admin/server_info",
Method: http.MethodGet,
Headers: map[string]string{"Authorization": token},
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
ExpectBody: "\"total_size\":2",
},
{
Desc: "list server info with hostname",
Object: ManagerApiExpect(t),
}),
table.Entry("list server info with hostname", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Path: "/apisix/admin/server_info",
Query: "hostname=apisix_",
Method: http.MethodGet,
Headers: map[string]string{"Authorization": token},
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
ExpectBody: "\"total_size\":2",
},
{
Desc: "list server info with hostname",
Object: ManagerApiExpect(t),
}),
table.Entry("list server info with hostname", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Path: "/apisix/admin/server_info",
Query: "hostname=apisix_server2",
Method: http.MethodGet,
Headers: map[string]string{"Authorization": token},
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
ExpectBody: "\"total_size\":1",
},
}

for _, tc := range testCases {
testCaseCheck(tc, t)
}
}
}),
)
})

func TestServerInfo_Get_OmitEmptyValue(t *testing.T) {
// wait for apisix report
time.Sleep(2 * time.Second)
testCases := []HttpTestCase{
{
Desc: "get server info",
Object: ManagerApiExpect(t),
var _ = ginkgo.Describe("server info test omitEmptyValue", func() {
table.DescribeTable("server info get omitEmptyValue",
func(tc base.HttpTestCase) {
time.Sleep(2 * time.Second)
base.RunTestCase(tc)
},
table.Entry("get server info", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Path: "/apisix/admin/server_info/apisix-server1",
Method: http.MethodGet,
Headers: map[string]string{"Authorization": token},
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
UnexpectBody: []string{"\"create_time\":", "\"update_time\":"},
},
}
}),
)

for _, tc := range testCases {
testCaseCheck(tc, t)
}
}

func TestServerInfo_List_OmitEmptyValue(t *testing.T) {
testCases := []HttpTestCase{
{
Desc: "list all server info",
Object: ManagerApiExpect(t),
table.DescribeTable("server info list omitEmptyValue",
func(tc base.HttpTestCase) {
base.RunTestCase(tc)
},
table.Entry("list all server info", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Path: "/apisix/admin/server_info",
Method: http.MethodGet,
Headers: map[string]string{"Authorization": token},
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
ExpectBody: "\"total_size\":2",
UnexpectBody: []string{"\"create_time\":", "\"update_time\":"},
},
{
Desc: "list server info with hostname",
Object: ManagerApiExpect(t),
}),
table.Entry("list server info with hostname", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Path: "/apisix/admin/server_info",
Query: "hostname=apisix_",
Method: http.MethodGet,
Headers: map[string]string{"Authorization": token},
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
ExpectBody: "\"total_size\":2",
UnexpectBody: []string{"\"create_time\":", "\"update_time\":"},
},
}
}),
)

for _, tc := range testCases {
testCaseCheck(tc, t)
}
}
})