Example #1
0
        public async Task TestPullAsync()
        {
            // Pulls the busybox image.
            localRegistry.PullAndPushToLocal("busybox", "busybox");
            RegistryClient registryClient =
                RegistryClient.CreateFactory(EventHandlers.NONE, "localhost:5000", "busybox")
                .SetAllowInsecureRegistries(true)
                .NewRegistryClient();
            V21ManifestTemplate manifestTemplate =
                await registryClient.PullManifestAsync <V21ManifestTemplate>("latest").ConfigureAwait(false);

            DescriptorDigest realDigest = manifestTemplate.GetLayerDigests().First();

            // Pulls a layer BLOB of the busybox image.
            LongAdder totalByteCount = new LongAdder();
            LongAdder expectedSize   = new LongAdder();
            IBlob     pulledBlob     =
                registryClient.PullBlob(
                    realDigest,
                    size =>
            {
                Assert.AreEqual(0, expectedSize.Sum());
                expectedSize.Add(size);
            },
                    totalByteCount.Add);
            BlobDescriptor blobDescriptor = await pulledBlob.WriteToAsync(Stream.Null).ConfigureAwait(false);

            Assert.AreEqual(realDigest, blobDescriptor.GetDigest());
            Assert.IsTrue(expectedSize.Sum() > 0);
            Assert.AreEqual(expectedSize.Sum(), totalByteCount.Sum());
        }
Example #2
0
        public async Task TestHandleResponseAsync()
        {
            using (MemoryStream blobContent = new MemoryStream(Encoding.UTF8.GetBytes("some BLOB content")))
            {
                BlobDescriptor descriptor = await Digests.ComputeDigestAsync(blobContent).ConfigureAwait(false);

                DescriptorDigest testBlobDigest = descriptor.GetDigest();
                blobContent.Position = 0;

                using (HttpResponseMessage mockResponse = new HttpResponseMessage()
                {
                    Content = new StringContent("some BLOB content")
                })
                {
                    LongAdder  byteCount  = new LongAdder();
                    BlobPuller blobPuller =
                        new BlobPuller(
                            fakeRegistryEndpointRequestProperties,
                            testBlobDigest,
                            layerOutputStream,
                            size => Assert.AreEqual("some BLOB content".Length, size),
                            byteCount.Add);
                    await blobPuller.HandleResponseAsync(mockResponse).ConfigureAwait(false);

                    Assert.AreEqual(
                        "some BLOB content",
                        Encoding.UTF8.GetString(layerContentOutputStream.ToArray()));
                    Assert.AreEqual(testBlobDigest, layerOutputStream.ComputeDigest().GetDigest());
                    Assert.AreEqual("some BLOB content".Length, byteCount.Sum());
                }
            }
        }
Example #3
0
        public async Task TestWriter_getContentAsync()
        {
            LongAdder       byteCount = new LongAdder();
            BlobHttpContent body      = testBlobPusher.CreateWriter(mockURL, byteCount.Add).GetContent();

            Assert.IsNotNull(body);
            Assert.AreEqual("application/octet-stream", body.Headers.ContentType.MediaType);

            using (MemoryStream byteArrayOutputStream = new MemoryStream())
            {
                await body.CopyToAsync(byteArrayOutputStream).ConfigureAwait(false);

                Assert.AreEqual(
                    TEST_BLOB_CONTENT, Encoding.UTF8.GetString(byteArrayOutputStream.ToArray()));
                Assert.AreEqual(TEST_BLOB_CONTENT.Length, byteCount.Sum());
            }
        }