@@ -15,20 +15,24 @@ func makeClient(baseUrl string) *resty.Client {
15
15
16
16
func TestPublicDeviceRegister (t * testing.T ) {
17
17
cases := []struct {
18
+ name string
18
19
headers map [string ]string
19
20
expectedStatusCode int
20
21
}{
21
22
{
23
+ name : "with valid token" ,
22
24
headers : map [string ]string {
23
25
"Authorization" : "Bearer 123456789" ,
24
26
},
25
27
expectedStatusCode : 201 ,
26
28
},
27
29
{
30
+ name : "without token" ,
28
31
headers : map [string ]string {},
29
32
expectedStatusCode : 201 ,
30
33
},
31
34
{
35
+ name : "with invalid token" ,
32
36
headers : map [string ]string {
33
37
"Authorization" : "Bearer 987654321" ,
34
38
},
@@ -39,37 +43,43 @@ func TestPublicDeviceRegister(t *testing.T) {
39
43
client := makeClient (PublicURL + "/mobile/v1/device" )
40
44
41
45
for _ , c := range cases {
42
- res , err := client .R ().
43
- SetHeader ("Content-Type" , "application/json" ).
44
- SetBody (`{"name": "Public Device Name", "pushToken": "token"}` ).
45
- SetHeaders (c .headers ).
46
- Post ("" )
47
- if err != nil {
48
- t .Fatal (err )
49
- }
46
+ t .Run (c .name , func (t * testing.T ) {
47
+ res , err := client .R ().
48
+ SetHeader ("Content-Type" , "application/json" ).
49
+ SetBody (`{"name": "Public Device Name", "pushToken": "token"}` ).
50
+ SetHeaders (c .headers ).
51
+ Post ("" )
52
+ if err != nil {
53
+ t .Fatal (err )
54
+ }
50
55
51
- if res .StatusCode () != c .expectedStatusCode {
52
- t .Fatal (res .StatusCode (), res .String ())
53
- }
56
+ if res .StatusCode () != c .expectedStatusCode {
57
+ t .Fatal (res .StatusCode (), res .String ())
58
+ }
59
+ })
54
60
}
55
61
}
56
62
57
63
func TestPrivateDeviceRegister (t * testing.T ) {
58
64
cases := []struct {
65
+ name string
59
66
headers map [string ]string
60
67
expectedStatusCode int
61
68
}{
62
69
{
70
+ name : "with valid token" ,
63
71
headers : map [string ]string {
64
72
"Authorization" : "Bearer 123456789" ,
65
73
},
66
74
expectedStatusCode : 201 ,
67
75
},
68
76
{
77
+ name : "without token" ,
69
78
headers : map [string ]string {},
70
79
expectedStatusCode : 401 ,
71
80
},
72
81
{
82
+ name : "with invalid token" ,
73
83
headers : map [string ]string {
74
84
"Authorization" : "Bearer 987654321" ,
75
85
},
@@ -80,17 +90,19 @@ func TestPrivateDeviceRegister(t *testing.T) {
80
90
client := makeClient (PrivateURL + "/mobile/v1/device" )
81
91
82
92
for _ , c := range cases {
83
- res , err := client .R ().
84
- SetHeader ("Content-Type" , "application/json" ).
85
- SetBody (`{"name": "Private Device Name", "pushToken": "token"}` ).
86
- SetHeaders (c .headers ).
87
- Post ("" )
88
- if err != nil {
89
- t .Fatal (err )
90
- }
93
+ t .Run (c .name , func (t * testing.T ) {
94
+ res , err := client .R ().
95
+ SetHeader ("Content-Type" , "application/json" ).
96
+ SetBody (`{"name": "Private Device Name", "pushToken": "token"}` ).
97
+ SetHeaders (c .headers ).
98
+ Post ("" )
99
+ if err != nil {
100
+ t .Fatal (err )
101
+ }
91
102
92
- if res .StatusCode () != c .expectedStatusCode {
93
- t .Fatal (res .StatusCode (), res .String ())
94
- }
103
+ if res .StatusCode () != c .expectedStatusCode {
104
+ t .Fatal (res .StatusCode (), res .String ())
105
+ }
106
+ })
95
107
}
96
108
}
0 commit comments