MCPcopy Create free account
hub / github.com/containers/image / TestSerialization

Function TestSerialization

docker/reference/reference_test.go:344–465  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

342}
343
344func TestSerialization(t *testing.T) {
345 testcases := []struct {
346 description string
347 input string
348 name string
349 tag string
350 digest string
351 err error
352 }{
353 {
354 description: "empty value",
355 err: ErrNameEmpty,
356 },
357 {
358 description: "just a name",
359 input: "example.com:8000/named",
360 name: "example.com:8000/named",
361 },
362 {
363 description: "name with a tag",
364 input: "example.com:8000/named:tagged",
365 name: "example.com:8000/named",
366 tag: "tagged",
367 },
368 {
369 description: "name with digest",
370 input: "other.com/named@sha256:1234567890098765432112345667890098765432112345667890098765432112",
371 name: "other.com/named",
372 digest: "sha256:1234567890098765432112345667890098765432112345667890098765432112",
373 },
374 }
375 for _, testcase := range testcases {
376 failf := func(format string, v ...interface{}) {
377 t.Logf(strconv.Quote(testcase.input)+": "+format, v...)
378 t.Fail()
379 }
380
381 m := map[string]string{
382 "Description": testcase.description,
383 "Field": testcase.input,
384 }
385 b, err := json.Marshal(m)
386 if err != nil {
387 failf("error marshaling: %v", err)
388 }
389 t := serializationType{}
390
391 if err := json.Unmarshal(b, &t); err != nil {
392 if testcase.err == nil {
393 failf("error unmarshaling: %v", err)
394 }
395 if err != testcase.err {
396 failf("wrong error, expected %v, got %v", testcase.err, err)
397 }
398
399 continue
400 } else if testcase.err != nil {
401 failf("expected error unmarshaling: %v", testcase.err)

Callers

nothing calls this directly

Calls 6

AsFieldFunction · 0.85
ReferenceMethod · 0.65
NameMethod · 0.65
TagMethod · 0.65
StringMethod · 0.65
DigestMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…