mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(batch): tag actions and one-lock teardown, wired into the CloudFormation provisioner (#4268)
Batch gains ListTagsForResource, TagResource and UntagResource (rest-json on
/v1/tags/{arn}, served by a BatchTagHandler under the shared V1Tags controller,
200 on success as the model declares no responseCode), and the compute
environment, job queue and job definition each get a teardown that deletes
under one lock and reports false when the resource is already gone (an
INACTIVE job definition revision counts as gone).
BatchCfnProvisioner deletes through those teardowns so DeleteStack and rollback
remove the backing resources instead of only forgetting them, and a JobQueue
update reconciles its tags in place. ProvisionContext.resolveTags now reads the
object form of Tags as well as the list form: Batch templates declare tags as a
map, which was silently dropped at create time.
Refs #2861
This commit is contained in:
1 parent
375d83c0f4
commit
bfedf6c679
10 files changed
+518
-120
No files matched your search
@@ -755,6 +755,58 @@ class BatchIntegrationTest {
|
||||
.body("jobs", hasSize(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagRoutesTagListAndUntagAResource() {
|
||||
String suffix = uniqueSuffix();
|
||||
String computeArn = createComputeEnvironment("batch-tags-ce-" + suffix);
|
||||
|
||||
givenJson("{\"tags\":{\"team\":\"a\",\"tier\":\"gold\"}}")
|
||||
.when()
|
||||
.post("/v1/tags/" + computeArn)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
givenJson("{\"tags\":{\"env\":\"blue\"}}")
|
||||
.when()
|
||||
.post("/v1/tags/" + computeArn)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.get("/v1/tags/" + computeArn)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("tags.team", equalTo("a"))
|
||||
.body("tags.tier", equalTo("gold"))
|
||||
.body("tags.env", equalTo("blue"));
|
||||
|
||||
given()
|
||||
.header("Authorization", AUTH)
|
||||
.queryParam("tagKeys", "tier", "env")
|
||||
.when()
|
||||
.delete("/v1/tags/" + computeArn)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.get("/v1/tags/" + computeArn)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("tags.team", equalTo("a"))
|
||||
.body("tags.size()", equalTo(1));
|
||||
|
||||
given()
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.get("/v1/tags/arn:aws:batch:us-east-1:000000000000:job-queue/never-" + suffix)
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.header("X-Amzn-Errortype", "ClientException");
|
||||
}
|
||||
|
||||
private static io.restassured.specification.RequestSpecification givenJson(String body) {
|
||||
return given()
|
||||
.header("Authorization", AUTH)
|
||||
|
||||
@@ -21,14 +21,17 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -1058,6 +1061,145 @@ class BatchServiceTest {
|
||||
""".formatted(suffix, computeArn)), REGION).path("jobQueueArn").asText();
|
||||
}
|
||||
|
||||
// ── teardown (one hold of the lock: look-up, disable, delete) ────────────
|
||||
|
||||
@Test
|
||||
void teardownDisablesAndDeletesAnEnabledComputeEnvironmentAndIsIdempotent() throws Exception {
|
||||
BatchService service = immediateService(new InMemoryStorage<String, BatchJob>());
|
||||
String arn = service.createComputeEnvironment(json("""
|
||||
{"computeEnvironmentName":"td-ce","type":"MANAGED"}
|
||||
"""), REGION).path("computeEnvironmentArn").asText();
|
||||
assertEquals("ENABLED", service.describeComputeEnvironments(json(
|
||||
"{\"computeEnvironments\":[\"td-ce\"]}")).path("computeEnvironments").get(0).path("state").asText());
|
||||
|
||||
assertTrue(service.teardownComputeEnvironment(arn), "an ENABLED environment is disabled then deleted");
|
||||
assertTrue(service.describeComputeEnvironments(json("{\"computeEnvironments\":[\"td-ce\"]}"))
|
||||
.path("computeEnvironments").isEmpty());
|
||||
assertFalse(service.teardownComputeEnvironment(arn), "a repeat counts the environment as gone");
|
||||
}
|
||||
|
||||
@Test
|
||||
void teardownRefusesAComputeEnvironmentStillAttachedToAQueueUntilTheQueueIsGone() throws Exception {
|
||||
BatchService service = immediateService(new InMemoryStorage<String, BatchJob>());
|
||||
String computeArn = service.createComputeEnvironment(json("""
|
||||
{"computeEnvironmentName":"td-attached-ce","type":"MANAGED"}
|
||||
"""), REGION).path("computeEnvironmentArn").asText();
|
||||
String queueArn = service.createJobQueue(json("""
|
||||
{"jobQueueName":"td-queue","priority":1,
|
||||
"computeEnvironmentOrder":[{"order":1,"computeEnvironment":"%s"}]}
|
||||
""".formatted(computeArn)), REGION).path("jobQueueArn").asText();
|
||||
|
||||
AwsException refused = assertThrows(AwsException.class,
|
||||
() -> service.teardownComputeEnvironment(computeArn));
|
||||
assertTrue(refused.getMessage().contains("still associated with a job queue"), refused.getMessage());
|
||||
// The refused teardown left the environment behind, disabled, exactly as AWS would.
|
||||
assertEquals("DISABLED", service.describeComputeEnvironments(json(
|
||||
"{\"computeEnvironments\":[\"td-attached-ce\"]}")).path("computeEnvironments").get(0).path("state").asText());
|
||||
|
||||
assertTrue(service.teardownJobQueue(queueArn), "an ENABLED queue is disabled then deleted");
|
||||
assertFalse(service.teardownJobQueue(queueArn));
|
||||
assertTrue(service.teardownComputeEnvironment(computeArn));
|
||||
}
|
||||
|
||||
@Test
|
||||
void teardownDeregistersAnActiveJobDefinitionOnce() throws Exception {
|
||||
BatchService service = immediateService(new InMemoryStorage<String, BatchJob>());
|
||||
String arn = service.registerJobDefinition(json("""
|
||||
{"jobDefinitionName":"td-def","type":"container",
|
||||
"containerProperties":{"image":"public.ecr.aws/example/job:latest"}}
|
||||
"""), REGION).path("jobDefinitionArn").asText();
|
||||
|
||||
assertTrue(service.teardownJobDefinition(arn));
|
||||
assertEquals("INACTIVE", service.describeJobDefinitions(json("{\"jobDefinitions\":[\"" + arn + "\"]}"))
|
||||
.path("jobDefinitions").get(0).path("status").asText());
|
||||
assertFalse(service.teardownJobDefinition(arn), "an INACTIVE revision counts as gone");
|
||||
assertFalse(service.teardownJobDefinition("arn:aws:batch:us-east-1:000000000000:job-definition/never:1"));
|
||||
}
|
||||
|
||||
// ── tags ─────────────────────────────────────────────────────────────────
|
||||
|
||||
/** TagResource obeys the create-time tag rules, on the request and on the merged result. */
|
||||
@Test
|
||||
void tagResourceEnforcesTheCreateTimeTagRulesOnTheRequestAndTheMergedResult() throws Exception {
|
||||
BatchService service = immediateService(new InMemoryStorage<String, BatchJob>());
|
||||
String queueArn = createTaggedQueue(service, "rules-queue", Map.of("team", "a"));
|
||||
|
||||
assertEquals("ClientException", assertThrows(AwsException.class,
|
||||
() -> service.tagResource(queueArn, Map.of("aws:cloudformation:stack-name", "x"))).getErrorCode());
|
||||
assertThrows(AwsException.class, () -> service.tagResource(queueArn, Map.of("k".repeat(129), "v")));
|
||||
assertThrows(AwsException.class, () -> service.tagResource(queueArn, Map.of("k", "v".repeat(257))));
|
||||
assertThrows(AwsException.class, () -> service.tagResource(queueArn, tagsNumbered(0, 51)));
|
||||
|
||||
service.tagResource(queueArn, tagsNumbered(0, 39));
|
||||
assertEquals(40, service.listTagsForResource(queueArn).size());
|
||||
assertThrows(AwsException.class, () -> service.tagResource(queueArn, tagsNumbered(39, 59)),
|
||||
"a request that fits on its own must not push the resource past 50 tags");
|
||||
assertEquals(40, service.listTagsForResource(queueArn).size(), "a rejected request stores nothing");
|
||||
service.tagResource(queueArn, tagsNumbered(39, 49));
|
||||
assertEquals(50, service.listTagsForResource(queueArn).size());
|
||||
|
||||
assertThrows(AwsException.class, () -> service.untagResource(queueArn,
|
||||
tagsNumbered(0, 51).keySet().stream().toList()));
|
||||
service.untagResource(queueArn, tagsNumbered(0, 49).keySet().stream().toList());
|
||||
assertEquals(Map.of("team", "a"), service.listTagsForResource(queueArn));
|
||||
}
|
||||
|
||||
private static Map<String, String> tagsNumbered(int from, int toExclusive) {
|
||||
Map<String, String> tags = new LinkedHashMap<>();
|
||||
for (int i = from; i < toExclusive; i++) {
|
||||
tags.put("k" + i, "v");
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
private String createTaggedQueue(BatchService service, String name, Map<String, String> tags) throws Exception {
|
||||
String computeArn = service.createComputeEnvironment(json("""
|
||||
{"computeEnvironmentName":"%s-ce","type":"MANAGED"}
|
||||
""".formatted(name)), REGION).path("computeEnvironmentArn").asText();
|
||||
return service.createJobQueue(json("""
|
||||
{"jobQueueName":"%s","priority":1,"tags":%s,
|
||||
"computeEnvironmentOrder":[{"order":1,"computeEnvironment":"%s"}]}
|
||||
""".formatted(name, new ObjectMapper().writeValueAsString(tags), computeArn)), REGION)
|
||||
.path("jobQueueArn").asText();
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagResourceMergesAndUntagResourceRemovesOnEveryTaggableType() throws Exception {
|
||||
BatchService service = immediateService(new InMemoryStorage<String, BatchJob>());
|
||||
String computeArn = service.createComputeEnvironment(json("""
|
||||
{"computeEnvironmentName":"tag-ce","type":"MANAGED","tags":{"team":"a"}}
|
||||
"""), REGION).path("computeEnvironmentArn").asText();
|
||||
String queueArn = service.createJobQueue(json("""
|
||||
{"jobQueueName":"tag-queue","priority":1,
|
||||
"computeEnvironmentOrder":[{"order":1,"computeEnvironment":"%s"}]}
|
||||
""".formatted(computeArn)), REGION).path("jobQueueArn").asText();
|
||||
String definitionArn = service.registerJobDefinition(json("""
|
||||
{"jobDefinitionName":"tag-def","type":"container",
|
||||
"containerProperties":{"image":"public.ecr.aws/example/job:latest"}}
|
||||
"""), REGION).path("jobDefinitionArn").asText();
|
||||
|
||||
for (String arn : List.of(computeArn, queueArn, definitionArn)) {
|
||||
service.tagResource(arn, Map.of("tier", "gold"));
|
||||
service.tagResource(arn, Map.of("env", "blue"));
|
||||
Map<String, String> tags = service.listTagsForResource(arn);
|
||||
assertEquals("gold", tags.get("tier"), arn);
|
||||
assertEquals("blue", tags.get("env"), "an earlier tag survives a later TagResource: " + arn);
|
||||
service.untagResource(arn, List.of("tier", "never-set"));
|
||||
assertEquals(Map.of("env", "blue", "team", "a").entrySet().stream()
|
||||
.filter(e -> arn.equals(computeArn) || !"team".equals(e.getKey()))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)),
|
||||
service.listTagsForResource(arn), arn);
|
||||
}
|
||||
// The create-time tags of the compute environment were kept through the merges.
|
||||
assertEquals("a", service.listTagsForResource(computeArn).get("team"));
|
||||
|
||||
AwsException unknown = assertThrows(AwsException.class, () -> service.listTagsForResource(
|
||||
"arn:aws:batch:us-east-1:000000000000:job-queue/never"));
|
||||
assertEquals("ClientException", unknown.getErrorCode());
|
||||
assertThrows(AwsException.class, () -> service.tagResource(queueArn, Map.of()));
|
||||
assertThrows(AwsException.class, () -> service.untagResource(queueArn, List.of()));
|
||||
}
|
||||
|
||||
private BatchService dockerService(BatchDockerRunner runner) {
|
||||
return service("docker", new InMemoryStorage<String, BatchJob>(), runner);
|
||||
}
|
||||
|
||||
+9
-3
@@ -218,6 +218,7 @@ class CloudFormationBatchIntegrationTest {
|
||||
"Properties": {
|
||||
"JobQueueName": "%s",
|
||||
"Priority": %d,
|
||||
"Tags": {"env": "%s"},
|
||||
"ComputeEnvironmentOrder": [{
|
||||
"Order": 1,
|
||||
"ComputeEnvironment": {"Ref": "Compute"}
|
||||
@@ -236,7 +237,7 @@ class CloudFormationBatchIntegrationTest {
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateStack")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("TemplateBody", template.formatted(computeName, 4, queueName, 1))
|
||||
.formParam("TemplateBody", template.formatted(computeName, 4, queueName, 1, "green"))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
@@ -248,7 +249,7 @@ class CloudFormationBatchIntegrationTest {
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "UpdateStack")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("TemplateBody", template.formatted(computeName, 8, queueName, 5))
|
||||
.formParam("TemplateBody", template.formatted(computeName, 8, queueName, 5, "blue"))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
@@ -272,7 +273,12 @@ class CloudFormationBatchIntegrationTest {
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("jobQueues", hasSize(1))
|
||||
.body("jobQueues[0].priority", equalTo(5));
|
||||
.body("jobQueues[0].priority", equalTo(5))
|
||||
// Tags are tag-updatable on a queue: the kept queue carries the template's new value.
|
||||
.body("jobQueues[0].tags.env", equalTo("blue"))
|
||||
// Both entities are still ENABLED (AWS's default), which is what the delete below
|
||||
// has to disable first: a delete that only works on DISABLED ones proves nothing.
|
||||
.body("jobQueues[0].state", equalTo("ENABLED"));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
|
||||
+48
-60
@@ -12,6 +12,8 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
@@ -168,6 +170,39 @@ class BatchCfnProvisionerTest {
|
||||
assertEquals(CE_ARN, r.getPhysicalId(), "an in-place update keeps the physical id");
|
||||
}
|
||||
|
||||
@Test
|
||||
void updatingAJobQueueReconcilesItsDeclaredTags() {
|
||||
// JobQueue tags are tag-updatable, so a kept queue is driven to the template's set: the
|
||||
// dropped key is untagged, the rest tagged, through the same tag actions the API serves.
|
||||
when(batch.listTagsForResource(JQ_ARN)).thenReturn(Map.of("team", "a", "stale", "x"));
|
||||
StackResource r = resource("AWS::Batch::JobQueue", "Queue");
|
||||
r.getAttributes().put("JobQueueName", "queue");
|
||||
ObjectNode props = mapper.createObjectNode();
|
||||
props.put("JobQueueName", "queue");
|
||||
props.put("Priority", "9");
|
||||
props.putObject("Tags").put("team", "a").put("tier", "gold");
|
||||
|
||||
provisioner.provision(r, props, updateCtx(JQ_ARN));
|
||||
|
||||
verify(batch).untagResource(JQ_ARN, List.of("stale"));
|
||||
verify(batch).tagResource(JQ_ARN, Map.of("team", "a", "tier", "gold"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updatingAJobQueueWithoutDeclaredTagsLeavesItsTagsAlone() {
|
||||
StackResource r = resource("AWS::Batch::JobQueue", "Queue");
|
||||
r.getAttributes().put("JobQueueName", "queue");
|
||||
ObjectNode props = mapper.createObjectNode();
|
||||
props.put("JobQueueName", "queue");
|
||||
props.put("Priority", "9");
|
||||
|
||||
provisioner.provision(r, props, updateCtx(JQ_ARN));
|
||||
|
||||
verify(batch, never()).listTagsForResource(anyString());
|
||||
verify(batch, never()).untagResource(anyString(), any());
|
||||
verify(batch, never()).tagResource(anyString(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updatingAJobQueueUpdatesInPlace() {
|
||||
StackResource r = resource("AWS::Batch::JobQueue", "Queue");
|
||||
@@ -308,58 +343,18 @@ class BatchCfnProvisionerTest {
|
||||
// ── delete ───────────────────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
void deletingAJobQueueDisablesItFirst() {
|
||||
// DeleteJobQueue refuses an ENABLED queue, as on AWS, so the disable has to come first
|
||||
// and in this order.
|
||||
when(batch.describeJobQueues(any())).thenReturn(describeWith("jobQueues", JQ_ARN));
|
||||
|
||||
provisioner.delete("AWS::Batch::JobQueue", JQ_ARN, "us-east-1");
|
||||
|
||||
InOrder order = inOrder(batch);
|
||||
ArgumentCaptor<JsonNode> disable = ArgumentCaptor.forClass(JsonNode.class);
|
||||
order.verify(batch).updateJobQueue(disable.capture());
|
||||
order.verify(batch).deleteJobQueue(any());
|
||||
assertEquals("DISABLED", disable.getValue().path("state").asText());
|
||||
assertEquals(JQ_ARN, disable.getValue().path("jobQueue").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletingAComputeEnvironmentDisablesItFirst() {
|
||||
when(batch.describeComputeEnvironments(any()))
|
||||
.thenReturn(describeWith("computeEnvironments", CE_ARN));
|
||||
|
||||
provisioner.delete("AWS::Batch::ComputeEnvironment", CE_ARN, "us-east-1");
|
||||
|
||||
InOrder order = inOrder(batch);
|
||||
ArgumentCaptor<JsonNode> disable = ArgumentCaptor.forClass(JsonNode.class);
|
||||
order.verify(batch).updateComputeEnvironment(disable.capture());
|
||||
order.verify(batch).deleteComputeEnvironment(any());
|
||||
assertEquals("DISABLED", disable.getValue().path("state").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletingAJobDefinitionDeregistersIt() {
|
||||
when(batch.describeJobDefinitions(any())).thenReturn(describeWith("jobDefinitions", JD_ARN));
|
||||
|
||||
provisioner.delete("AWS::Batch::JobDefinition", JD_ARN, "us-east-1");
|
||||
|
||||
ArgumentCaptor<JsonNode> req = ArgumentCaptor.forClass(JsonNode.class);
|
||||
verify(batch).deregisterJobDefinition(req.capture());
|
||||
assertEquals(JD_ARN, req.getValue().path("jobDefinition").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletingAnEntityThatIsAlreadyGoneDoesNothing() {
|
||||
// A repeated stack delete must be idempotent. It matters most for the job definition:
|
||||
// deregister throws when the definition is missing, so the existence check is the guard.
|
||||
when(batch.describeComputeEnvironments(any())).thenReturn(describeEmpty("computeEnvironments"));
|
||||
when(batch.describeJobQueues(any())).thenReturn(describeEmpty("jobQueues"));
|
||||
when(batch.describeJobDefinitions(any())).thenReturn(describeEmpty("jobDefinitions"));
|
||||
|
||||
void deletingTearsEachTypeDownThroughTheServiceInOneStep() {
|
||||
// The disable-before-delete order and the already-gone guard live in BatchService's
|
||||
// teardown methods, under one hold of its lock (BatchServiceTest pins them); the
|
||||
// provisioner must not re-implement them as separately locked calls.
|
||||
provisioner.delete("AWS::Batch::ComputeEnvironment", CE_ARN, "us-east-1");
|
||||
provisioner.delete("AWS::Batch::JobQueue", JQ_ARN, "us-east-1");
|
||||
provisioner.delete("AWS::Batch::JobDefinition", JD_ARN, "us-east-1");
|
||||
|
||||
verify(batch).teardownComputeEnvironment(CE_ARN);
|
||||
verify(batch).teardownJobQueue(JQ_ARN);
|
||||
verify(batch).teardownJobDefinition(JD_ARN);
|
||||
verify(batch, never()).describeComputeEnvironments(any());
|
||||
verify(batch, never()).updateComputeEnvironment(any());
|
||||
verify(batch, never()).deleteComputeEnvironment(any());
|
||||
verify(batch, never()).updateJobQueue(any());
|
||||
@@ -371,9 +366,7 @@ class BatchCfnProvisionerTest {
|
||||
void aRefusedDeletePropagatesInsteadOfBeingSwallowed() {
|
||||
// The failure that must not be tolerated: a compute environment still attached to a queue.
|
||||
// Swallowing it would report a green stack delete over a resource that is still there.
|
||||
when(batch.describeComputeEnvironments(any()))
|
||||
.thenReturn(describeWith("computeEnvironments", CE_ARN));
|
||||
when(batch.deleteComputeEnvironment(any())).thenThrow(new AwsException("ClientException",
|
||||
when(batch.teardownComputeEnvironment(CE_ARN)).thenThrow(new AwsException("ClientException",
|
||||
"Cannot delete compute environment still associated with a job queue: envy", 400));
|
||||
|
||||
AwsException thrown = assertThrows(AwsException.class,
|
||||
@@ -386,8 +379,7 @@ class BatchCfnProvisionerTest {
|
||||
provisioner.delete("AWS::Batch::JobQueue", null, "us-east-1");
|
||||
provisioner.delete("AWS::Batch::JobQueue", "", "us-east-1");
|
||||
|
||||
verify(batch, never()).describeJobQueues(any());
|
||||
verify(batch, never()).deleteJobQueue(any());
|
||||
verify(batch, never()).teardownJobQueue(any());
|
||||
}
|
||||
|
||||
// ── replacement cleanup ──────────────────────────────────────────────────
|
||||
@@ -441,9 +433,7 @@ class BatchCfnProvisionerTest {
|
||||
|
||||
assertTrue(result.applicable());
|
||||
assertTrue(result.complete(), "the displaced environment was deleted");
|
||||
ArgumentCaptor<JsonNode> deleted = ArgumentCaptor.forClass(JsonNode.class);
|
||||
verify(batch).deleteComputeEnvironment(deleted.capture());
|
||||
assertEquals(CE_ARN, deleted.getValue().path("computeEnvironment").asText());
|
||||
verify(batch).teardownComputeEnvironment(CE_ARN);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -599,10 +589,8 @@ class BatchCfnProvisionerTest {
|
||||
|
||||
assertTrue(provisioner.rollbackUpdate(r));
|
||||
|
||||
ArgumentCaptor<JsonNode> deregistered = ArgumentCaptor.forClass(JsonNode.class);
|
||||
verify(batch).deregisterJobDefinition(deregistered.capture());
|
||||
assertEquals(JD_ARN + "-r2", deregistered.getValue().path("jobDefinition").asText(),
|
||||
"the revision the failed update registered, not the one it started from");
|
||||
verify(batch).teardownJobDefinition(JD_ARN + "-r2");
|
||||
verify(batch, never()).teardownJobDefinition(JD_ARN);
|
||||
assertEquals(JD_ARN, r.getPhysicalId(), "the resource names the prior revision again");
|
||||
}
|
||||
|
||||
|
||||
+15
@@ -128,6 +128,21 @@ class ProvisionContextTest {
|
||||
assertEquals("", tags.get("novalue"), "a missing Value becomes empty, not null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveTagsReadsTheMapShapeSomeTypesDeclare() {
|
||||
// AWS::Batch::* declare Tags as {key: value} rather than [{Key, Value}]; the map form
|
||||
// resolves each value and keeps template order too.
|
||||
Map<String, String> tags = context(null).resolveTags(
|
||||
props("""
|
||||
{"Tags": {"zeta": "z", "alpha": "a", "empty": ""}}
|
||||
"""),
|
||||
"Tags");
|
||||
|
||||
assertEquals(List.of("zeta", "alpha", "empty"), List.copyOf(tags.keySet()));
|
||||
assertEquals("z", tags.get("zeta"));
|
||||
assertEquals("", tags.get("empty"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveTagsSkipsBlankKeysAndNeverReturnsNull() {
|
||||
Map<String, String> blankKeys = context(null).resolveTags(
|
||||
|
||||
Reference in new issue
Block a user