Skip to content

Commit

Permalink
Added version regex to parse the logs to see if matches vsemvar format (
Browse files Browse the repository at this point in the history
#747)

* check version in integration tests

---------

Co-authored-by: Donal Hurley <[email protected]>
  • Loading branch information
oliveromahony and dhurley authored Jul 15, 2024
1 parent f7c10e4 commit a6db6db
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion test/integration/utils/test_container_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"os"
"regexp"
"testing"
"time"

Expand All @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit a6db6db

Please sign in to comment.