Debian Codegraph @

object_id_test.go

raw symbols SCIP
1 package activitypub
2
3 import (
4 "bytes"
5 "testing"
6 )
7
8 func TestID_UnmarshalJSON(t *testing.T) {
9 tests := []struct {
10 name string
11 data []byte
12 want ID
13 }{
14 {
15 name: "nil",
16 data: []byte(nil),
17 want: "",
18 },
19 {
20 name: "empty",
21 data: []byte(""),
22 want: "",
23 },
24 {
25 name: "something",
26 data: []byte("something"),
27 want: "something",
28 },
29 }
30
31 for _, tt := range tests {
32 t.Run(tt.name, func(t *testing.T) {
33 got := ID("")
34 got.UnmarshalJSON(tt.data)
35 if got != tt.want {
36 t.Errorf("UnmarshalJSON() = %v, want %v", got, tt.want)
37 }
38 })
39 }
40 }
41
42 func TestID_MarshalJSON(t *testing.T) {
43 tests := []struct {
44 name string
45 i ID
46 want []byte
47 wantErr error
48 }{
49 {
50 name: "nil",
51 i: "",
52 want: []byte(nil),
53 },
54 {
55 name: "empty",
56 i: "",
57 want: []byte(""),
58 },
59 {
60 name: "something",
61 i: "something",
62 want: []byte(`"something"`),
63 },
64 }
65
66 for _, tt := range tests {
67 t.Run(tt.name, func(t *testing.T) {
68 got, err := tt.i.MarshalJSON()
69 if tt.wantErr != nil {
70 if err == nil {
71 t.Errorf("MarshalJSON() returned no error but expected %v", tt.wantErr)
72 }
73 if tt.wantErr.Error() != err.Error() {
74 t.Errorf("MarshalJSON() returned error %v but expected %v", err, tt.wantErr)
75 }
76 return
77 }
78 if !bytes.Equal(got, tt.want) {
79 t.Errorf("MarshalJSON() = %s, want %s", got, tt.want)
80 }
81 })
82 }
83 t.Skip("TODO")
84 }
85
86 func TestID_IsValid(t *testing.T) {
87 tests := []struct {
88 name string
89 i ID
90 want bool
91 }{
92 {
93 name: "empty",
94 i: "",
95 want: false,
96 },
97 {
98 name: "something",
99 i: "something",
100 want: true,
101 },
102 }
103 for _, tt := range tests {
104 t.Run(tt.name, func(t *testing.T) {
105 if got := tt.i.IsValid(); got != tt.want {
106 t.Errorf("IsValid() = %v, want %v", got, tt.want)
107 }
108 })
109 }
110 }