mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
feat(ecr): manage pull through cache rules (#4304)
Signed-off-by: XuJian <265865031+xujiantop-crypto@users.noreply.github.com>
This commit is contained in:
1 parent
34be03b334
commit
1952ba4052
7 files changed
+695
-2
No files matched your search
@@ -151,4 +151,54 @@ class EcrTest {
|
||||
b -> b.repositoryNames("does-not-exist-" + System.nanoTime())))
|
||||
.isInstanceOf(RepositoryNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
@DisplayName("Pull through cache rules round-trip through the AWS SDK")
|
||||
void pullThroughCacheRuleLifecycle() {
|
||||
String firstPrefix = "sdk-docker-hub";
|
||||
String secondPrefix = "sdk-kubernetes";
|
||||
try {
|
||||
CreatePullThroughCacheRuleResponse created = ecr.createPullThroughCacheRule(builder -> builder
|
||||
.ecrRepositoryPrefix(firstPrefix)
|
||||
.upstreamRegistryUrl("registry-1.docker.io"));
|
||||
ecr.createPullThroughCacheRule(builder -> builder
|
||||
.ecrRepositoryPrefix(secondPrefix)
|
||||
.upstreamRegistryUrl("registry.k8s.io"));
|
||||
|
||||
assertThat(created.ecrRepositoryPrefix()).isEqualTo(firstPrefix);
|
||||
assertThat(created.upstreamRegistry()).isEqualTo(UpstreamRegistry.DOCKER_HUB);
|
||||
assertThat(created.upstreamRepositoryPrefix()).isEqualTo("ROOT");
|
||||
assertThat(created.createdAt()).isNotNull();
|
||||
|
||||
DescribePullThroughCacheRulesResponse firstPage = ecr.describePullThroughCacheRules(
|
||||
builder -> builder.maxResults(1));
|
||||
DescribePullThroughCacheRulesResponse secondPage = ecr.describePullThroughCacheRules(
|
||||
builder -> builder.maxResults(1).nextToken(firstPage.nextToken()));
|
||||
DescribePullThroughCacheRulesResponse filtered = ecr.describePullThroughCacheRules(
|
||||
builder -> builder.ecrRepositoryPrefixes(firstPrefix));
|
||||
|
||||
assertThat(firstPage.pullThroughCacheRules()).hasSize(1);
|
||||
assertThat(firstPage.nextToken()).isNotBlank();
|
||||
assertThat(secondPage.pullThroughCacheRules()).hasSize(1);
|
||||
assertThat(filtered.pullThroughCacheRules())
|
||||
.extracting(PullThroughCacheRule::ecrRepositoryPrefix)
|
||||
.containsExactly(firstPrefix);
|
||||
|
||||
DeletePullThroughCacheRuleResponse deleted = ecr.deletePullThroughCacheRule(
|
||||
builder -> builder.ecrRepositoryPrefix(firstPrefix));
|
||||
assertThat(deleted.ecrRepositoryPrefix()).isEqualTo(firstPrefix);
|
||||
assertThatThrownBy(() -> ecr.deletePullThroughCacheRule(
|
||||
builder -> builder.ecrRepositoryPrefix(firstPrefix)))
|
||||
.isInstanceOf(PullThroughCacheRuleNotFoundException.class);
|
||||
} finally {
|
||||
for (String prefix : List.of(firstPrefix, secondPrefix)) {
|
||||
try {
|
||||
ecr.deletePullThroughCacheRule(builder -> builder.ecrRepositoryPrefix(prefix));
|
||||
} catch (PullThroughCacheRuleNotFoundException expected) {
|
||||
// The rule was already deleted by the lifecycle assertion.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user