From 9cad612839fd7dbb6404631793e6767bc7c58eed Mon Sep 17 00:00:00 2001 From: David Kornel Date: Mon, 8 Jul 2024 09:21:33 +0200 Subject: [PATCH] Add documentation Signed-off-by: David Kornel --- test-frame-log-collector/README.md | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test-frame-log-collector/README.md b/test-frame-log-collector/README.md index da3d56f..159c925 100644 --- a/test-frame-log-collector/README.md +++ b/test-frame-log-collector/README.md @@ -169,6 +169,42 @@ the logs path will then look like this: ``` The tree path will look similarly to above examples, there will be folders for Namespaces matching the specified labels. +### Global log collector +`GlobaLogCollector` is an annotation which can handle collecting logs which user want automatically in case of test failure or before/after failure. + +Register GlobalLogCollector handlers and configure + +```java +import io.skodjob.testframe.LogCollectorBuilder; +import io.skodjob.testframe.annotations.CollectLogs; +import io.skodjob.testframe.listeners.GlobalLogCollector; +import io.skodjob.testframe.resources.KubeResourceManager; +import org.junit.jupiter.api.Test; + +@CollectLogs +class TestClass() { + static { + // Setup global log collector and handlers + GlobalLogCollector.setupGlobalLogCollector(new LogCollectorBuilder() + .withNamespacedResources("sa", "deployment", "configmaps", "secret") + .withClusterWideResources("nodes") + .withKubeClient(KubeResourceManager.getKubeClient()) + .withKubeCmdClient(KubeResourceManager.getKubeCmdClient()) + .withRootFolderPath("/some-path/path/") + .build()); + GlobalLogCollector.addLogCallback(() -> { + GlobalLogCollector.getGlobalLogCollector().collectFromNamespaces("test-namespace", "test-namespace-2"); + GlobalLogCollector.getGlobalLogCollector().collectClusterWideResources(); + }); + } + + @Test + void test() { + ... + } +} +``` + ### Specifying additional folder path In case that you would like to collect the logs to additional sub-directories of your root folder, the `LogCollector` contains