Add test case for kubevela memory, cpu rewriting

Change-Id: Id40689d56e44737f7513edc4e6af7c33554cdce5
This commit is contained in:
Rudi Schlatte 2024-02-21 17:11:52 +01:00
parent 876de5b542
commit a2d1477ee2
4 changed files with 260 additions and 47 deletions

View File

@ -42,8 +42,11 @@ public class NebulousAppTests {
@Test
void readValidAppCreationMessage() throws URISyntaxException, IOException {
NebulousApp app = appFromTestFile("app-creation-message-mercabana.json");
NebulousApp app2 = appFromTestFile("app-creation-message-complex.json");
assertNotNull(app);
assertNotNull(app2);
assertTrue(app.validatePaths());
assertTrue(app2.validatePaths());
}
@Test
@ -62,11 +65,10 @@ public class NebulousAppTests {
assertTrue(NebulousApps.values().size() == 2);
}
// @Test
@Test
void replaceValueInKubevela() throws IOException, URISyntaxException {
// TODO reinstate with mercabana app messge, new sample-solution file
NebulousApp app = appFromTestFile("vela-deployment-app-message.json");
String solution_string = Files.readString(getResourcePath("vela-deployment-sample-solution.json"),
NebulousApp app = appFromTestFile("app-creation-message-complex.json");
String solution_string = Files.readString(getResourcePath("sample-solution-complex.json"),
StandardCharsets.UTF_8);
JsonNode solutions = mapper.readTree(solution_string);
ObjectNode replacements = solutions.withObject("VariableValues");
@ -74,10 +76,12 @@ public class NebulousAppTests {
// We deserialize and serialize, just for good measure
String kubevela_str = yaml_mapper.writeValueAsString(kubevela1);
JsonNode kubevela = yaml_mapper.readTree(kubevela_str);
JsonNode cpu = kubevela.at("/spec/components/3/properties/edge/cpu");
JsonNode memory = kubevela.at("/spec/components/3/properties/edge/memory");
assertTrue(cpu.asText().equals("2.7"));
assertTrue(memory.asText().equals("1024"));
JsonNode replicas = kubevela.at("/spec/components/0/traits/0/properties/replicas");
assertTrue(replicas.asText().equals("8"));
JsonNode cpu = kubevela.at("/spec/components/0/properties/requests/cpu");
JsonNode memory = kubevela.at("/spec/components/0/properties/requests/memory");
assertTrue(cpu.asText().equals("3.5"));
assertTrue(memory.asText().equals("4096Mi"));
}
@Test

View File

@ -1,39 +0,0 @@
package eu.nebulouscloud.optimiser.controller;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
import org.junit.jupiter.api.Test;
import java.net.URI;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@WireMockTest
public class SALConnectorTests {
// FIXME: test broken when we use reactor.netty.http.client.HttpClient --
// commenting it out for now
// @Test
// void testConnect(WireMockRuntimeInfo wmRuntimeInfo) {
// WireMock wireMock = wmRuntimeInfo.getWireMock();
// //wireMock.register(post("/sal/pagateway/connect").willReturn(ok()));
// URI uri = URI.create(wmRuntimeInfo.getHttpBaseUrl());
// stubFor(post(urlPathEqualTo("/sal/pagateway/connect"))
// .atPriority(1)
// .withFormParam("name", equalTo("test"))
// .withFormParam("password", equalTo("testpasswd"))
// .willReturn(ok("session key")));
// stubFor(post(urlPathEqualTo("/sal/pagateway/connect"))
// .atPriority(5)
// .willReturn(unauthorized()));
// SalConnector connector_success = new SalConnector(uri, "test", "testpasswd");
// assertTrue(connector_success.isConnected());
// SalConnector connector_fail = new SalConnector(uri, "test", "passwd");
// assertFalse(connector_fail.isConnected());
// }
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,9 @@
{
"VariableValues": {
"spec_components_0_traits_0_properties_replicas": 8,
"spec_components_0_properties_requests_cpu": 3.5,
"spec_components_0_properties_requests_memory": 4096
},
"ObjectiveValues": {
}
}