-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
119 lines (102 loc) · 3.4 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
package main
import (
"context"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/rs/zerolog"
"github.com/rs/zerolog/pkgerrors"
"github.com/equinor/radix-cicd-canary/scenarios/deployonly"
"github.com/equinor/radix-cicd-canary/scenarios/happypath"
"github.com/equinor/radix-cicd-canary/scenarios/nsp"
nsplong "github.com/equinor/radix-cicd-canary/scenarios/nsp-long"
"github.com/equinor/radix-cicd-canary/scenarios/test"
"github.com/equinor/radix-cicd-canary/scenarios/utils/config"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/rs/zerolog/log"
)
func init() {
// If you get GOAWAY calling API with token using:
// az account get-access-token
// ...enable this line
// os.Setenv("GODEBUG", "http2server=0,http2client=0")
}
func main() {
cfg := config.NewConfig()
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGTERM)
defer cancel()
logLevel := cfg.GetLogLevel()
pretty := cfg.GetPrettyPrint()
zerolog.SetGlobalLevel(logLevel)
zerolog.DurationFieldInteger = true
zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack
if pretty {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.TimeOnly})
}
ctx = log.Logger.WithContext(ctx)
log.Info().Msg("Starting...")
log.Info().Msgf("Log level: %s", logLevel.String())
sleepInterval := cfg.GetSleepIntervalBetweenTestRuns()
happyPathSuite := happypath.TestSuite()
deployOnlySuite := deployonly.TestSuite()
nspSleepInterval := cfg.GetNSPSleepInterval()
nspLongSleepInterval := cfg.GetNSPLongSleepInterval()
nspSuite := nsp.TestSuite()
nspLongSuite := nsplong.TestSuite()
go runSuites(ctx, cfg, sleepInterval, happyPathSuite)
go runSuites(ctx, cfg, sleepInterval, deployOnlySuite)
go runSuites(ctx, cfg, nspSleepInterval, nspSuite)
go runSuites(ctx, cfg, nspLongSleepInterval, nspLongSuite)
log.Info().Msg("Started suites. Start metrics service.")
http.Handle("/metrics", promhttp.Handler())
err := http.ListenAndServe(":5000", nil)
if err != nil {
log.Fatal().Stack().Err(err).Msg("Failed to listen")
return
}
log.Info().Msg("Complete.")
<-ctx.Done()
}
func runSuites(ctx context.Context, environmentVariables config.Config, sleepInterval time.Duration, suites ...test.Suite) {
log.Debug().Int("suites", len(suites)).Msg("Prepare to run suite(s)")
suites = filterSuites(suites, environmentVariables)
if len(suites) == 0 {
log.Debug().Msg("No suites to run")
return
}
log.Debug().Int("suites", len(suites)).Msg("Run suite(s)")
runner := test.NewRunner(environmentVariables)
for {
runner.Run(ctx, suites...)
time.Sleep(sleepInterval)
}
}
func filterSuites(suites []test.Suite, environmentVariables config.Config) []test.Suite {
filter := environmentVariables.GetSuiteList()
if len(filter) == 0 {
return suites
}
log.Debug().Msg("Filtering suites...")
suitesToRun := make([]test.Suite, 0)
isBlacklist := environmentVariables.GetSuiteListIsBlacklist()
for _, suite := range suites {
// pass the filter if mentioned and !isBlacklist OR if !mentioned and isBlacklist
if contains(filter, suite.Name) != isBlacklist {
log.Debug().Str("name", suite.Name).Msg("run suite")
suitesToRun = append(suitesToRun, suite)
} else {
log.Debug().Str("name", suite.Name).Msg("skip suite")
}
}
return suitesToRun
}
func contains(list []string, target string) bool {
for _, item := range list {
if target == item {
return true
}
}
return false
}