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

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

            await Assert.ThrowsAsync <ArgumentNullException>(() => client.PushManifestAsync(string.Empty, string.Empty, null, default)).ConfigureAwait(false);
        }
示例#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);
        }
示例#3
0
        public async Task PushManifestAsync_Works_Async()
        {
            var handler = new MockHttpMessageHandler();

            handler
            .Expect(HttpMethod.Put, "http://localhost:5000/v2/registry/manifests/my-tag")
            .With((request) => request.Content is StreamContent)
            .With((request) => request.Content.Headers.ContentType.MediaType == "application/vnd.oci.image.manifest.v1+json")
            .Respond(
                (request) =>
            {
                var response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.Created,
                };

                response.Headers.Location = new Uri("http://localhost:5000/v2/registry/manifests/my-tag");
                return(response);
            });

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

                var client = new ImageRegistryClient(httpClient);

                var result = await client.PushManifestAsync("registry", "my-tag", blobStream, default).ConfigureAwait(false);

                Assert.Equal(new Uri("http://localhost:5000/v2/registry/manifests/my-tag"), result);
            }

            handler.VerifyNoOutstandingExpectation();
        }
示例#4
0
        public async Task PushManifestAsync_Error_Throws_Async()
        {
            var handler = new MockHttpMessageHandler();

            handler
            .Expect(HttpMethod.Put, "http://localhost:5000/v2/registry/manifests/my-tag")
            .With((request) => request.Content is StreamContent)
            .With((request) => request.Content.Headers.ContentType.MediaType == "application/vnd.oci.image.manifest.v1+json")
            .Respond(HttpStatusCode.InternalServerError, new StringContent("{\"errors\":[{\"code\":\"UNKNOWN\",\"message\":\"unknown error\",\"detail\":{}}]}\n", Encoding.UTF8, "application/json"));

            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.PushManifestAsync("registry", "my-tag", blobStream, default)).ConfigureAwait(false);
            }

            handler.VerifyNoOutstandingExpectation();
        }