-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ACR delete tag methods #19680
Add ACR delete tag methods #19680
Changes from all commits
6493027
b1ea4a7
0674deb
2eacc1e
5848ca7
b777de0
7e8c047
f06b542
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,147 +2,185 @@ | |
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using System.Collections.Generic; | ||
|
||
using Azure.Core.TestFramework; | ||
|
||
using Microsoft.Azure.Management.ContainerRegistry; | ||
using Microsoft.Azure.Management.ContainerRegistry.Models; | ||
using Microsoft.Azure.Management.ResourceManager.Fluent; | ||
using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication; | ||
using NUnit.Framework; | ||
using Task = System.Threading.Tasks.Task; | ||
annelo-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
namespace Azure.Containers.ContainerRegistry.Tests | ||
{ | ||
public class ContainerRepositoryClientLiveTests : RecordedTestBase<ContainerRegistryTestEnvironment> | ||
{ | ||
private readonly string _repositoryName = "library/hello-world"; | ||
private readonly string _tagName = "latest"; | ||
private ContainerRepositoryClient _client; | ||
|
||
public ContainerRepositoryClientLiveTests(bool isAsync) : base(isAsync) | ||
{ | ||
} | ||
|
||
[SetUp] | ||
protected async Task CreateClient() | ||
protected ContainerRepositoryClient CreateClient() | ||
{ | ||
_client = InstrumentClient(new ContainerRepositoryClient( | ||
return InstrumentClient(new ContainerRepositoryClient( | ||
new Uri(TestEnvironment.Endpoint), | ||
_repositoryName, | ||
TestEnvironment.UserName, | ||
TestEnvironment.Password, | ||
InstrumentClientOptions(new ContainerRegistryClientOptions()) | ||
)); | ||
|
||
await InitializeRepositoryProperties(); | ||
await InitializeTagProperties(); | ||
} | ||
|
||
[OneTimeTearDown] | ||
public async Task TearDown() | ||
{ | ||
await InitializeRepositoryProperties(); | ||
await InitializeTagProperties(); | ||
} | ||
|
||
public async Task InitializeRepositoryProperties() | ||
public async Task ImportImage(string tag) | ||
{ | ||
await _client.SetPropertiesAsync( | ||
new ContentProperties() | ||
if (TestEnvironment.IsTestModeLive) | ||
annelo-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
var credential = new AzureCredentials( | ||
new ServicePrincipalLoginInformation | ||
{ | ||
ClientId = TestEnvironment.ClientId, | ||
ClientSecret = TestEnvironment.ClientSecret, | ||
}, | ||
TestEnvironment.TenantId, | ||
AzureEnvironment.AzureGlobalCloud); | ||
|
||
var _registryClient = new ContainerRegistryManagementClient(credential.WithDefaultSubscription(TestEnvironment.SubscriptionId)); | ||
_registryClient.SubscriptionId = TestEnvironment.SubscriptionId; | ||
|
||
var importSource = new ImportSource | ||
{ | ||
CanList = true, | ||
CanRead = true, | ||
CanWrite = true, | ||
CanDelete = true | ||
}); | ||
|
||
RepositoryProperties properties = await _client.GetPropertiesAsync(); | ||
|
||
Assert.IsTrue(properties.WriteableProperties.CanList); | ||
Assert.IsTrue(properties.WriteableProperties.CanRead); | ||
Assert.IsTrue(properties.WriteableProperties.CanWrite); | ||
Assert.IsTrue(properties.WriteableProperties.CanDelete); | ||
} | ||
|
||
public async Task InitializeTagProperties() | ||
{ | ||
await _client.SetTagPropertiesAsync( | ||
_tagName, | ||
new ContentProperties() | ||
{ | ||
CanList = true, | ||
CanRead = true, | ||
CanWrite = true, | ||
CanDelete = true | ||
}); | ||
|
||
RepositoryProperties properties = await _client.GetPropertiesAsync(); | ||
|
||
Assert.IsTrue(properties.WriteableProperties.CanList); | ||
Assert.IsTrue(properties.WriteableProperties.CanRead); | ||
Assert.IsTrue(properties.WriteableProperties.CanWrite); | ||
Assert.IsTrue(properties.WriteableProperties.CanDelete); | ||
SourceImage = "library/hello-world", | ||
RegistryUri = "registry.hub.docker.com" | ||
}; | ||
|
||
await _registryClient.Registries.ImportImageAsync( | ||
resourceGroupName: TestEnvironment.ResourceGroup, | ||
registryName: TestEnvironment.Registry, | ||
parameters: | ||
new ImportImageParameters | ||
{ | ||
Mode = ImportMode.Force, | ||
Source = importSource, | ||
TargetTags = new List<string>() | ||
{ | ||
$"library/hello-world:{tag}" | ||
} | ||
}); | ||
} | ||
} | ||
|
||
[RecordedTest] | ||
public async Task CanGetRepositoryProperties() | ||
{ | ||
RepositoryProperties properties = await _client.GetPropertiesAsync(); | ||
// Arrange | ||
ContainerRepositoryClient client = CreateClient(); | ||
annelo-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Act | ||
RepositoryProperties properties = await client.GetPropertiesAsync(); | ||
|
||
// Assert | ||
Assert.AreEqual(_repositoryName, properties.Name); | ||
Assert.AreEqual(new Uri(TestEnvironment.Endpoint).Host, properties.Registry); | ||
} | ||
|
||
[RecordedTest, NonParallelizable] | ||
public async Task CanSetRepositoryProperties([Values(true, false)] bool canList, | ||
[Values(true, false)] bool canRead, | ||
[Values(true, false)] bool canWrite, | ||
[Values(true, false)] bool canDelete) | ||
public async Task CanSetRepositoryProperties() | ||
annelo-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
await _client.SetPropertiesAsync( | ||
// Arrange | ||
ContainerRepositoryClient client = CreateClient(); | ||
RepositoryProperties repositoryProperties = await client.GetPropertiesAsync(); | ||
ContentProperties originalContentProperties = repositoryProperties.WriteableProperties; | ||
|
||
// Act | ||
await client.SetPropertiesAsync( | ||
new ContentProperties() | ||
{ | ||
CanList = canList, | ||
CanRead = canRead, | ||
CanWrite = canWrite, | ||
CanDelete = canDelete | ||
CanList = false, | ||
CanRead = false, | ||
CanWrite = false, | ||
CanDelete = false, | ||
}); | ||
|
||
RepositoryProperties properties = await _client.GetPropertiesAsync(); | ||
// Assert | ||
RepositoryProperties properties = await client.GetPropertiesAsync(); | ||
|
||
Assert.AreEqual(canList, properties.WriteableProperties.CanList); | ||
Assert.AreEqual(canRead, properties.WriteableProperties.CanRead); | ||
Assert.AreEqual(canWrite, properties.WriteableProperties.CanWrite); | ||
Assert.AreEqual(canDelete, properties.WriteableProperties.CanDelete); | ||
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); | ||
} | ||
|
||
[RecordedTest] | ||
public async Task CanGetTagProperties() | ||
{ | ||
TagProperties properties = await _client.GetTagPropertiesAsync(_tagName); | ||
// Arrange | ||
ContainerRepositoryClient client = CreateClient(); | ||
string tag = "latest"; | ||
|
||
// Act | ||
TagProperties properties = await client.GetTagPropertiesAsync(tag); | ||
|
||
Assert.AreEqual(_tagName, properties.Name); | ||
// Assert | ||
Assert.AreEqual(tag, properties.Name); | ||
Assert.AreEqual(_repositoryName, properties.Repository); | ||
Assert.AreEqual(new Uri(TestEnvironment.Endpoint).Host, properties.Registry); | ||
} | ||
|
||
[RecordedTest, NonParallelizable] | ||
public async Task CanSetTagProperties([Values(true, false)] bool canList, | ||
[Values(true, false)] bool canRead, | ||
[Values(true, false)] bool canWrite, | ||
[Values(true, false)] bool canDelete) | ||
public async Task CanSetTagProperties() | ||
{ | ||
await _client.SetTagPropertiesAsync( | ||
_tagName, | ||
// Arrange | ||
ContainerRepositoryClient client = CreateClient(); | ||
string tag = "latest"; | ||
TagProperties tagProperties = await client.GetTagPropertiesAsync(tag); | ||
ContentProperties originalContentProperties = tagProperties.ModifiableProperties; | ||
|
||
// Act | ||
await client.SetTagPropertiesAsync( | ||
tag, | ||
new ContentProperties() | ||
{ | ||
CanList = canList, | ||
CanRead = canRead, | ||
CanWrite = canWrite, | ||
CanDelete = canDelete | ||
CanList = false, | ||
CanRead = false, | ||
CanWrite = false, | ||
CanDelete = false | ||
}); | ||
|
||
TagProperties properties = await _client.GetTagPropertiesAsync(_tagName); | ||
// Assert | ||
TagProperties properties = await client.GetTagPropertiesAsync(tag); | ||
|
||
Assert.IsFalse(properties.ModifiableProperties.CanList); | ||
Assert.IsFalse(properties.ModifiableProperties.CanRead); | ||
Assert.IsFalse(properties.ModifiableProperties.CanWrite); | ||
Assert.IsFalse(properties.ModifiableProperties.CanDelete); | ||
|
||
// Cleanup | ||
await client.SetTagPropertiesAsync(tag, originalContentProperties); | ||
} | ||
|
||
[RecordedTest, NonParallelizable] | ||
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. | ||
annelo-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await Task.Delay(5000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Search and Key Vault, we have our own protected async ValueTask DelayAsync(TimeSpan? duration = null)
{
duration ??= TimeSpan.FromSeconds(5);
if (TestMode == RecordingTestMode.Playback)
{
return ValueTask.Completed;
}
else
{
await Task.Delay(duration);
}
} This way, you don't waste time during playback. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very cool, Heath, thanks for the pointer! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably add this to https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core.TestFramework/src/TestRecording.cs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If so, take a look at Search or Key Vault's. It's a bit more robust (involved) than this sample, but this shows the gist of it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...effectively, you can optionally set a delay, or for retries (something else maybe to add, but separate) a polling interval with default. Both should probably take a
annelo-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Assert.AreEqual(canList, properties.ModifiableProperties.CanList); | ||
Assert.AreEqual(canRead, properties.ModifiableProperties.CanRead); | ||
Assert.AreEqual(canWrite, properties.ModifiableProperties.CanWrite); | ||
Assert.AreEqual(canDelete, properties.ModifiableProperties.CanDelete); | ||
Assert.ThrowsAsync<RequestFailedException>(async () => { await client.GetTagPropertiesAsync(tag); }); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm does the "azp" command not work for container registry, "/azp run net - containerregistry - ci"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need a slash '/azp run net - core - ci'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated