mirror of
https://github.com/makayabou/asg-server.git
synced 2026-05-02 17:43:36 +02:00
[test] use subtests
This commit is contained in:
parent
8896245762
commit
aeed25e00b
@ -15,20 +15,24 @@ func makeClient(baseUrl string) *resty.Client {
|
||||
|
||||
func TestPublicDeviceRegister(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
headers map[string]string
|
||||
expectedStatusCode int
|
||||
}{
|
||||
{
|
||||
name: "with valid token",
|
||||
headers: map[string]string{
|
||||
"Authorization": "Bearer 123456789",
|
||||
},
|
||||
expectedStatusCode: 201,
|
||||
},
|
||||
{
|
||||
name: "without token",
|
||||
headers: map[string]string{},
|
||||
expectedStatusCode: 201,
|
||||
},
|
||||
{
|
||||
name: "with invalid token",
|
||||
headers: map[string]string{
|
||||
"Authorization": "Bearer 987654321",
|
||||
},
|
||||
@ -39,37 +43,43 @@ func TestPublicDeviceRegister(t *testing.T) {
|
||||
client := makeClient(PublicURL + "/mobile/v1/device")
|
||||
|
||||
for _, c := range cases {
|
||||
res, err := client.R().
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetBody(`{"name": "Public Device Name", "pushToken": "token"}`).
|
||||
SetHeaders(c.headers).
|
||||
Post("")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
res, err := client.R().
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetBody(`{"name": "Public Device Name", "pushToken": "token"}`).
|
||||
SetHeaders(c.headers).
|
||||
Post("")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if res.StatusCode() != c.expectedStatusCode {
|
||||
t.Fatal(res.StatusCode(), res.String())
|
||||
}
|
||||
if res.StatusCode() != c.expectedStatusCode {
|
||||
t.Fatal(res.StatusCode(), res.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrivateDeviceRegister(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
headers map[string]string
|
||||
expectedStatusCode int
|
||||
}{
|
||||
{
|
||||
name: "with valid token",
|
||||
headers: map[string]string{
|
||||
"Authorization": "Bearer 123456789",
|
||||
},
|
||||
expectedStatusCode: 201,
|
||||
},
|
||||
{
|
||||
name: "without token",
|
||||
headers: map[string]string{},
|
||||
expectedStatusCode: 401,
|
||||
},
|
||||
{
|
||||
name: "with invalid token",
|
||||
headers: map[string]string{
|
||||
"Authorization": "Bearer 987654321",
|
||||
},
|
||||
@ -80,17 +90,19 @@ func TestPrivateDeviceRegister(t *testing.T) {
|
||||
client := makeClient(PrivateURL + "/mobile/v1/device")
|
||||
|
||||
for _, c := range cases {
|
||||
res, err := client.R().
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetBody(`{"name": "Private Device Name", "pushToken": "token"}`).
|
||||
SetHeaders(c.headers).
|
||||
Post("")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
res, err := client.R().
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetBody(`{"name": "Private Device Name", "pushToken": "token"}`).
|
||||
SetHeaders(c.headers).
|
||||
Post("")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if res.StatusCode() != c.expectedStatusCode {
|
||||
t.Fatal(res.StatusCode(), res.String())
|
||||
}
|
||||
if res.StatusCode() != c.expectedStatusCode {
|
||||
t.Fatal(res.StatusCode(), res.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user