From 3c47f6835fb5eb1030077c5894ae9ce71798c3fe Mon Sep 17 00:00:00 2001 From: Stephan Schnabel Date: Tue, 16 May 2023 14:25:56 +0200 Subject: [PATCH] Add it for gcp with service context --- .../log-gcp-with-service/invoker.properties | 3 +++ src/it/log-gcp-with-service/pom.xml | 12 +++++++++++ src/it/log-gcp-with-service/postbuild.bsh | 21 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 src/it/log-gcp-with-service/invoker.properties create mode 100644 src/it/log-gcp-with-service/pom.xml create mode 100644 src/it/log-gcp-with-service/postbuild.bsh diff --git a/src/it/log-gcp-with-service/invoker.properties b/src/it/log-gcp-with-service/invoker.properties new file mode 100644 index 0000000..887fd80 --- /dev/null +++ b/src/it/log-gcp-with-service/invoker.properties @@ -0,0 +1,3 @@ +invoker.environmentVariables.LOGBACK_APPENDER=GCP +invoker.environmentVariables.SERVICE_NAME=test-service +invoker.environmentVariables.SERVICE_VERSION=0.1.2 diff --git a/src/it/log-gcp-with-service/pom.xml b/src/it/log-gcp-with-service/pom.xml new file mode 100644 index 0000000..f13550f --- /dev/null +++ b/src/it/log-gcp-with-service/pom.xml @@ -0,0 +1,12 @@ + + + 4.0.0 + + + @project.groupId@ + @project.artifactId@-it + LOCAL-SNAPSHOT + + + @project.artifactId@-it-log-gcp-with-service + diff --git a/src/it/log-gcp-with-service/postbuild.bsh b/src/it/log-gcp-with-service/postbuild.bsh new file mode 100644 index 0000000..7ba1cab --- /dev/null +++ b/src/it/log-gcp-with-service/postbuild.bsh @@ -0,0 +1,21 @@ +// verify log + +String expected = "^\\{\"time\":\"202[3-9]-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{0,3}Z\",\"severity\":\"INFO\",\"thread\":\"main\",\"logger\":\"io.kokuwa.micronaut.logging.LoggingTest\",\"message\":\"test-output-marker\",\"raw-message\":\"test-output-marker\",\"serviceContext\":\\{\"version\":\"0.1.2\",\"service\":\"test-service\"}}$"; +String[] logs = org.codehaus.plexus.util.FileUtils.fileRead(basedir + "/build.log").split("\n"); + +for (String log : logs) { + if (!log.contains("test-output-marker")) { + continue; + } + if (java.util.regex.Pattern.matches(expected, log)) { + return true; + } else { + System.out.println("marker found, but formatting invalid:"); + System.out.println("[EXPECTED] " + expected); + System.out.println("[ACTUAL] " + log); + return false; + } +} + +System.out.println("marker not found"); +return false;