Skip to content

Commit 222b2d6

Browse files
committed
Fixed task tests
1 parent 5a19649 commit 222b2d6

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build
22
_old
33
._*
4+
.DS_Store

pkg/handler/nginx/task_test.go

+31-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ package nginx_test
33
import (
44
"context"
55
"os/exec"
6+
"regexp"
67
"sync"
78
"testing"
89
"time"
910

1011
// Packages
11-
"github.com/mutablelogic/go-server/pkg/handler/nginx"
12-
"github.com/stretchr/testify/assert"
12+
nginx "github.com/mutablelogic/go-server/pkg/handler/nginx"
13+
cmd "github.com/mutablelogic/go-server/pkg/handler/nginx/cmd"
14+
assert "github.com/stretchr/testify/assert"
1315
)
1416

1517
func Test_nginx_001(t *testing.T) {
@@ -62,9 +64,35 @@ func Test_nginx_003(t *testing.T) {
6264
}
6365

6466
func BinaryExec(t *testing.T) string {
67+
var version string
68+
6569
bin, err := exec.LookPath("nginx")
6670
if err != nil {
67-
t.Skip("nginx binary not found")
71+
t.Skip("Skipping test, nginx binary not found")
72+
return ""
73+
}
74+
75+
// TODO minimum version is 1.19.15
76+
reVersion := regexp.MustCompile(`nginx/(\d+)\.(\d+)\.(\d+)`)
77+
cmd, err := cmd.New(bin, "-v")
78+
cmd.Err = func(data []byte) {
79+
version += string(data)
80+
}
81+
cmd.Out = func(data []byte) {
82+
version += string(data)
6883
}
84+
if err != nil {
85+
t.Skip(err.Error())
86+
} else if err := cmd.Run(); err != nil {
87+
t.Skip(err.Error())
88+
} else if args := reVersion.FindStringSubmatch(version); args == nil {
89+
t.Skip("Missing version: " + version)
90+
} else if v := args[1] + args[2]; v < "119" {
91+
t.Skip("Invalid version (needs to be at least 1.19.X): " + version)
92+
} else if v == "119" && args[3] < "15" {
93+
t.Skip("Invalid version (needs to be >= 1.19.15): " + version)
94+
}
95+
96+
// Return binary path
6997
return bin
7098
}

0 commit comments

Comments
 (0)