mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor(cloudcontrol): move library usages to imports (#3902)
* refactor(cloudcontrol): move library usages to imports * refactor(cloudcontrol): eliminate var declarations and add explicit type imports
This commit is contained in:
1 parent
7777a97de9
commit
44fa114483
3 files changed
+46
-31
No files matched your search
+10
-6
@@ -6,6 +6,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.parsing.Parser;
|
||||
import io.restassured.response.ExtractableResponse;
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -15,6 +18,7 @@ import static io.restassured.config.EncoderConfig.encoderConfig;
|
||||
import static io.restassured.config.RestAssuredConfig.config;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -125,7 +129,7 @@ class CloudControlIntegrationTest {
|
||||
// Poll GetResourceRequestStatus until the async provision reaches SUCCESS.
|
||||
String identifier = null;
|
||||
for (int i = 0; i < 20 && identifier == null; i++) {
|
||||
var pe = given()
|
||||
ExtractableResponse<Response> pe = given()
|
||||
.config(config().encoderConfig(encoderConfig().encodeContentTypeAs(ct, TEXT)))
|
||||
.contentType(ct)
|
||||
.header("X-Amz-Target", "CloudApiService.GetResourceRequestStatus")
|
||||
@@ -224,7 +228,7 @@ class CloudControlIntegrationTest {
|
||||
.body("{\"TypeName\":\"AWS::S3::Bucket\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("TypeName", org.hamcrest.Matchers.equalTo("AWS::S3::Bucket"));
|
||||
.body("TypeName", equalTo("AWS::S3::Bucket"));
|
||||
}
|
||||
|
||||
private void assertErrorCode(String contentType, String target, String body) {
|
||||
@@ -284,7 +288,7 @@ class CloudControlIntegrationTest {
|
||||
.body("{\"TypeName\":\"AWS::IAM::Policy\",\"Identifier\":\"never-created\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("ProgressEvent.OperationStatus", org.hamcrest.Matchers.equalTo("FAILED"));
|
||||
.body("ProgressEvent.OperationStatus", equalTo("FAILED"));
|
||||
}
|
||||
|
||||
private String createVpcThroughCloudControl(String ct, String auth, String cidr) {
|
||||
@@ -302,7 +306,7 @@ class CloudControlIntegrationTest {
|
||||
.header("X-Amz-Target", "CloudApiService.DeleteResource")
|
||||
.body("{\"TypeName\":\"AWS::EC2::VPC\",\"Identifier\":\"" + identifier + "\"}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body("ProgressEvent.OperationStatus", org.hamcrest.Matchers.equalTo(status));
|
||||
.body("ProgressEvent.OperationStatus", equalTo(status));
|
||||
}
|
||||
|
||||
private String awaitIdentifier(String token, String ct) throws InterruptedException {
|
||||
@@ -311,10 +315,10 @@ class CloudControlIntegrationTest {
|
||||
|
||||
private String awaitIdentifier(String token, String ct, String auth) throws InterruptedException {
|
||||
for (int i = 0; i < 20; i++) {
|
||||
var request = given().config(config().encoderConfig(encoderConfig().encodeContentTypeAs(ct, TEXT)))
|
||||
RequestSpecification request = given().config(config().encoderConfig(encoderConfig().encodeContentTypeAs(ct, TEXT)))
|
||||
.contentType(ct).header("X-Amz-Target", "CloudApiService.GetResourceRequestStatus");
|
||||
if (auth != null) request.header("Authorization", auth);
|
||||
var pe = request.body("{\"RequestToken\":\"" + token + "\"}")
|
||||
ExtractableResponse<Response> pe = request.body("{\"RequestToken\":\"" + token + "\"}")
|
||||
.when().post("/").then().statusCode(200).extract();
|
||||
if ("SUCCESS".equals(pe.path("ProgressEvent.OperationStatus"))) {
|
||||
return pe.path("ProgressEvent.Identifier");
|
||||
|
||||
+16
-12
@@ -3,8 +3,8 @@ package io.github.hectorvent.floci.services.cloudcontrol;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.cloudformation.CloudFormationResourceProvisioner;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.services.cloudformation.CloudFormationResourceProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Tag;
|
||||
@@ -20,10 +20,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyMap;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class CloudControlServiceTest {
|
||||
|
||||
@@ -33,9 +37,9 @@ class CloudControlServiceTest {
|
||||
StackResource resource = new StackResource();
|
||||
resource.setPhysicalId("vpc-account-a");
|
||||
resource.setAttributes(Map.of("VpcId", "vpc-account-a"));
|
||||
when(provisioner.provisionStandalone(org.mockito.ArgumentMatchers.eq("AWS::EC2::VPC"),
|
||||
org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.eq("us-east-1"),
|
||||
org.mockito.ArgumentMatchers.eq("111111111111"))).thenReturn(resource);
|
||||
when(provisioner.provisionStandalone(eq("AWS::EC2::VPC"),
|
||||
any(), eq("us-east-1"),
|
||||
eq("111111111111"))).thenReturn(resource);
|
||||
CloudControlService service = new CloudControlService(
|
||||
mock(S3Service.class), mock(Ec2Service.class), mock(IamService.class), provisioner,
|
||||
new ObjectMapper());
|
||||
@@ -57,9 +61,9 @@ class CloudControlServiceTest {
|
||||
CloudControlService.ProgressEvent deniedDelete = service.deleteResource(
|
||||
"us-east-1", "222222222222", "AWS::EC2::VPC", "vpc-account-a");
|
||||
assertEquals("FAILED", deniedDelete.operationStatus());
|
||||
verify(provisioner, never()).deleteStandalone(org.mockito.ArgumentMatchers.anyString(),
|
||||
org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyString(),
|
||||
org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyMap());
|
||||
verify(provisioner, never()).deleteStandalone(anyString(),
|
||||
anyString(), anyString(),
|
||||
anyString(), anyMap());
|
||||
|
||||
CloudControlService.ProgressEvent deleted = service.deleteResource(
|
||||
"us-east-1", "111111111111", "AWS::EC2::VPC", "vpc-account-a");
|
||||
@@ -73,9 +77,9 @@ class CloudControlServiceTest {
|
||||
CloudFormationResourceProvisioner provisioner = mock(CloudFormationResourceProvisioner.class);
|
||||
StackResource resource = new StackResource();
|
||||
resource.setPhysicalId("igw-persisted");
|
||||
when(provisioner.provisionStandalone(org.mockito.ArgumentMatchers.eq("AWS::EC2::InternetGateway"),
|
||||
org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.eq("us-east-1"),
|
||||
org.mockito.ArgumentMatchers.eq("111111111111"))).thenReturn(resource);
|
||||
when(provisioner.provisionStandalone(eq("AWS::EC2::InternetGateway"),
|
||||
any(), eq("us-east-1"),
|
||||
eq("111111111111"))).thenReturn(resource);
|
||||
AccountAwareStorageBackend<CloudControlService.PersistedRequest> requests =
|
||||
AccountAwareStorageBackend.inMemory("000000000000");
|
||||
AccountAwareStorageBackend<CloudControlService.PersistedCreatedResource> created =
|
||||
|
||||
Reference in new issue
Block a user