@@ -5,32 +5,48 @@ import (
5
5
)
6
6
7
7
func TestMac_String (t * testing.T ) {
8
- m := & Mac {
9
- Type : Header ,
10
- Credential : & Credential {
11
- ID : "dh37fgj492je" ,
12
- Key : "werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn" ,
13
- Alg : SHA256 ,
8
+ for _ , tc := range []struct {
9
+ name string
10
+ uri string
11
+ expect string
12
+ }{
13
+ {
14
+ name : "non-encoded uri" ,
15
+ uri : "http://example.com:8000/resource/1?b=1&a=2" ,
16
+ expect : "6R4rV5iE+NPoym+WwjeHzjAGXUtLNIxmo1vpMofpLAE=" , // expected value is reference from https://github.com/hueniverse/hawk#protocol-example
14
17
},
15
- Uri : "http://example.com:8000/resource/1?b=1&a=2" ,
16
- Method : "GET" ,
17
- Option : & Option {
18
- TimeStamp : int64 (1353832234 ),
19
- Nonce : "j4h3g2" ,
20
- Ext : "some-app-ext-data" ,
18
+ {
19
+ name : "encoded uri" ,
20
+ uri : "http://example.com:8000/resource/x%2Fy%2Fz?b=1&a=2" ,
21
+ expect : "nurs0/PPVGhFt9v2gzBP4BCRQwzQJwPuIQKLYjoVIQ0=" ,
21
22
},
22
- }
23
-
24
- act , err := m .String ()
25
- if err != nil {
26
- t .Error ("got an error" , err .Error ())
27
- }
28
-
29
- // expected value is reference from https://github.com/hueniverse/hawk#protocol-example
30
- expect := "6R4rV5iE+NPoym+WwjeHzjAGXUtLNIxmo1vpMofpLAE="
31
-
32
- if act != expect {
33
- t .Error ("invalid mac." )
23
+ } {
24
+ t .Run (tc .name , func (t * testing.T ) {
25
+ m := & Mac {
26
+ Type : Header ,
27
+ Credential : & Credential {
28
+ ID : "dh37fgj492je" ,
29
+ Key : "werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn" ,
30
+ Alg : SHA256 ,
31
+ },
32
+ Uri : tc .uri ,
33
+ Method : "GET" ,
34
+ Option : & Option {
35
+ TimeStamp : int64 (1353832234 ),
36
+ Nonce : "j4h3g2" ,
37
+ Ext : "some-app-ext-data" ,
38
+ },
39
+ }
40
+
41
+ act , err := m .String ()
42
+ if err != nil {
43
+ t .Error ("got an error" , err .Error ())
44
+ }
45
+
46
+ if act != tc .expect {
47
+ t .Errorf ("invalid mac: actual=%v, expect=%v" , act , tc .expect )
48
+ }
49
+ })
34
50
}
35
51
}
36
52
0 commit comments