public void TestCreateFromHash_pass() { string goodHash = CreateGoodHash('a'); DescriptorDigest descriptorDigest = DescriptorDigest.FromHash(goodHash); Assert.AreEqual(goodHash, descriptorDigest.GetHash()); Assert.AreEqual("sha256:" + goodHash, descriptorDigest.ToString()); }
public async Task TestPushAsync() { localRegistry.PullAndPushToLocal("busybox", "busybox"); IBlob testLayerBlob = Blobs.From("crepecake"); // Known digest for 'crepecake' DescriptorDigest testLayerBlobDigest = DescriptorDigest.FromHash( "52a9e4d4ba4333ce593707f98564fee1e6d898db0d3602408c0b2a6a424d357c"); IBlob testContainerConfigurationBlob = Blobs.From("12345"); DescriptorDigest testContainerConfigurationBlobDigest = DescriptorDigest.FromHash( "5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5"); // Creates a valid image manifest. V22ManifestTemplate expectedManifestTemplate = new V22ManifestTemplate(); expectedManifestTemplate.AddLayer(9, testLayerBlobDigest); expectedManifestTemplate.SetContainerConfiguration(5, testContainerConfigurationBlobDigest); // Pushes the BLOBs. RegistryClient registryClient = RegistryClient.CreateFactory(EVENT_HANDLERS, "localhost:5000", "testimage") .SetAllowInsecureRegistries(true) .NewRegistryClient(); Assert.IsFalse( await registryClient.PushBlobAsync(testLayerBlobDigest, testLayerBlob, null, _ => { }).ConfigureAwait(false)); Assert.IsFalse( await registryClient.PushBlobAsync( testContainerConfigurationBlobDigest, testContainerConfigurationBlob, null, _ => { }).ConfigureAwait(false)); // Pushes the manifest. DescriptorDigest imageDigest = await registryClient.PushManifestAsync(expectedManifestTemplate, "latest").ConfigureAwait(false); // Pulls the manifest. V22ManifestTemplate manifestTemplate = await registryClient.PullManifestAsync <V22ManifestTemplate>("latest").ConfigureAwait(false); Assert.AreEqual(1, manifestTemplate.Layers.Count); Assert.AreEqual(testLayerBlobDigest, manifestTemplate.Layers[0].Digest); Assert.IsNotNull(manifestTemplate.GetContainerConfiguration()); Assert.AreEqual( testContainerConfigurationBlobDigest, manifestTemplate.GetContainerConfiguration().Digest); // Pulls the manifest by digest. V22ManifestTemplate manifestTemplateByDigest = await registryClient.PullManifestAsync <V22ManifestTemplate>(imageDigest.ToString()).ConfigureAwait(false); Assert.AreEqual( await Digests.ComputeJsonDigestAsync(manifestTemplate).ConfigureAwait(false), await Digests.ComputeJsonDigestAsync(manifestTemplateByDigest).ConfigureAwait(false)); }
public async Task TestHandleResponse_validAsync() { DescriptorDigest expectedDigest = await Digests.ComputeJsonDigestAsync(fakeManifestTemplate).ConfigureAwait(false); using (HttpResponseMessage mockResponse = new HttpResponseMessage { Headers = { { "Docker-Content-Digest", new List <string> { expectedDigest.ToString() } } } }) { Assert.AreEqual(expectedDigest, await testManifestPusher.HandleResponseAsync(mockResponse).ConfigureAwait(false)); } }