From a6db6dbdc5c6fc2a500032491d755ea85de133e7 Mon Sep 17 00:00:00 2001 From: oliveromahony Date: Mon, 15 Jul 2024 14:12:03 +0100 Subject: [PATCH] Added version regex to parse the logs to see if matches vsemvar format (#747) * check version in integration tests --------- Co-authored-by: Donal Hurley --- test/integration/utils/test_container_utils.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/integration/utils/test_container_utils.go b/test/integration/utils/test_container_utils.go index 5563fb07fd..9a2c649d9a 100644 --- a/test/integration/utils/test_container_utils.go +++ b/test/integration/utils/test_container_utils.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "os" + "regexp" "testing" "time" @@ -17,7 +18,10 @@ import ( wait "github.com/testcontainers/testcontainers-go/wait" ) -const agentServiceTimeout = 20 * time.Second +const ( + agentServiceTimeout = 20 * time.Second + semverRegex = `v^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-]\d*(?:\.\d*[a-zA-Z-]\d*)*)?))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$` +) // SetupTestContainerWithAgent sets up a container with nginx and nginx-agent installed func SetupTestContainerWithAgent(t *testing.T, testName string, conf string, waitForLog string) *testcontainers.DockerContainer { @@ -119,6 +123,14 @@ func TestAgentHasNoErrorLogs(t *testing.T, agentContainer *testcontainers.Docker require.NoError(t, err, "agent log file could not be read") assert.NotEmpty(t, agentLogContent, "agent log file empty") + assert.Contains(t, string(agentLogContent), "NGINX Agent v", "agent log file contains invalid agent version") + + semverRe := regexp.MustCompile(semverRegex) + + if semverRe.MatchString(string(agentLogContent)) { + assert.Fail(t, "failed log content for semver value passed to Agent") + } + assert.NotContains(t, string(agentLogContent), "level=error", "agent log file contains logs at error level") assert.NotContains(t, string(agentLogContent), "level=panic", "agent log file contains logs at panic level") assert.NotContains(t, string(agentLogContent), "level=fatal", "agent log file contains logs at fatal level")