forked from ooni/probe-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasksession_test.go
128 lines (116 loc) · 3.02 KB
/
tasksession_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
127
128
package oonimkall
import (
"context"
"testing"
"github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/engine"
"github.com/ooni/probe-cli/v3/internal/version"
)
func TestTaskKVSToreFSBuilderEngine(t *testing.T) {
b := &taskKVStoreFSBuilderEngine{}
store, err := b.NewFS("testdata/state")
if err != nil {
t.Fatal(err)
}
if store == nil {
t.Fatal("expected non-nil store here")
}
}
func TestTaskSessionBuilderEngine(t *testing.T) {
t.Run("NewSession", func(t *testing.T) {
t.Run("on success", func(t *testing.T) {
builder := &taskSessionBuilderEngine{}
ctx := context.Background()
config := engine.SessionConfig{
Logger: log.Log,
SoftwareName: "ooniprobe-cli",
SoftwareVersion: version.Version,
}
sess, err := builder.NewSession(ctx, config)
if err != nil {
t.Fatal(err)
}
sess.Close()
})
t.Run("on failure", func(t *testing.T) {
builder := &taskSessionBuilderEngine{}
ctx := context.Background()
config := engine.SessionConfig{}
sess, err := builder.NewSession(ctx, config)
if err == nil {
t.Fatal("expected an error here")
}
if sess != nil {
t.Fatal("expected nil session here")
}
})
})
}
func TestTaskSessionEngine(t *testing.T) {
// newSession is a helper function for creating a new session.
newSession := func(t *testing.T) taskSession {
builder := &taskSessionBuilderEngine{}
ctx := context.Background()
config := engine.SessionConfig{
Logger: log.Log,
SoftwareName: "ooniprobe-cli",
SoftwareVersion: version.Version,
}
sess, err := builder.NewSession(ctx, config)
if err != nil {
t.Fatal(err)
}
return sess
}
t.Run("NewExperimentBuilderByName", func(t *testing.T) {
t.Run("on success", func(t *testing.T) {
sess := newSession(t)
builder, err := sess.NewExperimentBuilderByName("ndt")
if err != nil {
t.Fatal(err)
}
if builder == nil {
t.Fatal("expected non-nil builder")
}
})
t.Run("on failure", func(t *testing.T) {
sess := newSession(t)
builder, err := sess.NewExperimentBuilderByName("antani")
if err == nil {
t.Fatal("expected an error here")
}
if builder != nil {
t.Fatal("expected nil builder")
}
})
})
}
func TestTaskExperimentBuilderEngine(t *testing.T) {
// newBuilder is a helper function for creating a new session
// as well as a new experiment builder
newBuilder := func(t *testing.T) (taskSession, taskExperimentBuilder) {
builder := &taskSessionBuilderEngine{}
ctx := context.Background()
config := engine.SessionConfig{
Logger: log.Log,
SoftwareName: "ooniprobe-cli",
SoftwareVersion: version.Version,
}
sess, err := builder.NewSession(ctx, config)
if err != nil {
t.Fatal(err)
}
expBuilder, err := sess.NewExperimentBuilderByName("ndt")
if err != nil {
t.Fatal(err)
}
return sess, expBuilder
}
t.Run("NewExperiment", func(t *testing.T) {
_, builder := newBuilder(t)
exp := builder.NewExperimentInstance()
if exp == nil {
t.Fatal("expected non-nil experiment here")
}
})
}