mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat: add ListTagsForResource, TagResource, UntagResource for Step Functions (#767)
* feat: add ListTagsForResource, TagResource, UntagResource for Step Functions Implements the SharedTagsController TagHandler pattern for SFN state machines and activities. Adds tags field to StateMachine and Activity models, tag CRUD methods to StepFunctionsService, and a new StepFunctionsTagHandler that registers the 'states' service key. Closes #766 * feat: cover JSON 1.0 SDK wire path for SFN tag operations Add ListTagsForResource, TagResource, UntagResource cases to StepFunctionsJsonHandler for AWS SDK (awsJson1.0) compatibility. The REST /tags/{arn} path (SharedTagsController) already covers Terraform; this commit covers the SDK path. Expand integration test to verify both wire paths. Add SDK-based compatibility test using SfnClient. * chore: remove invented inline comment from tags integration test * refactor: remove dead REST TagHandler and clean up integration tests StepFunctionsTagHandler registered the 'states' service key with SharedTagsController (REST /tags/{arn}), but SFN uses JSON 1.0 exclusively. No real client calls GET/POST/DELETE /tags/arn:aws:states:... — the handler was unreachable dead code. Remove StepFunctionsTagHandler and strip the eight REST-path tests from StepFunctionsTagsIntegrationTest. The remaining JSON 1.0 tests are now self-contained (no longer depend on state set by the deleted REST tests). * fix: correct SDK API usage in tag tests and persist creation-time tags - Fix StepFunctionsTagsTest: tags() takes Tag... not Map, use tagsAsMap() helper to convert List<Tag> before asserting with MapAssert methods - Fix StepFunctionsService: pass tags through createStateMachine/createActivity so tags set at creation time are persisted immediately - Fix StepFunctionsJsonHandler: extract parseTagsArray() helper, add 400 validation when tags/tagKeys are not arrays, wire tags into create calls - Expand StepFunctionsTagsIntegrationTest: cover creation-time tag persistence for state machines and activities, and 400 on malformed tag input
This commit is contained in:
1 parent
39ef0694a4
commit
4d2a99506a
6 files changed
+614
-4
No files matched your search
+155
@@ -0,0 +1,155 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import software.amazon.awssdk.services.sfn.SfnClient;
|
||||
import software.amazon.awssdk.services.sfn.model.ListTagsForResourceResponse;
|
||||
import software.amazon.awssdk.services.sfn.model.Tag;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Compatibility tests for Step Functions tag operations:
|
||||
* ListTagsForResource, TagResource, UntagResource on state machines and activities.
|
||||
*
|
||||
* Covers issue #766: Terraform AWS provider v5+ calls ListTagsForResource
|
||||
* unconditionally on every read of aws_sfn_state_machine.
|
||||
*/
|
||||
@DisplayName("SFN Tag Operations")
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class StepFunctionsTagsTest {
|
||||
|
||||
private static final String ROLE_ARN = System.getenv("SFN_ROLE_ARN") != null
|
||||
? System.getenv("SFN_ROLE_ARN")
|
||||
: "arn:aws:iam::000000000000:role/service-role/test-role";
|
||||
|
||||
private static final String SIMPLE_DEFINITION = """
|
||||
{"Comment":"tag test","StartAt":"Done","States":{"Done":{"Type":"Pass","End":true}}}
|
||||
""".strip();
|
||||
|
||||
private static SfnClient sfn;
|
||||
private static String stateMachineArn;
|
||||
private static String activityArn;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
sfn = TestFixtures.sfnClient();
|
||||
String smName = TestFixtures.uniqueName("tags-sm");
|
||||
stateMachineArn = sfn.createStateMachine(b -> b
|
||||
.name(smName)
|
||||
.definition(SIMPLE_DEFINITION)
|
||||
.roleArn(ROLE_ARN)).stateMachineArn();
|
||||
|
||||
String actName = TestFixtures.uniqueName("tags-activity");
|
||||
activityArn = sfn.createActivity(b -> b.name(actName)).activityArn();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (sfn != null) {
|
||||
if (stateMachineArn != null) {
|
||||
try { sfn.deleteStateMachine(b -> b.stateMachineArn(stateMachineArn)); } catch (Exception ignored) {}
|
||||
}
|
||||
if (activityArn != null) {
|
||||
try { sfn.deleteActivity(b -> b.activityArn(activityArn)); } catch (Exception ignored) {}
|
||||
}
|
||||
sfn.close();
|
||||
}
|
||||
}
|
||||
|
||||
// ──────────────── State Machine Tags ────────────────
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void listTags_newStateMachine_returnsEmptyList() {
|
||||
ListTagsForResourceResponse resp = sfn.listTagsForResource(b -> b.resourceArn(stateMachineArn));
|
||||
assertThat(resp.tags()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void tagResource_stateMachine_addsTagsAndListReturnsAll() {
|
||||
sfn.tagResource(b -> b
|
||||
.resourceArn(stateMachineArn)
|
||||
.tags(tag("env", "test"), tag("team", "platform")));
|
||||
|
||||
Map<String, String> tags = tagsAsMap(sfn.listTagsForResource(b -> b.resourceArn(stateMachineArn)).tags());
|
||||
assertThat(tags)
|
||||
.containsEntry("env", "test")
|
||||
.containsEntry("team", "platform");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void untagResource_stateMachine_removesOnlySpecifiedKeys() {
|
||||
sfn.untagResource(b -> b
|
||||
.resourceArn(stateMachineArn)
|
||||
.tagKeys("team"));
|
||||
|
||||
Map<String, String> tags = tagsAsMap(sfn.listTagsForResource(b -> b.resourceArn(stateMachineArn)).tags());
|
||||
assertThat(tags)
|
||||
.containsEntry("env", "test")
|
||||
.doesNotContainKey("team");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void tagResource_stateMachine_overwritesExistingKey() {
|
||||
sfn.tagResource(b -> b
|
||||
.resourceArn(stateMachineArn)
|
||||
.tags(tag("env", "prod")));
|
||||
|
||||
Map<String, String> tags = tagsAsMap(sfn.listTagsForResource(b -> b.resourceArn(stateMachineArn)).tags());
|
||||
assertThat(tags).containsEntry("env", "prod");
|
||||
}
|
||||
|
||||
// ──────────────── Activity Tags ────────────────
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void listTags_newActivity_returnsEmptyList() {
|
||||
ListTagsForResourceResponse resp = sfn.listTagsForResource(b -> b.resourceArn(activityArn));
|
||||
assertThat(resp.tags()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void tagResource_activity_addsTagsAndListReturnsAll() {
|
||||
sfn.tagResource(b -> b
|
||||
.resourceArn(activityArn)
|
||||
.tags(tag("owner", "infra")));
|
||||
|
||||
Map<String, String> tags = tagsAsMap(sfn.listTagsForResource(b -> b.resourceArn(activityArn)).tags());
|
||||
assertThat(tags).containsEntry("owner", "infra");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void untagResource_activity_removesSpecifiedKey() {
|
||||
sfn.untagResource(b -> b
|
||||
.resourceArn(activityArn)
|
||||
.tagKeys("owner"));
|
||||
|
||||
Map<String, String> tags = tagsAsMap(sfn.listTagsForResource(b -> b.resourceArn(activityArn)).tags());
|
||||
assertThat(tags).doesNotContainKey("owner");
|
||||
}
|
||||
|
||||
// ──────────────── Helpers ────────────────
|
||||
|
||||
private static Tag tag(String key, String value) {
|
||||
return Tag.builder().key(key).value(value).build();
|
||||
}
|
||||
|
||||
private static Map<String, String> tagsAsMap(List<Tag> tags) {
|
||||
return tags.stream().collect(Collectors.toMap(Tag::key, Tag::value));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user