-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathplugin.go
More file actions
83 lines (64 loc) · 1.54 KB
/
Copy pathplugin.go
File metadata and controls
83 lines (64 loc) · 1.54 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
//go:build example
package main
import (
"cmp"
"slices"
"github.com/ozontech/testo"
"github.com/ozontech/testo/testoplugin"
"github.com/ozontech/testo/testoreflect"
)
type Order int
const (
First Order = iota - 1
None
Last
)
type utilCfg struct {
priority Order
runs int
}
func newUtilCfg(options ...testoplugin.Option) utilCfg {
cfg := utilCfg{
priority: None,
runs: 1,
}
for _, opt := range options {
if o, ok := opt.Value.(utilOption); ok {
o(&cfg)
}
}
return cfg
}
type utilOption func(*utilCfg)
func WithOrder(priority Order) testoplugin.Option {
return testoplugin.Option{
Value: utilOption(func(cfg *utilCfg) { cfg.priority = priority }),
}
}
func WithRuns(runs int) testoplugin.Option {
return testoplugin.Option{
Value: utilOption(func(cfg *utilCfg) { cfg.runs = runs }),
}
}
type PluginUtils struct{ *testo.T }
func (*PluginUtils) Plugin(testoplugin.Plugin, ...testoplugin.Option) testoplugin.Spec {
return testoplugin.Spec{
Plan: testoplugin.Plan{
Prepare: func(_ testoreflect.SuiteInfo, tests *[]testoplugin.PlannedTest) {
prepared := make([]testoplugin.PlannedTest, 0, len(*tests))
for _, t := range *tests {
cfg := newUtilCfg(t.Annotations()...)
for range cfg.runs {
prepared = append(prepared, t)
}
}
slices.SortStableFunc(prepared, func(a, b testoplugin.PlannedTest) int {
aCfg := newUtilCfg(a.Annotations()...)
bCfg := newUtilCfg(b.Annotations()...)
return cmp.Compare(aCfg.priority, bCfg.priority)
})
*tests = prepared
},
},
}
}