-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
92 lines (77 loc) · 1.96 KB
/
main_test.go
File metadata and controls
92 lines (77 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//go:build e2escripts
package main
import (
"encoding/json/v2"
"fmt"
"os"
"strings"
"testing"
"github.com/rogpeppe/go-internal/testscript"
"golang.org/x/mod/semver"
)
func TestScripts(t *testing.T) {
srvURL := os.Getenv("WPSECADV_SERVER_URL")
if srvURL == "" {
t.Fatal("WPSECADV_SERVER_URL environment variable is not set")
}
t.Logf("server URL: %q", srvURL)
caFile := os.Getenv("TESTSCRIPT_COMPOSER_CAFILE")
t.Logf("ca file: %q", caFile)
type repo struct {
Type string `json:"type"`
URL string `json:"url"`
Options struct {
SSL struct {
CAFile string `json:"cafile,omitzero"`
} `json:"ssl,omitzero"`
} `json:"options,omitzero"`
}
r := repo{
Type: "composer",
URL: srvURL,
}
if caFile != "" {
r.Options.SSL.CAFile = caFile
}
rb, err := json.Marshal(r)
if err != nil {
t.Fatalf("json.Marshal error: %v", err)
}
t.Logf("repo: %s", rb)
testscript.Run(t, testscript.Params{
Dir: "testdata",
Setup: func(e *testscript.Env) error {
e.Vars = append(e.Vars,
"COMPOSER_NO_INTERACTION=true",
"COMPOSER_NO_AUDIT=true",
"COMPOSER_NO_SECURITY_BLOCKING=true",
"COMPOSER_ROOT_VERSION=0.0.1",
"REPO="+string(rb),
)
dir := os.Getenv("TESTSCRIPT_COMPOSER_CACHE_DIR")
dir = strings.TrimSpace(dir)
if dir != "" {
e.Vars = append(e.Vars, "COMPOSER_CACHE_DIR="+dir)
}
return nil
},
Condition: func(cond string) (bool, error) {
if !strings.HasPrefix(cond, "composer:") {
return false, fmt.Errorf("unknown condition: %s", cond)
}
// This is set by the image.
cur := os.Getenv("COMPOSER_VERSION")
cur = "v" + cur
if cur == "" || !semver.IsValid(cur) {
// Assume latest composer version when running outside containers.
return true, nil
}
targ := strings.TrimPrefix(cond, "composer:")
targ = "v" + targ + ".0"
if !semver.IsValid(targ) {
return false, fmt.Errorf("invalid composer version: %q", targ)
}
return semver.Compare(cur, targ) >= 0, nil
},
})
}