Beispiel #1
0
        public async Task PushBlobAsync_ValidatesArguments_Async()
        {
            var client = new ImageRegistryClient(new HttpClient());
            await Assert.ThrowsAsync <ArgumentNullException>(() => client.PushBlobAsync(null, Stream.Null, string.Empty, default)).ConfigureAwait(false);

            await Assert.ThrowsAsync <ArgumentNullException>(() => client.PushBlobAsync(string.Empty, null, string.Empty, default)).ConfigureAwait(false);

            await Assert.ThrowsAsync <ArgumentNullException>(() => client.PushBlobAsync(string.Empty, Stream.Null, null, default)).ConfigureAwait(false);
        }
Beispiel #2
0
        public async Task Dispose_Works_Async()
        {
            var httpClient = new HttpClient();
            var client     = new ImageRegistryClient(httpClient);

            Assert.False(client.IsDisposed);

            client.Dispose();

            Assert.Throws <ObjectDisposedException>(() => httpClient.BaseAddress = new Uri("http://localhost:5000"));
            Assert.True(client.IsDisposed);

            await Assert.ThrowsAsync <ObjectDisposedException>(() => client.DeleteBlobAsync(null, null, default)).ConfigureAwait(false);

            await Assert.ThrowsAsync <ObjectDisposedException>(() => client.DeleteManifestAsync(null, null, default)).ConfigureAwait(false);

            await Assert.ThrowsAsync <ObjectDisposedException>(() => client.GetBlobAsync(null, null, default)).ConfigureAwait(false);

            await Assert.ThrowsAsync <ObjectDisposedException>(() => client.GetManifestAsync(null, null, default)).ConfigureAwait(false);

            await Assert.ThrowsAsync <ObjectDisposedException>(() => client.ListTagsAsync(null, default)).ConfigureAwait(false);

            await Assert.ThrowsAsync <ObjectDisposedException>(() => client.PushBlobAsync(null, null, null, default)).ConfigureAwait(false);

            await Assert.ThrowsAsync <ObjectDisposedException>(() => client.PushManifestAsync(null, null, null, default)).ConfigureAwait(false);
        }
Beispiel #3
0
        public async Task PushBlobAsync_InvalidDigest_Throws_Async()
        {
            var handler = new MockHttpMessageHandler();

            handler
            .Expect(HttpMethod.Post, "http://localhost:5000/v2/registry/blobs/uploads/")
            .WithContent(string.Empty)
            .Respond(
                (request) =>
            {
                var response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.Accepted,
                };

                response.Headers.Location = new Uri("http://localhost:5000/v2/registry/blobs/uploads/65707092-6422-4b33-bba7-c655318616e9?_state=state_string");
                return(response);
            });

            handler
            .Expect(HttpMethod.Put, "http://localhost:5000/v2/registry/blobs/uploads/65707092-6422-4b33-bba7-c655318616e9?_state=state_string&digest=sha256:0")
            .Respond(HttpStatusCode.BadRequest);

            using (var blobStream = new MemoryStream())
            {
                var httpClient = handler.ToHttpClient();
                httpClient.BaseAddress = new Uri("http://localhost:5000");

                var client = new ImageRegistryClient(httpClient);
                await Assert.ThrowsAsync <ImageRegistryException>(() => client.PushBlobAsync("registry", blobStream, "sha256:0", default)).ConfigureAwait(false);
            }

            handler.VerifyNoOutstandingExpectation();
        }
Beispiel #4
0
        public async Task PushBlobAsync_InvalidRegistry_Throws_Async()
        {
            var handler = new MockHttpMessageHandler();

            handler
            .Expect(HttpMethod.Post, "http://localhost:5000/v2/REGISTRY/blobs/uploads/")
            .WithContent(string.Empty)
            .Respond(HttpStatusCode.NotFound);

            var httpClient = handler.ToHttpClient();

            httpClient.BaseAddress = new Uri("http://localhost:5000");

            var client = new ImageRegistryClient(httpClient);
            await Assert.ThrowsAsync <ImageRegistryException>(() => client.PushBlobAsync("REGISTRY", new MemoryStream(), "sha:0", default)).ConfigureAwait(false);

            handler.VerifyNoOutstandingExpectation();
        }