MCPcopy
hub / github.com/perkeep/perkeep / TestJSONUnmarshal

Function TestJSONUnmarshal

pkg/blob/ref_test.go:135–162  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

133}
134
135func TestJSONUnmarshal(t *testing.T) {
136 var f Foo
137 if err := json.Unmarshal([]byte(`{"foo": "abc-def123", "other": 123}`), &f); err != nil {
138 t.Fatalf("Unmarshal: %v", err)
139 }
140 if !f.B.Valid() {
141 t.Fatal("blobref is nil")
142 }
143 if g, e := f.B.String(), "abc-def123"; g != e {
144 t.Errorf("got %q, want %q", g, e)
145 }
146
147 f = Foo{}
148 if err := json.Unmarshal([]byte(`{}`), &f); err != nil {
149 t.Fatalf("Unmarshal: %v", err)
150 }
151 if f.B.Valid() {
152 t.Fatal("blobref is valid and shouldn't be")
153 }
154
155 f = Foo{}
156 if err := json.Unmarshal([]byte(`{"foo":null}`), &f); err != nil {
157 t.Fatalf("Unmarshal: %v", err)
158 }
159 if f.B.Valid() {
160 t.Fatal("blobref is valid and shouldn't be")
161 }
162}
163
164func TestJSONMarshal(t *testing.T) {
165 f := &Foo{}

Callers

nothing calls this directly

Calls 4

FatalMethod · 0.80
FatalfMethod · 0.65
ValidMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected