Esempio n. 1
0
        public async Task GetManifestAsync_ValidatesArguments_Async()
        {
            var client = new ImageRegistryClient(new HttpClient());
            await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetManifestAsync(null, string.Empty, default)).ConfigureAwait(false);

            await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetManifestAsync(string.Empty, null, default)).ConfigureAwait(false);
        }
Esempio n. 2
0
        public async Task GetManifestAsync_Works_Async()
        {
            var handler = new MockHttpMessageHandler();

            handler
            .Expect(HttpMethod.Get, "http://localhost:5000/v2/registry/manifests/my-tag")
            .With((request) => request.Headers.Accept.Any(h => h.MediaType == "application/vnd.oci.image.manifest.v1+json"))
            .Respond(HttpStatusCode.OK, new StringContent("{\"schemaVersion\":2,\"config\":{\"mediaType\":\"\",\"digest\":\"sha256:a\",\"size\":1},\"layers\":[{\"mediaType\":\"\",\"digest\":\"sha256:b\",\"size\":2}]}", Encoding.UTF8, "application/json"));

            var httpClient = handler.ToHttpClient();

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

            var client = new ImageRegistryClient(httpClient);

            var manifest = await client.GetManifestAsync("registry", "my-tag", default).ConfigureAwait(false);

            Assert.Equal(2, manifest.SchemaVersion);
            Assert.Equal(1, manifest.Config.Size);
            var layer = Assert.Single(manifest.Layers);

            Assert.Equal(2, layer.Size);

            handler.VerifyNoOutstandingExpectation();
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public async Task GetManifestAsync_RetursNullWhenNotFound_Async()
        {
            var handler = new MockHttpMessageHandler();

            handler
            .Expect(HttpMethod.Get, "http://localhost:5000/v2/registry/manifests/my-tag")
            .With((request) => request.Headers.Accept.Any(h => h.MediaType == "application/vnd.oci.image.manifest.v1+json"))
            .Respond(HttpStatusCode.NotFound);

            var httpClient = handler.ToHttpClient();

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

            var client = new ImageRegistryClient(httpClient);

            Assert.Null(await client.GetManifestAsync("registry", "my-tag", default).ConfigureAwait(false));

            handler.VerifyNoOutstandingExpectation();
        }