forked from cloudfoundry-incubator/pat
/
cmdline_test.go
126 lines (105 loc) · 2.89 KB
/
cmdline_test.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
package pat_test
import (
. "github.com/julz/pat"
"github.com/julz/pat/benchmarker"
"github.com/julz/pat/config"
"github.com/julz/pat/experiment"
"github.com/julz/pat/laboratory"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Cmdline", func() {
var (
flags config.Config
args []string
lab *dummyLab
worker benchmarker.Worker
)
JustBeforeEach(func() {
flags = config.NewConfig()
InitCommandLineFlags(flags)
flags.Parse(args)
lab = &dummyLab{}
worker = benchmarker.NewWorker()
RunCommandLineWithLabAndWorker(lab, worker)
})
Describe("When -iterations is supplied", func() {
BeforeEach(func() {
args = []string{"-iterations", "3"}
})
It("configures the experiment with the parameter", func() {
Ω(lab).Should(HaveBeenRunWith("iterations", 3))
})
})
Describe("When -concurrency is supplied", func() {
BeforeEach(func() {
args = []string{"-concurrency", "3"}
})
It("configures the experiment with the parameter", func() {
Ω(lab).Should(HaveBeenRunWith("concurrency", 3))
})
})
Describe("When -workload is supplied", func() {
BeforeEach(func() {
args = []string{"-workload", "login,push"}
})
It("configures the experiment with the parameter", func() {
Ω(lab).Should(HaveBeenRunWith("workload", "login,push"))
})
})
Describe("When -interval is supplied", func() {
BeforeEach(func() {
args = []string{"-interval", "10"}
})
It("configures the experiment with the parameter", func() {
Ω(lab).Should(HaveBeenRunWith("interval", 10))
})
})
Describe("When -stop is supplied", func() {
BeforeEach(func() {
args = []string{"-stop", "11"}
})
It("configures the experiment with the parameter", func() {
Ω(lab).Should(HaveBeenRunWith("stop", 11))
})
})
})
type runWithMatcher struct {
field string
value interface{}
}
func HaveBeenRunWith(field string, value interface{}) OmegaMatcher {
return &runWithMatcher{field, value}
}
func (m *runWithMatcher) Match(actualLab interface{}) (bool, string, error) {
runWith := actualLab.(*dummyLab).lastRunWith
var actual interface{}
switch m.field {
case "iterations":
actual = runWith.Iterations
case "concurrency":
actual = runWith.Concurrency
case "workload":
actual = runWith.Workload
case "interval":
actual = runWith.Interval
case "stop":
actual = runWith.Stop
}
return Equal(actual).Match(m.value)
}
type dummyLab struct {
lastRunWith *experiment.RunnableExperiment
}
func (d *dummyLab) GetData(guid string) ([]*experiment.Sample, error) {
return nil, nil
}
func (d *dummyLab) Run(runnable laboratory.Runnable) (experiment.Experiment, error) {
return nil, nil
}
func (d *dummyLab) RunWithHandlers(runnable laboratory.Runnable, handlers []func(<-chan *experiment.Sample)) (experiment.Experiment, error) {
d.lastRunWith = runnable.(*experiment.RunnableExperiment)
return nil, nil
}
func (d *dummyLab) Visit(func(experiment.Experiment)) {
}