Пример #1
0
        public async Task CanSetTagProperties()
        {
            // Arrange
            ContainerRepositoryClient client = CreateClient();
            string        tag           = "latest";
            TagProperties tagProperties = await client.GetTagPropertiesAsync(tag);

            ContentProperties originalContentProperties = tagProperties.WriteableProperties;

            // Act
            await client.SetTagPropertiesAsync(
                tag,
                new ContentProperties()
            {
                CanList   = false,
                CanRead   = false,
                CanWrite  = false,
                CanDelete = false
            });

            // Assert
            TagProperties properties = await client.GetTagPropertiesAsync(tag);

            Assert.IsFalse(properties.WriteableProperties.CanList);
            Assert.IsFalse(properties.WriteableProperties.CanRead);
            Assert.IsFalse(properties.WriteableProperties.CanWrite);
            Assert.IsFalse(properties.WriteableProperties.CanDelete);

            // Cleanup
            await client.SetTagPropertiesAsync(tag, originalContentProperties);
        }
Пример #2
0
        public async Task CanDeleteTag()
        {
            // Arrange
            ContainerRepositoryClient client = CreateClient();
            string tag = "test-delete-tag";

            if (Mode != RecordedTestMode.Playback)
            {
                await ImportImage(_repositoryName, tag);
            }

            // Act
            await client.DeleteTagAsync(tag);

            // Assert

            // This will be removed, pending investigation into potential race condition.
            // https://github.com/azure/azure-sdk-for-net/issues/19699
            if (Mode != RecordedTestMode.Playback)
            {
                await Task.Delay(5000);
            }

            Assert.ThrowsAsync <RequestFailedException>(async() => { await client.GetTagPropertiesAsync(tag); });
        }
Пример #3
0
        public async Task CanDeleteRegistryArtifact()
        {
            // Arrange
            string repository = $"library/node";
            string tag        = "test-delete-image";
            ContainerRepositoryClient client = CreateClient(repository);

            if (Mode != RecordedTestMode.Playback)
            {
                await ImportImage(repository, tag);
            }

            TagProperties tagProperties = await client.GetTagPropertiesAsync(tag);

            string digest = tagProperties.Digest;

            // Act
            await client.DeleteRegistryArtifactAsync(digest);

            // Assert

            // This will be removed, pending investigation into potential race condition.
            // https://github.com/azure/azure-sdk-for-net/issues/19699
            if (Mode != RecordedTestMode.Playback)
            {
                await Task.Delay(5000);
            }

            Assert.ThrowsAsync <RequestFailedException>(async() => { await client.GetRegistryArtifactPropertiesAsync(tag); });
        }
Пример #4
0
        public async Task CanSetRepositoryProperties()
        {
            // Arrange
            ContainerRepositoryClient client = CreateClient();
            RepositoryProperties      repositoryProperties = await client.GetPropertiesAsync();

            ContentProperties originalContentProperties = repositoryProperties.WriteableProperties;

            // Act
            await client.SetPropertiesAsync(
                new ContentProperties()
            {
                CanList   = false,
                CanRead   = false,
                CanWrite  = false,
                CanDelete = false,
            });

            // Assert
            RepositoryProperties properties = await client.GetPropertiesAsync();

            Assert.IsFalse(properties.WriteableProperties.CanList);
            Assert.IsFalse(properties.WriteableProperties.CanRead);
            Assert.IsFalse(properties.WriteableProperties.CanWrite);
            Assert.IsFalse(properties.WriteableProperties.CanDelete);

            // Cleanup
            await client.SetPropertiesAsync(originalContentProperties);
        }
Пример #5
0
        public async Task CanGetMultiArchitectureImageProperties()
        {
            // Arrange
            ContainerRepositoryClient client = CreateClient();
            string tag = "v1";
            int    helloWorldManifestReferences = 9;

            // Act
            RegistryArtifactProperties properties = await client.GetRegistryArtifactPropertiesAsync(tag);

            // Assert
            Assert.Contains(tag, properties.Tags.ToList());
            Assert.AreEqual(_repositoryName, properties.Repository);
            Assert.GreaterOrEqual(helloWorldManifestReferences, properties.RegistryArtifacts.Count);

            Assert.IsTrue(properties.RegistryArtifacts.Any(
                              artifact =>
                              artifact.CpuArchitecture == "arm64" &&
                              artifact.OperatingSystem == "linux"));

            Assert.IsTrue(properties.RegistryArtifacts.Any(
                              artifact =>
                              artifact.CpuArchitecture == "amd64" &&
                              artifact.OperatingSystem == "windows"));
        }
Пример #6
0
 protected void CreateClient()
 {
     _client = InstrumentClient(new ContainerRepositoryClient(
                                    new Uri(TestEnvironment.Endpoint),
                                    _repositoryName,
                                    TestEnvironment.UserName,
                                    TestEnvironment.Password,
                                    InstrumentClientOptions(new ContainerRegistryClientOptions())
                                    ));
 }
