Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

test(codeartifact): pin ResourceNotFoundException on DeleteDomain of a missing domain (#4107)

Matheus André2e038b5cfbeb
diff --git a/docs/services/codeartifact.md b/docs/services/codeartifact.md
index b02ad6ee0b..aa44c60f12 100644
--- a/docs/services/codeartifact.md
+++ b/docs/services/codeartifact.md
@@ -16,7 +16,7 @@ proxy behind them yet.
| Action | Description |
| --- | --- |
| `CreateDomain` | Creates a domain (max 10 per account per Region), optionally with a KMS encryption key and initial tags. |
-| `DeleteDomain` | Deletes a domain; fails with `ConflictException` while it still contains repositories. |
+| `DeleteDomain` | Deletes a domain; fails with `ConflictException` while it still contains repositories, and with `ResourceNotFoundException` for a missing domain (as AWS does, although the API reference does not list it). |
| `DescribeDomain` | Returns a domain's full description, including its repository count. |
| `ListDomains` | Lists domain summaries for the account and Region, paginated. |
| `PutDomainPermissionsPolicy` | Attaches or replaces a domain's resource policy, versioned by `policyRevision`. |
diff --git a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactService.java b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactService.java
index 37cfe3b7de..461bfad89f 100644
--- a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactService.java
@@ -162,6 +162,10 @@ public class CodeArtifactService implements Resettable {
return new DomainView(d, 0);
}
+ /**
+ * A missing domain fails with {@code ResourceNotFoundException} (404), which is what AWS
+ * returns even though the API reference leaves it out of DeleteDomain's error list.
+ */
public synchronized DomainView deleteDomain(String region, String domain, String domainOwner) {
String owner = effectiveOwner(domainOwner);
String key = domainKey(region, domain);
@@ -687,6 +691,8 @@ public class CodeArtifactService implements Resettable {
}
}
+ // Used by DeleteDomain too: AWS returns ResourceNotFoundException for a missing domain there,
+ // although the API reference does not declare it on that operation.
private CodeArtifactDomain requireDomain(String owner, String key, String domainName) {
if (domainName == null || domainName.isBlank()) {
throw validation("domain is required.");
diff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactIntegrationTest.java
index 820477d2b6..08aa34be1a 100644
--- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactIntegrationTest.java
@@ -58,7 +58,12 @@ class CodeArtifactIntegrationTest {
given().header("Authorization", AUTH)
.delete("/v1/domain?domain=lifecycle-domain")
- .then().statusCode(200);
+ .then().statusCode(200).body("domain.name", equalTo("lifecycle-domain"));
+
+ // AWS returns ResourceNotFoundException here although the API reference does not list it on DeleteDomain.
+ given().header("Authorization", AUTH)
+ .delete("/v1/domain?domain=lifecycle-domain")
+ .then().statusCode(404).body("__type", equalTo("ResourceNotFoundException"));
}
@Test
diff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactServiceTest.java
index 4e345fdd72..36bf6ecf82 100644
--- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactServiceTest.java
@@ -163,6 +163,19 @@ class CodeArtifactServiceTest {
assertEquals("with-repo", deleted.domain().getName());
}
+ @Test
+ void deleteDomainOfMissingDomainReturnsResourceNotFound() {
+ // AWS returns this even though the API reference does not list it on DeleteDomain.
+ AwsException e = assertThrows(AwsException.class, () -> service.deleteDomain(REGION, "never-created", null));
+ assertEquals("ResourceNotFoundException", e.getErrorCode());
+ assertEquals(404, e.getHttpStatus());
+
+ service.createDomain(REGION, "once", null, Map.of());
+ service.deleteDomain(REGION, "once", null);
+ AwsException again = assertThrows(AwsException.class, () -> service.deleteDomain(REGION, "once", null));
+ assertEquals("ResourceNotFoundException", again.getErrorCode());
+ }
+
@Test
void describeDomainReflectsLiveRepositoryCount() {
service.createDomain(REGION, "counted", null, Map.of());