Skip to content

Commit

Permalink
update testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
idbeta committed Nov 26, 2020
1 parent eb64156 commit 34c5b82
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 201 deletions.
201 changes: 0 additions & 201 deletions api/test/e2e/consumer_e2e_part2_test.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@
package e2e

import (
"io/ioutil"
"net/http"
"strings"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/tidwall/gjson"
)

//case 1: add consumer with username
Expand Down Expand Up @@ -161,6 +167,24 @@ func TestConsumer_delete_consumer(t *testing.T) {
}
}

//case 4: delete consumer(id: not_found)
func TestConsumer_delete_notexit_consumer(t *testing.T) {
tests := []HttpTestCase{
{
caseDesc: "delete notexit consumer",
Object: MangerApiExpect(t),
Method: http.MethodDelete,
Path: "/apisix/admin/consumers/notexit",
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusNotFound,
},
}

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

//case 5: create consumer with error key
func TestConsumer_create_consumer_with_error_key(t *testing.T) {
tests := []HttpTestCase{
Expand Down Expand Up @@ -322,6 +346,72 @@ func TestConsumer_add_consumer_with_labels(t *testing.T) {
}
}

//case 8: update consumer, check if updatetime is updated
func TestConsumer_create_consumer_with_createtime_updatetime(t *testing.T) {
//create consumer, save the result_A ( create_time and update_time )
data := `{
"username":"case_8",
"desc": "new consumer"
}`
request, _ := http.NewRequest("PUT", "http://127.0.0.1:8080/apisix/admin/consumers", strings.NewReader(data))
request.Header.Add("Authorization", token)
resp, _ := http.DefaultClient.Do(request)
defer resp.Body.Close()
respBody, _ := ioutil.ReadAll(resp.Body)
code := gjson.Get(string(respBody), "code")
assert.Equal(t, code.String(), "0")

time.Sleep(1 * time.Second)

request, _ = http.NewRequest("GET", "http://127.0.0.1:8080/apisix/admin/consumers/case_8", nil)
request.Header.Add("Authorization", token)
resp, _ = http.DefaultClient.Do(request)
defer resp.Body.Close()
respBody, _ = ioutil.ReadAll(resp.Body)
createtime := gjson.Get(string(respBody), "data.create_time")
updatetime := gjson.Get(string(respBody), "data.update_time")

//create consumer again, compare the new result and the result_A
data = `{
"username":"case_8",
"desc": "new consumer haha"
}`
request, _ = http.NewRequest("PUT", "http://127.0.0.1:8080/apisix/admin/consumers", strings.NewReader(data))
request.Header.Add("Authorization", token)
resp, _ = http.DefaultClient.Do(request)
defer resp.Body.Close()
respBody, _ = ioutil.ReadAll(resp.Body)
code = gjson.Get(string(respBody), "code")
assert.Equal(t, code.String(), "0")

time.Sleep(1 * time.Second)

request, _ = http.NewRequest("GET", "http://127.0.0.1:8080/apisix/admin/consumers/case_8", nil)
request.Header.Add("Authorization", token)
resp, _ = http.DefaultClient.Do(request)
defer resp.Body.Close()
respBody, _ = ioutil.ReadAll(resp.Body)
createtime2 := gjson.Get(string(respBody), "data.create_time")
updatetime2 := gjson.Get(string(respBody), "data.update_time")

assert.Equal(t, createtime.String(), createtime2.String())
assert.NotEqual(t, updatetime.String(), updatetime2.String())

//deletea consumer
request, _ = http.NewRequest("DELETE", "http://127.0.0.1:8080/apisix/admin/consumers/case_8", nil)
request.Header.Add("Authorization", token)
_, err := http.DefaultClient.Do(request)
assert.Nil(t, err)

}

// TODO it's a bug here, see: https://github.com/apache/apisix-dashboard/issues/852

// TODO it's a bug here, see: https://github.com/apache/apisix-dashboard/issues/568

// TODO it's a bug here, see: https://github.com/apache/apisix-dashboard/issues/870


//Teardown
func TestConsumer_teardown(t *testing.T) {
tests := []HttpTestCase{
Expand Down

0 comments on commit 34c5b82

Please sign in to comment.