Search in sources :

Example 1 with TerraformStatus

use of org.ligoj.app.plugin.prov.model.TerraformStatus in project plugin-prov by ligoj.

the class TerraformResourceTest method applyTerraformIOE.

private void applyTerraformIOE(final TerraformResource resource) {
    Assertions.assertThrows(IOException.class, () -> {
        applyTerraform(resource);
    });
    // Nice, as expected, but more check to do
    final TerraformStatus task = resource.runner.getTask("service:prov:test:account");
    Assertions.assertNotNull(task);
    Assertions.assertTrue(task.isFinished());
    Assertions.assertTrue(resource.runner.getTask("service:prov:test:account").isFailed());
}
Also used : TerraformStatus(org.ligoj.app.plugin.prov.model.TerraformStatus)

Example 2 with TerraformStatus

use of org.ligoj.app.plugin.prov.model.TerraformStatus in project plugin-prov by ligoj.

the class TerraformResourceTest method applyTerraformInternal.

@Test
public void applyTerraformInternal() throws IOException, InterruptedException {
    final File log = new File(MOCK_PATH, "main.log");
    final File tf = new File(MOCK_PATH, "main.tf");
    final TerraformResource resource = newResource(Mockito.mock(Terraforming.class), false);
    applyTerraform(resource);
    // Synchronization of sub processes
    Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> tf.exists() && log.exists() && IOUtils.toString(log.toURI(), "UTF-8").contains("show"));
    Thread.yield();
    Assertions.assertTrue(tf.exists());
    Assertions.assertTrue(log.exists());
    final String logString = IOUtils.toString(log.toURI(), "UTF-8");
    Assertions.assertTrue(logString.contains("plan"));
    Assertions.assertTrue(logString.contains("apply"));
    Assertions.assertTrue(logString.contains("show"));
    // Check the log file is well handled
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ((StreamingOutput) resource.getTerraformLog(subscription).getEntity()).write(bos);
    Assertions.assertEquals(logString, bos.toString(StandardCharsets.UTF_8));
    // Check the task status
    final TerraformStatus task = resource.runner.getTask("service:prov:test:account");
    Assertions.assertTrue(task.isFinished());
    Assertions.assertFalse(task.isFailed());
    Assertions.assertNotNull(task.getStart());
    Assertions.assertNotNull(task.getAuthor());
    Assertions.assertEquals(DEFAULT_USER, task.getAuthor());
    Assertions.assertEquals("service:prov:test:account", task.getLocked().getId());
    Assertions.assertNotNull(task.getEnd());
    Assertions.assertEquals(TerraformStep.SHOW, task.getStep());
}
Also used : StreamingOutput(javax.ws.rs.core.StreamingOutput) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) TerraformStatus(org.ligoj.app.plugin.prov.model.TerraformStatus) File(java.io.File) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Aggregations

TerraformStatus (org.ligoj.app.plugin.prov.model.TerraformStatus)2 File (java.io.File)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 Test (org.junit.jupiter.api.Test)1 AbstractAppTest (org.ligoj.app.AbstractAppTest)1