-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudience_test.go
52 lines (48 loc) · 881 Bytes
/
audience_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package jwt
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestAudienceMarshalJSON(t *testing.T) {
c := []struct {
a Audience
b string
}{
{Audience{}, `""`},
{Audience{"0"}, `"0"`},
{Audience{"0", "1"}, `["0","1"]`},
}
for _, n := range c {
t.Run("", func(t *testing.T) {
b, err := n.a.MarshalJSON()
if err != nil {
t.Fatal(err)
}
if n.b != string(b) {
t.Errorf(cmp.Diff(n.b, string(b)))
}
})
}
}
func TestAudienceUnmarshalJSON(t *testing.T) {
c := []struct {
a Audience
b []byte
}{
{Audience{}, nil},
{Audience{"0"}, []byte(`"0"`)},
{Audience{"0", "1"}, []byte(`["0","1"]`)},
}
for _, n := range c {
t.Run("", func(t *testing.T) {
a := Audience{}
err := a.UnmarshalJSON(n.b)
if err != nil && n.b != nil {
t.Fatal(err)
}
if d := cmp.Diff(n.a, a); d != "" {
t.Errorf(d)
}
})
}
}