Beispiel #1
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());
                }
            }
        }
Beispiel #2
0
        public async Task TestHandleResponse_unexpectedDigestAsync()
        {
            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")
                })
                {
                    try
                    {
                        await testBlobPuller.HandleResponseAsync(mockResponse).ConfigureAwait(false);

                        Assert.Fail("Receiving an unexpected digest should fail");
                    }
                    catch (UnexpectedBlobDigestException ex)
                    {
                        Assert.AreEqual(
                            "The pulled BLOB has digest '"
                            + testBlobDigest
                            + "', but the request digest was '"
                            + fakeDigest
                            + "'",
                            ex.Message);
                    }
                }
            }
        }