-
Notifications
You must be signed in to change notification settings - Fork 5
/
processor.go
96 lines (81 loc) · 2.09 KB
/
processor.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
package handler
import (
"encoding/json"
"sync"
"time"
"github.com/go-logr/logr"
"github.com/open-cluster-management/applifecycle-backend-e2e/pkg"
gerr "github.com/pkg/errors"
)
const (
defaultPort = ":8765"
Unknown = "unknown"
Succeed = "succeed"
Failed = "failed"
InfoLevel = 0
DebugLevel = 1
pullInterval = time.Second * 10
)
type Processor struct {
mux *sync.Mutex
timeout time.Duration
// the config directory flag
cfgDir string
configs pkg.KubeConfigs
testCases pkg.TestCasesReg
expectations pkg.ExpctationReg
stages pkg.StageReg
getMatcher func(string) pkg.Matcher
logger logr.Logger
set map[string]struct{}
}
type Storage interface {
LoadTestCases() (pkg.TestCasesReg, error)
LoadExpectations() (pkg.ExpctationReg, error)
LoadStages() (pkg.StageReg, error)
}
func NewProcessor(cfgDir string, timeout int, storage Storage, logger logr.Logger) (*Processor, error) {
var err error
cfg, err := pkg.LoadKubeConfigs(cfgDir)
if err != nil {
return nil, gerr.Wrap(err, "failed to load kubeconfig")
}
tCases, err := storage.LoadTestCases()
if err != nil {
return nil, gerr.Wrap(err, "failed to load test case")
}
exps, err := storage.LoadExpectations()
if err != nil {
return nil, gerr.Wrap(err, "failed to load expectations")
}
stages, err := storage.LoadStages()
if err != nil {
return nil, gerr.Wrap(err, "failed to load test case")
}
return &Processor{
mux: &sync.Mutex{},
timeout: time.Duration(timeout) * time.Second,
cfgDir: cfgDir,
configs: cfg,
testCases: tCases,
expectations: exps,
stages: stages,
getMatcher: pkg.MatcherRouter,
logger: logger,
set: map[string]struct{}{},
}, nil
}
type TResponse struct {
TestID string `json:"test_id"`
Name string `json:"name"`
Status string `json:"run_status"`
Error string `json:"error"`
Details interface{} `json:"details"`
}
func (tr *TResponse) String() string {
o, err := json.MarshalIndent(tr, "", "\t")
if err != nil {
return ""
}
return string(o)
}