-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
134 lines (115 loc) · 3.15 KB
/
main.go
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package main
import (
"bufio"
_ "embed" // this is required in order for go:embed to work
"fmt"
"log"
"os"
"regexp"
"strings"
"time"
"github.com/launchdarkly/sdk-test-harness/v2/framework"
"github.com/launchdarkly/sdk-test-harness/v2/framework/harness"
"github.com/launchdarkly/sdk-test-harness/v2/framework/helpers"
"github.com/launchdarkly/sdk-test-harness/v2/framework/ldtest"
"github.com/launchdarkly/sdk-test-harness/v2/sdktests"
)
const defaultPort = 8111
const versionString string = "2.25.1" // {{ x-release-please-version }}
func main() {
fmt.Printf("sdk-test-harness v%s\n", strings.TrimSpace(versionString))
var params commandParams
if !params.Read(os.Args) {
os.Exit(1)
}
results, err := run(params)
if err != nil {
helpers.MustFprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
if !results.OK() {
os.Exit(1)
}
}
func run(params commandParams) (*ldtest.Results, error) {
if params.skipFile != "" {
if err := loadSuppressions(¶ms); err != nil {
return nil, err
}
}
mainDebugLogger := framework.NullLogger()
if params.debugAll {
mainDebugLogger = log.New(os.Stdout, "", log.LstdFlags)
}
harness, err := harness.NewTestHarness(
params.serviceURL,
params.host,
params.port,
params.enablePersistenceTests,
time.Duration(params.queryTimeoutSeconds)*time.Second,
mainDebugLogger,
os.Stdout,
)
if err != nil {
return nil, err
}
var testLogger ldtest.TestLogger
consoleLogger := ldtest.ConsoleTestLogger{
DebugOutputOnFailure: params.debug || params.debugAll,
DebugOutputOnSuccess: params.debugAll,
}
if params.jUnitFile == "" {
testLogger = consoleLogger
} else {
testLogger = &ldtest.MultiTestLogger{Loggers: []ldtest.TestLogger{
consoleLogger,
ldtest.NewJUnitTestLogger(params.jUnitFile, harness.TestServiceInfo(), params.filters),
}}
}
results := sdktests.RunSDKTestSuite(harness, params.filters, testLogger)
fmt.Println()
logErr := testLogger.EndLog(results)
if params.stopServiceAtEnd {
fmt.Println("Stopping test service")
if err := harness.StopService(); err != nil {
helpers.MustFprintf(os.Stderr, "Failed to stop test service: %s\n", err)
}
}
if logErr != nil {
return nil, fmt.Errorf("error writing log: %v", logErr)
}
if params.recordFailures != "" {
f, err := os.Create(params.recordFailures)
if err != nil {
return nil, fmt.Errorf("cannot create suppression file: %v", err)
}
for _, test := range results.Failures {
helpers.MustFprintln(f, test.TestID)
}
_ = f.Close()
}
return &results, nil
}
func loadSuppressions(params *commandParams) error {
file, err := os.Open(params.skipFile)
if err != nil {
return fmt.Errorf("cannot open provided suppression file: %v", err)
}
defer func() { _ = file.Close() }()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
// Ignore blank lines
if strings.TrimSpace(line) == "" {
continue
}
escaped := regexp.QuoteMeta(line)
if err := params.filters.MustNotMatch.Set(escaped); err != nil {
return fmt.Errorf("cannot parse suppression: %v", err)
}
}
if err := scanner.Err(); err != nil {
return fmt.Errorf("while processing suppression file: %v", err)
}
return nil
}