6
6
"fmt"
7
7
"io"
8
8
"os"
9
+ "regexp"
9
10
"testing"
10
11
"time"
11
12
@@ -17,7 +18,10 @@ import (
17
18
wait "github.com/testcontainers/testcontainers-go/wait"
18
19
)
19
20
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
+ )
21
25
22
26
// SetupTestContainerWithAgent sets up a container with nginx and nginx-agent installed
23
27
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
119
123
require .NoError (t , err , "agent log file could not be read" )
120
124
121
125
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
+
122
134
assert .NotContains (t , string (agentLogContent ), "level=error" , "agent log file contains logs at error level" )
123
135
assert .NotContains (t , string (agentLogContent ), "level=panic" , "agent log file contains logs at panic level" )
124
136
assert .NotContains (t , string (agentLogContent ), "level=fatal" , "agent log file contains logs at fatal level" )
0 commit comments