/
tests_runners.go
145 lines (130 loc) · 3.47 KB
/
tests_runners.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package tests
import (
"fmt"
"io/ioutil"
"os"
"path"
"testing"
gofig "github.com/akutz/gofig/types"
"github.com/rexray/rexray/libstorage/api/context"
"github.com/rexray/rexray/libstorage/api/registry"
"github.com/rexray/rexray/libstorage/api/types"
"github.com/rexray/rexray/libstorage/api/utils"
apiconfig "github.com/rexray/rexray/libstorage/api/utils/config"
)
type suiteRunner struct {
t *testing.T
driverName string
proto string
}
func newSuiteRunner(t *testing.T, d, p string) (string, func()) {
sr := &suiteRunner{t: t, driverName: d, proto: p}
return fmt.Sprintf("%s (%s)", d, p), sr.Describe
}
func newTestRunner(driverName string) *testRunner {
return &testRunner{
store: utils.NewStore(),
driverName: driverName,
expectedVolID: v0ID,
expectedVolName: v0Name,
expectedNextDev: v0NextDev,
}
}
type testRunner struct {
err error
ctx types.Context
config gofig.Config
configFileData []byte
pathConfig *types.PathConfig
client types.Client
server types.Server
srvErr <-chan error
store types.Store
vol *types.Volume
driverName string
sysHome string
usrHome string
proto string
laddr string
serverCrt string
serverKey string
clientCrt string
clientKey string
cacerts string
knownHosts string
volID string
volName string
nextDev string
expectedVolID string
expectedVolName string
expectedNextDev string
}
func (t *testRunner) beforeEach() {
t.serverCrt = suiteServerCrt
t.serverKey = suiteServerKey
t.clientCrt = suiteClientCrt
t.clientKey = suiteClientKey
t.cacerts = suiteTrustedCerts
t.knownHosts = suiteKnownHosts
t.volID = v0ID
t.volName = v0Name
t.nextDev = v0NextDev
// get temp dirs for the sys and user home dirs
newTempDir(&t.sysHome)
newTempDir(&t.usrHome)
// create a context and path config then process the
// registered config registrations
t.ctx = context.Background()
Ω(t.ctx).ShouldNot(BeNil())
t.pathConfig = utils.NewPathConfig(t.sysHome, "", t.usrHome)
Ω(t.pathConfig).ShouldNot(BeNil())
t.ctx = context.WithValue(t.ctx, context.PathConfigKey, t.pathConfig)
registry.ProcessRegisteredConfigs(t.ctx)
}
func (t *testRunner) afterEach() {
os.RemoveAll(t.sysHome)
os.RemoveAll(t.usrHome)
t.ctx = nil
t.vol = nil
t.sysHome = ""
t.usrHome = ""
t.proto = ""
t.laddr = ""
t.client = nil
t.pathConfig = nil
t.configFileData = nil
t.err = nil
t.serverCrt = ""
t.serverKey = ""
t.clientCrt = ""
t.clientKey = ""
t.cacerts = ""
t.knownHosts = ""
t.volID = ""
t.volName = ""
t.nextDev = ""
if t.server != nil {
Ω(t.server.Close()).ToNot(HaveOccurred())
t.server = nil
Ω(<-t.srvErr).ToNot(HaveOccurred())
}
os.Setenv("LIBSTORAGE_TLS_SOCKITTOME", "")
os.Setenv("LIBSTORAGE_TLS_SERVERNAME", "")
os.Setenv("LIBSTORAGE_TLS_CERTFILE", "")
os.Setenv("LIBSTORAGE_TLS_KEYFILE", "")
os.Setenv("LIBSTORAGE_TLS_TRUSTEDCERTSFILE", "")
}
func (t *testRunner) justBeforeEach() {
// write the config data to disk
configFilePath := path.Join(t.pathConfig.Etc, "config.yml")
Ω(configFilePath).ShouldNot(BeAnExistingFile())
Ω(ioutil.WriteFile(
configFilePath,
t.configFileData,
0644)).ToNot(HaveOccurred())
Ω(configFilePath).Should(BeARegularFile())
// create a new config object
t.config, t.err = apiconfig.NewConfig(t.ctx)
Ω(t.err).ToNot(HaveOccurred())
Ω(t.config).ShouldNot(BeNil())
}