MCPcopy
hub / github.com/perkeep/perkeep / TestJSONUnmarshalSized

Function TestJSONUnmarshalSized

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

Source from the content-addressed store, hash-verified

231}
232
233func TestJSONUnmarshalSized(t *testing.T) {
234 var sb SizedRef
235 if err := json.Unmarshal([]byte(`{
236 "blobRef": "sha1-ce284c167558a9ef22df04390c87a6d0c9ed9659",
237 "size": 123}`), &sb); err != nil {
238 t.Fatalf("Unmarshal: %v", err)
239 }
240 want := SizedRef{
241 Ref: MustParse("sha1-ce284c167558a9ef22df04390c87a6d0c9ed9659"),
242 Size: 123,
243 }
244 if sb != want {
245 t.Fatalf("got %q, want %q", sb, want)
246 }
247
248 sb = SizedRef{}
249 if err := json.Unmarshal([]byte(`{}`), &sb); err != nil {
250 t.Fatalf("Unmarshal: %v", err)
251 }
252 if sb.Valid() {
253 t.Fatal("sized blobref is valid and shouldn't be")
254 }
255
256 sb = SizedRef{}
257 if err := json.Unmarshal([]byte(`{"blobRef":null, "size": 456}`), &sb); err != nil {
258 t.Fatalf("Unmarshal: %v", err)
259 }
260 if sb.Valid() {
261 t.Fatal("sized blobref is valid and shouldn't be")
262 }
263}
264
265func TestJSONMarshalSized(t *testing.T) {
266 sb := SizedRef{

Callers

nothing calls this directly

Calls 4

ValidMethod · 0.95
MustParseFunction · 0.85
FatalMethod · 0.80
FatalfMethod · 0.65

Tested by

no test coverage detected