-
Notifications
You must be signed in to change notification settings - Fork 534
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
test: add consumer e2e test for manager-api #830
Changes from 2 commits
5eb14c1
8af23cd
af109cf
d77b790
ec96439
845beba
dc8187f
0032669
2ccb8fc
eb64156
34c5b82
27c85c7
71a708e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
/* | ||
* 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 e2e | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
//CASE 1: add consumer with username | ||
func TestConsumer_add_consumer_with_username(t *testing.T) { | ||
tests := []HttpTestCase{ | ||
{ | ||
caseDesc: "create consumer", | ||
Object: MangerApiExpect(t), | ||
Path: "/apisix/admin/consumers", | ||
Method: http.MethodPut, | ||
Body: `{ | ||
"username": "jack", | ||
"plugins": { | ||
"key-auth": { | ||
"key": "auth-one" | ||
} | ||
}, | ||
"desc": "test description" | ||
}`, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
}, | ||
{ | ||
caseDesc: "create route", | ||
Object: MangerApiExpect(t), | ||
Method: http.MethodPut, | ||
Path: "/apisix/admin/routes/r1", | ||
Body: `{ | ||
"uri": "/hello", | ||
"plugins": { | ||
"key-auth": {} | ||
}, | ||
"upstream": { | ||
"type": "roundrobin", | ||
"nodes": { | ||
"172.16.238.20:1980": 1 | ||
} | ||
} | ||
}`, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
}, | ||
{ | ||
caseDesc: "verify route", | ||
Object: APISIXExpect(t), | ||
Method: http.MethodGet, | ||
Path: "/hello", | ||
Headers: map[string]string{"apikey": "auth-one"}, | ||
ExpectStatus: http.StatusOK, | ||
Sleep: sleepTime, //sleep x millisecond before verify route | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to check body. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to check before consumer created. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, thanks for the suggestion, I already add it now. |
||
}, | ||
{ | ||
caseDesc: "verify route without auth", | ||
Object: APISIXExpect(t), | ||
Method: http.MethodGet, | ||
Path: "/hello", | ||
ExpectStatus: http.StatusUnauthorized, | ||
Sleep: sleepTime, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to delete the |
||
} | ||
|
||
for _, tc := range tests { | ||
testCaseCheck(tc) | ||
} | ||
} | ||
|
||
//CASE 2: add consumer without username | ||
func TestConsumer_add_consumer_without_username(t *testing.T) { | ||
tests := []HttpTestCase{ | ||
{ | ||
caseDesc: "create consumer", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bad title.
|
||
Object: MangerApiExpect(t), | ||
Path: "/apisix/admin/consumers", | ||
Method: http.MethodPut, | ||
Body: `{ | ||
"plugins": { | ||
"key-auth": { | ||
"key": "auth-new" | ||
} | ||
}, | ||
"desc": "test description" | ||
}`, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusBadRequest, | ||
}, | ||
{ | ||
caseDesc: "verify route", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to create the |
||
Object: APISIXExpect(t), | ||
Method: http.MethodGet, | ||
Path: "/hello", | ||
Headers: map[string]string{"apikey": "auth-new"}, | ||
ExpectStatus: http.StatusUnauthorized, | ||
Sleep: sleepTime, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
testCaseCheck(tc) | ||
} | ||
} | ||
|
||
//CASE 3: add consumer with labels | ||
|
||
idbeta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//CASE 4: delete consumer | ||
func TestConsumer_delete_consumer(t *testing.T) { | ||
tests := []HttpTestCase{ | ||
{ | ||
caseDesc: "delete consumer", | ||
Object: MangerApiExpect(t), | ||
Method: http.MethodDelete, | ||
Path: "/apisix/admin/consumers/jack", | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
}, | ||
idbeta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
caseDesc: "verify route", | ||
Object: APISIXExpect(t), | ||
Method: http.MethodGet, | ||
Path: "/hello", | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusUnauthorized, | ||
Sleep: sleepTime, //sleep x millisecond before verify route | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
testCaseCheck(tc) | ||
} | ||
} | ||
|
||
//CASE 5: Teardown | ||
func TestConsumer_teardown(t *testing.T) { | ||
_ = []HttpTestCase{ | ||
{ | ||
caseDesc: "delete route", | ||
Object: MangerApiExpect(t), | ||
Method: http.MethodDelete, | ||
Path: "/apisix/admin/routes/r1", | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
}, | ||
{ | ||
caseDesc: "delete consumer", | ||
Object: MangerApiExpect(t), | ||
Method: http.MethodDelete, | ||
Path: "/apisix/admin/consumers/jack", | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
}, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
desc: hit route with correct
key