Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
Signed-off-by: David Kornel <[email protected]>
  • Loading branch information
kornys committed Jul 8, 2024
1 parent 9cad612 commit e2e4da8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.skodjob.testframe.LogCollectorBuilder;
import io.skodjob.testframe.annotations.CollectLogs;
import io.skodjob.testframe.listeners.GlobalLogCollector;
import io.skodjob.testframe.test.integration.helpers.GlobalLogCollectorTestHandler;
import io.skodjob.testframe.utils.LoggerUtils;
import io.skodjob.testframe.annotations.ResourceManager;
import io.skodjob.testframe.annotations.TestVisualSeparator;
Expand All @@ -15,13 +16,15 @@
import io.skodjob.testframe.resources.NamespaceType;
import io.skodjob.testframe.resources.ServiceAccountType;
import io.skodjob.testframe.utils.KubeUtils;
import org.junit.jupiter.api.extension.ExtendWith;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.atomic.AtomicBoolean;

@ExtendWith(GlobalLogCollectorTestHandler.class) // For testing purpose
@ResourceManager
@CollectLogs
@TestVisualSeparator
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Skodjob authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.skodjob.testframe.test.integration;

import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.fail;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class GlobalLogCollectorIT extends AbstractIT {
@Test
void testGlobalLogCollector() {
fail("Expected issue");
}

@AfterEach
void clean() throws IOException {
FileUtils.deleteDirectory(LOG_DIR.toFile());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright Skodjob authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.skodjob.testframe.test.integration.helpers;

import io.skodjob.testframe.test.integration.AbstractIT;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler;

import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Override test failure for expected test issue in GlobalLogCollectorIT test
*/
public class GlobalLogCollectorTestHandler implements TestExecutionExceptionHandler {

/**
* Check cause message and if it is from GlobalLogCollectorIT check if logs
* are collected and do not mark test as failure
*
* @param context extension context
* @param cause throwable object
* @throws Throwable throwable object
*/
@Override
public void handleTestExecutionException(ExtensionContext context, Throwable cause) throws Throwable {
if (cause.getMessage().contains("Expected issue")) {
assertTrue(AbstractIT.LOG_DIR.toFile().exists());
assertTrue(AbstractIT.LOG_DIR.resolve("default").toFile().exists());
assertTrue(AbstractIT.LOG_DIR.resolve("cluster-wide-resources").toFile().exists());
} else {
throw cause;
}
}
}

0 comments on commit e2e4da8

Please sign in to comment.