Skip to content

Commit a6db6db

Browse files
Added version regex to parse the logs to see if matches vsemvar format (#747)
* check version in integration tests --------- Co-authored-by: Donal Hurley <[email protected]>
1 parent f7c10e4 commit a6db6db

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

test/integration/utils/test_container_utils.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io"
88
"os"
9+
"regexp"
910
"testing"
1011
"time"
1112

@@ -17,7 +18,10 @@ import (
1718
wait "github.com/testcontainers/testcontainers-go/wait"
1819
)
1920

20-
const agentServiceTimeout = 20 * time.Second
21+
const (
22+
agentServiceTimeout = 20 * time.Second
23+
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-]+)*))?$`
24+
)
2125

2226
// SetupTestContainerWithAgent sets up a container with nginx and nginx-agent installed
2327
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
119123
require.NoError(t, err, "agent log file could not be read")
120124

121125
assert.NotEmpty(t, agentLogContent, "agent log file empty")
126+
assert.Contains(t, string(agentLogContent), "NGINX Agent v", "agent log file contains invalid agent version")
127+
128+
semverRe := regexp.MustCompile(semverRegex)
129+
130+
if semverRe.MatchString(string(agentLogContent)) {
131+
assert.Fail(t, "failed log content for semver value passed to Agent")
132+
}
133+
122134
assert.NotContains(t, string(agentLogContent), "level=error", "agent log file contains logs at error level")
123135
assert.NotContains(t, string(agentLogContent), "level=panic", "agent log file contains logs at panic level")
124136
assert.NotContains(t, string(agentLogContent), "level=fatal", "agent log file contains logs at fatal level")

0 commit comments

Comments
 (0)