mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(servicecatalog): use injected clock for plan execution record (#7122)
This commit is contained in:
1 parent
d173d65eb4
commit
87a733edea
2 files changed
+20
-4
No files matched your search
+1
-1
@@ -1152,7 +1152,7 @@ public class ServiceCatalogService implements PassedRoleLookup {
|
||||
ObjectNode record = objectMapper.createObjectNode();
|
||||
record.put("RecordId", "rec-" + UUID.randomUUID().toString().replace("-", "").substring(0, 16));
|
||||
record.put("Status", "SUCCEEDED");
|
||||
record.put("CreatedTime", System.currentTimeMillis() / 1000.0);
|
||||
record.put("CreatedTime", Instant.now(clock).toEpochMilli() / 1000.0);
|
||||
return record;
|
||||
}
|
||||
|
||||
|
||||
+19
-3
@@ -1,8 +1,11 @@
|
||||
package io.github.hectorvent.floci.services.servicecatalog;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.testing.MutableClock;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import jakarta.inject.Inject;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -10,6 +13,7 @@ import org.junit.jupiter.api.Test;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Wire-level tests for {@code CreateProvisionedProductPlan},
|
||||
@@ -39,6 +43,12 @@ class ServiceCatalogProvisionedProductPlanConsumerTest {
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
|
||||
|
||||
@Inject
|
||||
ObjectMapper objectMapper;
|
||||
|
||||
@Inject
|
||||
MutableClock clock;
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
@@ -146,16 +156,22 @@ class ServiceCatalogProvisionedProductPlanConsumerTest {
|
||||
// ---------- ExecuteProvisionedProductPlan ----------
|
||||
|
||||
@Test
|
||||
void executeProvisionedProductPlan_returnsRecordDetail() {
|
||||
void executeProvisionedProductPlan_returnsRecordDetail() throws Exception {
|
||||
String productId = createProduct("ab-plan-execute-product");
|
||||
String artifactId = firstArtifactId(productId);
|
||||
String planId = createPlan(productId, artifactId, "ab-execute-plan");
|
||||
|
||||
call("ExecuteProvisionedProductPlan", "{\"PlanId\":\"" + planId
|
||||
double beforeExecution = clock.instant().toEpochMilli() / 1000.0;
|
||||
Response executed = call("ExecuteProvisionedProductPlan", "{\"PlanId\":\"" + planId
|
||||
+ "\",\"IdempotencyToken\":\"tok-execute-plan\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RecordDetail.Status", equalTo("SUCCEEDED"));
|
||||
.body("RecordDetail.Status", equalTo("SUCCEEDED"))
|
||||
.extract().response();
|
||||
double afterExecution = clock.instant().toEpochMilli() / 1000.0;
|
||||
double createdTime = objectMapper.readTree(executed.asString())
|
||||
.path("RecordDetail").path("CreatedTime").asDouble();
|
||||
assertTrue(createdTime >= beforeExecution && createdTime <= afterExecution);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user