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

Function TestWithDigest

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

Source from the content-addressed store, hash-verified

527}
528
529func TestWithDigest(t *testing.T) {
530 testcases := []struct {
531 name string
532 digest digest.Digest
533 tag string
534 combined string
535 }{
536 {
537 name: "test.com/foo",
538 digest: "sha256:1234567890098765432112345667890098765",
539 combined: "test.com/foo@sha256:1234567890098765432112345667890098765",
540 },
541 {
542 name: "foo",
543 digest: "sha256:1234567890098765432112345667890098765",
544 combined: "foo@sha256:1234567890098765432112345667890098765",
545 },
546 {
547 name: "test.com:8000/foo",
548 digest: "sha256:1234567890098765432112345667890098765",
549 combined: "test.com:8000/foo@sha256:1234567890098765432112345667890098765",
550 },
551 {
552 name: "test.com:8000/foo",
553 digest: "sha256:1234567890098765432112345667890098765",
554 tag: "latest",
555 combined: "test.com:8000/foo:latest@sha256:1234567890098765432112345667890098765",
556 },
557 }
558 for _, testcase := range testcases {
559 failf := func(format string, v ...interface{}) {
560 t.Logf(strconv.Quote(testcase.name)+": "+format, v...)
561 t.Fail()
562 }
563
564 named, err := WithName(testcase.name)
565 if err != nil {
566 failf("error parsing name: %s", err)
567 }
568 if testcase.tag != "" {
569 tagged, err := WithTag(named, testcase.tag)
570 if err != nil {
571 failf("error adding tag")
572 }
573 named = tagged
574 }
575 digested, err := WithDigest(named, testcase.digest)
576 if err != nil {
577 failf("WithDigest failed: %s", err)
578 }
579 if digested.String() != testcase.combined {
580 failf("unexpected: got %q, expected %q", digested.String(), testcase.combined)
581 }
582 }
583}
584
585func TestParseNamed(t *testing.T) {
586 testcases := []struct {

Callers

nothing calls this directly

Calls 4

WithNameFunction · 0.85
WithTagFunction · 0.85
WithDigestFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…