Пример #7
0
        public async Task CanGetRepositoryProperties()
        {
            // Arrange
            ContainerRepositoryClient client = CreateClient();

            // Act
            RepositoryProperties properties = await client.GetPropertiesAsync();

            // Assert
            Assert.AreEqual(_repositoryName, properties.Name);
        }
        public async Task CanGetRepositoryProperties()
        {
            // Arrange
            ContainerRepositoryClient client = CreateClient();

            // Act
            RepositoryProperties properties = await client.GetPropertiesAsync();

            // Assert
            Assert.AreEqual(_repositoryName, properties.Name);
            Assert.AreEqual(new Uri(TestEnvironment.Endpoint).Host, properties.Registry);
        }
Пример #9
0
        public async Task CanGetTagProperties()
        {
            // Arrange
            ContainerRepositoryClient client = CreateClient();
            string tag = "latest";

            // Act
            TagProperties properties = await client.GetTagPropertiesAsync(tag);

            // Assert
            Assert.AreEqual(tag, properties.Name);
            Assert.AreEqual(_repositoryName, properties.Repository);
        }
        protected async Task CreateClient()
        {
            _client = InstrumentClient(new ContainerRepositoryClient(
                                           new Uri(TestEnvironment.Endpoint),
                                           _repositoryName,
                                           TestEnvironment.UserName,
                                           TestEnvironment.Password,
                                           InstrumentClientOptions(new ContainerRegistryClientOptions())
                                           ));

            await InitializeRepositoryProperties();
            await InitializeTagProperties();
        }
        public async Task CanDeleteTag()
        {
            // Arrange
            ContainerRepositoryClient client = CreateClient();
            string tag = "test-delete";

            await ImportImage(tag);

            // Act
            await client.DeleteTagAsync(tag);

            // Assert

            // The delete takes some time, so if we call GetTagProperties() without a delay, we get a 200 response.
            await Task.Delay(5000);

            Assert.ThrowsAsync <RequestFailedException>(async() => { await client.GetTagPropertiesAsync(tag); });
        }
Пример #12
0
        public async Task CanGetArtifactProperties()
        {
            // Arrange
            ContainerRepositoryClient client = CreateClient();
            string tag = "v1";

            // Act
            RegistryArtifactProperties listProperties = await client.GetRegistryArtifactPropertiesAsync(tag);

            var arm64LinuxImage = listProperties.RegistryArtifacts.First(
                artifact =>
                artifact.CpuArchitecture == "arm64" &&
                artifact.OperatingSystem == "linux");
            RegistryArtifactProperties properties = await client.GetRegistryArtifactPropertiesAsync(arm64LinuxImage.Digest);

            // Assert
            Assert.AreEqual(_repositoryName, properties.Repository);
            Assert.IsNotNull(properties.Digest);
            Assert.AreEqual("arm64", properties.CpuArchitecture);
            Assert.AreEqual("linux", properties.OperatingSystem);
        }
Пример #13
0
        public async Task HandleErrorsAsync()
        {
            Environment.SetEnvironmentVariable("REGISTRY_ENDPOINT", TestEnvironment.Endpoint);

            #region Snippet:ContainerRegistry_Tests_Samples_HandleErrorsAsync
            Uri endpoint = new Uri(Environment.GetEnvironmentVariable("REGISTRY_ENDPOINT"));

            // Create an invalid ContainerRepositoryClient
            string fakeRepositoryName        = "doesnotexist";
            ContainerRepositoryClient client = new ContainerRepositoryClient(endpoint, fakeRepositoryName, new DefaultAzureCredential());

            try
            {
                await client.GetPropertiesAsync();
            }
            catch (RequestFailedException ex) when(ex.Status == 404)
            {
                Console.WriteLine("Repository wasn't found.");
            }
            #endregion Snippet:ContainerRegistry_Tests_Samples_HandleErrorsAsync
        }
Пример #14
0
        public async Task CanSetManifestProperties()
        {
            // Arrange
            ContainerRepositoryClient client = CreateClient();
            string        tag           = "latest";
            TagProperties tagProperties = await client.GetTagPropertiesAsync(tag);

            string digest = tagProperties.Digest;
            RegistryArtifactProperties artifactProperties = await client.GetRegistryArtifactPropertiesAsync(digest);

            ContentProperties originalContentProperties = artifactProperties.WriteableProperties;

            // Act
            RegistryArtifactProperties properties = await client.SetManifestPropertiesAsync(
                digest,
                new ContentProperties()
            {
                CanList   = false,
                CanRead   = false,
                CanWrite  = false,
                CanDelete = false
            });

            // Assert
            Assert.IsFalse(properties.WriteableProperties.CanList);
            Assert.IsFalse(properties.WriteableProperties.CanRead);
            Assert.IsFalse(properties.WriteableProperties.CanWrite);
            Assert.IsFalse(properties.WriteableProperties.CanDelete);

            RegistryArtifactProperties updatedProperties = await client.GetRegistryArtifactPropertiesAsync(digest);

            Assert.IsFalse(updatedProperties.WriteableProperties.CanList);
            Assert.IsFalse(updatedProperties.WriteableProperties.CanRead);
            Assert.IsFalse(updatedProperties.WriteableProperties.CanWrite);
            Assert.IsFalse(updatedProperties.WriteableProperties.CanDelete);

            // Cleanup
            await client.SetManifestPropertiesAsync(digest, originalContentProperties);
        }
 public void TestSetup()
 {
     client = InstrumentClient(new ContainerRepositoryClient(_url, _repository, GetCredential(), new ContainerRegistryClientOptions()));
 }