(t *testing.T)
| 56 | } |
| 57 | |
| 58 | func TestOCIDistributionGetter(t *testing.T) { |
| 59 | // For this test we'll use an in-memory-only repository store implementation, |
| 60 | // although we need to use a local wrapper to work around a leaky abstraction |
| 61 | // where the in-memory store doesn't behave quite the same as a real OCI |
| 62 | // Distribution registry client would. :( |
| 63 | // |
| 64 | // In real use ociDistributionGetter is more likely to be used with ORAS-Go's |
| 65 | // remote registry client implementation, but that's the caller's responsibility |
| 66 | // to decide if so. |
| 67 | mainStore := digestResolvingInMemoryOCIStore{ |
| 68 | orasMemoryStore.New(), |
| 69 | } |
| 70 | |
| 71 | // We'll build some fake-but-valid module packages to put in this store so |
| 72 | // that we can test various valid source address inputs. |
| 73 | latestBlobDesc := ociPushFakeModulePackageBlob(t, "content of latest", mainStore) |
| 74 | latestManifestDesc := ociPushFakeImageManifest(t, latestBlobDesc, ociIndexManifestArtifactType, mainStore) |
| 75 | ociCreateTag(t, "latest", latestManifestDesc, mainStore) |
| 76 | fooBlobDesc := ociPushFakeModulePackageBlob(t, "content of foo", mainStore) |
| 77 | fooManifestDesc := ociPushFakeImageManifest(t, fooBlobDesc, ociIndexManifestArtifactType, mainStore) |
| 78 | ociCreateTag(t, "foo", fooManifestDesc, mainStore) |
| 79 | digestBlobDesc := ociPushFakeModulePackageBlob(t, "content of digest-only reference", mainStore) |
| 80 | digestManifestDesc := ociPushFakeImageManifest(t, digestBlobDesc, ociIndexManifestArtifactType, mainStore) |
| 81 | digestManifestDigestStr := digestManifestDesc.Digest.String() |
| 82 | |
| 83 | // We'll log the digests of the three manifests we're going to use in |
| 84 | // the tests below just in case they appear as part of error messages, |
| 85 | // so we can understand what failed. |
| 86 | t.Logf("'latest' tag\nmanifest: %s\nblob: %s", latestManifestDesc.Digest, latestBlobDesc.Digest) |
| 87 | t.Logf("'foo' tag\nmanifest: %s\nblob: %s", fooManifestDesc.Digest, fooBlobDesc.Digest) |
| 88 | t.Logf("untagged manifest\nmanifest: %s\nblob: %s", digestManifestDigestStr, digestBlobDesc.Digest) |
| 89 | |
| 90 | ociGetter := &ociDistributionGetter{ |
| 91 | getOCIRepositoryStore: func(ctx context.Context, registryDomain, repositoryName string) (OCIRepositoryStore, error) { |
| 92 | if registryDomain != "example.com" { |
| 93 | return nil, fmt.Errorf("no such registry") |
| 94 | } |
| 95 | switch repositoryName { |
| 96 | case "main": |
| 97 | return mainStore, nil |
| 98 | case "empty": |
| 99 | // We'll just return a completely empty store for this one |
| 100 | return orasMemoryStore.New(), nil |
| 101 | default: |
| 102 | return nil, fmt.Errorf("no such repository") |
| 103 | } |
| 104 | }, |
| 105 | } |
| 106 | |
| 107 | tests := []struct { |
| 108 | source string |
| 109 | wantFileContent string |
| 110 | wantError string |
| 111 | }{ |
| 112 | { |
| 113 | source: "oci://example.com/main", |
| 114 | wantFileContent: `content of latest`, |
| 115 | }, |
nothing calls this directly
no test coverage detected