@@ -2,10 +2,10 @@ package main
2
2
3
3
import (
4
4
"fmt"
5
+ assert "github.com/stretchr/testify/require"
5
6
"os"
6
7
"testing"
7
8
8
- . "github.com/aandryashin/matchers"
9
9
. "github.com/aerokube/ggr/config"
10
10
)
11
11
@@ -15,32 +15,32 @@ func init() {
15
15
16
16
func TestEmptyListOfHosts (t * testing.T ) {
17
17
host , index := choose (Hosts {})
18
- AssertThat (t , host , Is {( * Host )( nil )} )
19
- AssertThat (t , index , EqualTo { - 1 } )
18
+ assert . Nil (t , host )
19
+ assert . Equal (t , index , - 1 )
20
20
}
21
21
22
22
func TestNothingToChoose (t * testing.T ) {
23
23
host , index := choose (Hosts {Host {Count : 0 }, Host {Count : 0 }})
24
- AssertThat (t , host , Is {( * Host )( nil )} )
25
- AssertThat (t , index , EqualTo { - 1 } )
24
+ assert . Nil (t , host )
25
+ assert . Equal (t , index , - 1 )
26
26
}
27
27
28
28
func TestChooseFirst (t * testing.T ) {
29
29
host , index := choose (Hosts {Host {Name : "first" , Count : 1 }, Host {Name : "mid" , Count : 0 }, Host {Name : "last" , Count : 0 }})
30
- AssertThat (t , host .Name , EqualTo { "first" } )
31
- AssertThat (t , index , EqualTo { 0 } )
30
+ assert . Equal (t , host .Name , "first" )
31
+ assert . Equal (t , index , 0 )
32
32
}
33
33
34
34
func TestChooseMid (t * testing.T ) {
35
35
host , index := choose (Hosts {Host {Name : "first" , Count : 0 }, Host {Name : "mid" , Count : 1 }, Host {Name : "last" , Count : 0 }})
36
- AssertThat (t , host .Name , EqualTo { "mid" } )
37
- AssertThat (t , index , EqualTo { 1 } )
36
+ assert . Equal (t , host .Name , "mid" )
37
+ assert . Equal (t , index , 1 )
38
38
}
39
39
40
40
func TestChooseLast (t * testing.T ) {
41
41
host , index := choose (Hosts {Host {Name : "first" , Count : 0 }, Host {Name : "mid" , Count : 0 }, Host {Name : "last" , Count : 1 }})
42
- AssertThat (t , host .Name , EqualTo { "last" } )
43
- AssertThat (t , index , EqualTo { 2 } )
42
+ assert . Equal (t , host .Name , "last" )
43
+ assert . Equal (t , index , 2 )
44
44
}
45
45
46
46
var (
@@ -92,84 +92,84 @@ var (
92
92
93
93
func TestFindDefaultVersion (t * testing.T ) {
94
94
hosts , version , _ := browsersWithMultipleVersions .find ("browser" , "" , "" , newSet (), newSet ())
95
- AssertThat (t , version , EqualTo { "2.0" } )
96
- AssertThat (t , len ( hosts ), EqualTo { 1 } )
97
- AssertThat (t , hosts [0 ].Name , EqualTo { "browser-2.0" } )
95
+ assert . Equal (t , version , "2.0" )
96
+ assert . Len (t , hosts , 1 )
97
+ assert . Equal (t , hosts [0 ].Name , "browser-2.0" )
98
98
}
99
99
100
100
func TestFindVersion (t * testing.T ) {
101
101
hosts , version , _ := browsersWithMultipleVersions .find ("browser" , "1.0" , "LINUX" , newSet (), newSet ())
102
- AssertThat (t , version , EqualTo { "1.0" } )
103
- AssertThat (t , len ( hosts ), EqualTo { 1 } )
104
- AssertThat (t , hosts [0 ].Name , EqualTo { "browser-1.0" } )
102
+ assert . Equal (t , version , "1.0" )
103
+ assert . Len (t , hosts , 1 )
104
+ assert . Equal (t , hosts [0 ].Name , "browser-1.0" )
105
105
}
106
106
107
107
func TestFindVersionByPrefix (t * testing.T ) {
108
108
hosts , version , _ := browsersWithMultipleVersions .find ("browser" , "1" , "" , newSet (), newSet ())
109
- AssertThat (t , version , EqualTo { "1.0" } )
110
- AssertThat (t , len ( hosts ), EqualTo { 1 } )
111
- AssertThat (t , hosts [0 ].Name , EqualTo { "browser-1.0" } )
109
+ assert . Equal (t , version , "1.0" )
110
+ assert . Len (t , hosts , 1 )
111
+ assert . Equal (t , hosts [0 ].Name , "browser-1.0" )
112
112
}
113
113
114
114
func TestVersionNotFound (t * testing.T ) {
115
115
hosts , version , _ := browsersWithMultipleVersions .find ("browser" , "missing" , "" , newSet (), newSet ())
116
- AssertThat (t , version , EqualTo { "missing" } )
117
- AssertThat (t , len ( hosts ), EqualTo { 0 } )
116
+ assert . Equal (t , version , "missing" )
117
+ assert . Empty (t , hosts )
118
118
}
119
119
120
120
func TestFindWithExcludedRegions (t * testing.T ) {
121
121
hosts , version , _ := browsersWithMultipleRegions .find ("browser" , "1.0" , "" , newSet (), newSet ("f" ))
122
- AssertThat (t , version , EqualTo { "1.0" } )
123
- AssertThat (t , len ( hosts ), EqualTo { 1 } )
124
- AssertThat (t , hosts [0 ].Name , EqualTo { "browser-e-1.0" } )
122
+ assert . Equal (t , version , "1.0" )
123
+ assert . Len (t , hosts , 1 )
124
+ assert . Equal (t , hosts [0 ].Name , "browser-e-1.0" )
125
125
}
126
126
127
127
func TestFindWithExcludedRegionsExhausted (t * testing.T ) {
128
128
hosts , _ , excludedRegions := browsersWithMultipleRegions .find ("browser" , "1.0" , "" , newSet (), newSet ("e" , "f" ))
129
- AssertThat (t , len ( hosts ), EqualTo { 2 } )
130
- AssertThat (t , excludedRegions .size (), EqualTo { 0 } )
129
+ assert . Len (t , hosts , 2 )
130
+ assert . Equal (t , excludedRegions .size (), 0 )
131
131
}
132
132
133
133
func TestFindWithExcludedHosts (t * testing.T ) {
134
134
hosts , version , _ := browsersWithMultipleRegions .find ("browser" , "1.0" , "" , newSet ("browser-e-1.0:4444" ), newSet ())
135
- AssertThat (t , version , EqualTo { "1.0" } )
136
- AssertThat (t , len ( hosts ), EqualTo { 1 } )
137
- AssertThat (t , hosts [0 ].Name , EqualTo { "browser-f-1.0" } )
135
+ assert . Equal (t , version , "1.0" )
136
+ assert . Len (t , hosts , 1 )
137
+ assert . Equal (t , hosts [0 ].Name , "browser-f-1.0" )
138
138
}
139
139
140
140
func TestFindWithDefaultPlatform (t * testing.T ) {
141
141
hosts , version , _ := browsersWithMultiplePlatforms .find ("browser" , "2.0" , "" , newSet (), newSet ())
142
- AssertThat (t , version , EqualTo { "2.0" } )
143
- AssertThat (t , len ( hosts ), EqualTo { 1 } )
144
- AssertThat (t , hosts [0 ].Name , EqualTo { "browser-2.0-linux" } )
142
+ assert . Equal (t , version , "2.0" )
143
+ assert . Len (t , hosts , 1 )
144
+ assert . Equal (t , hosts [0 ].Name , "browser-2.0-linux" )
145
145
}
146
146
147
147
func TestFindWithAnyPlatform (t * testing.T ) {
148
148
hosts , version , _ := browsersWithMultiplePlatforms .find ("browser" , "2.0" , "ANY" , newSet (), newSet ())
149
- AssertThat (t , version , EqualTo { "2.0" } )
150
- AssertThat (t , len ( hosts ), EqualTo { 1 } )
151
- AssertThat (t , hosts [0 ].Name , EqualTo { "browser-2.0-linux" } )
149
+ assert . Equal (t , version , "2.0" )
150
+ assert . Len (t , hosts , 1 )
151
+ assert . Equal (t , hosts [0 ].Name , "browser-2.0-linux" )
152
152
}
153
153
154
154
func TestFindWithPlatform (t * testing.T ) {
155
155
hosts , version , _ := browsersWithMultiplePlatforms .find ("browser" , "2.0" , "LINUX" , newSet (), newSet ())
156
- AssertThat (t , version , EqualTo { "2.0" } )
157
- AssertThat (t , len ( hosts ), EqualTo { 1 } )
158
- AssertThat (t , hosts [0 ].Name , EqualTo { "browser-2.0-linux" } )
156
+ assert . Equal (t , version , "2.0" )
157
+ assert . Len (t , hosts , 1 )
158
+ assert . Equal (t , hosts [0 ].Name , "browser-2.0-linux" )
159
159
}
160
160
161
161
func TestFindWithPlatformLowercase (t * testing.T ) {
162
162
hosts , version , _ := browsersWithMultiplePlatforms .find ("browser" , "2.0" , "windows" , newSet (), newSet ())
163
- AssertThat (t , version , EqualTo { "2.0" } )
164
- AssertThat (t , len ( hosts ), EqualTo { 1 } )
165
- AssertThat (t , hosts [0 ].Name , EqualTo { "browser-2.0-windows" } )
163
+ assert . Equal (t , version , "2.0" )
164
+ assert . Len (t , hosts , 1 )
165
+ assert . Equal (t , hosts [0 ].Name , "browser-2.0-windows" )
166
166
}
167
167
168
168
func TestFindWithPlatformPrefix (t * testing.T ) {
169
169
hosts , version , _ := browsersWithMultiplePlatforms .find ("browser" , "2.0" , "WIN" , newSet (), newSet ())
170
- AssertThat (t , version , EqualTo { "2.0" } )
171
- AssertThat (t , len ( hosts ), EqualTo { 1 } )
172
- AssertThat (t , hosts [0 ].Name , EqualTo { "browser-2.0-windows" } )
170
+ assert . Equal (t , version , "2.0" )
171
+ assert . Len (t , hosts , 1 )
172
+ assert . Equal (t , hosts [0 ].Name , "browser-2.0-windows" )
173
173
}
174
174
175
175
func TestReadNotExistingConfig (t * testing.T ) {
@@ -184,8 +184,8 @@ func TestReadNotExistingConfig(t *testing.T) {
184
184
var browsers Browsers
185
185
err = readConfig (tmp .Name (), & browsers )
186
186
187
- AssertThat (t , err , Is { Not { nil }} )
188
- AssertThat (t , err .Error (), EqualTo { fmt .Sprintf ("error reading configuration file %s: open %s: no such file or directory" , tmp .Name (), tmp .Name ())} )
187
+ assert . Error (t , err )
188
+ assert . Equal (t , err .Error (), fmt .Sprintf ("error reading configuration file %s: open %s: no such file or directory" , tmp .Name (), tmp .Name ()))
189
189
}
190
190
191
191
func TestParseInvalidConfig (t * testing.T ) {
@@ -205,8 +205,8 @@ func TestParseInvalidConfig(t *testing.T) {
205
205
var browsers Browsers
206
206
err = readConfig (tmp .Name (), & browsers )
207
207
208
- AssertThat (t , err , Is { Not { nil }} )
209
- AssertThat (t , err .Error (), EqualTo { fmt .Sprintf ("error parsing configuration file %s: EOF" , tmp .Name ())} )
208
+ assert . Error (t , err )
209
+ assert . Equal (t , err .Error (), fmt .Sprintf ("error parsing configuration file %s: EOF" , tmp .Name ()))
210
210
}
211
211
212
212
func TestParseConfig (t * testing.T ) {
@@ -234,20 +234,20 @@ func testParseConfig(t *testing.T, config string) {
234
234
var browsers Browsers
235
235
err = readConfig (tmp .Name (), & browsers )
236
236
237
- AssertThat (t , err , Is { nil } )
238
- AssertThat (t , browsers .Browsers [0 ].Name , EqualTo { "browser" } )
237
+ assert . NoError (t , err )
238
+ assert . Equal (t , browsers .Browsers [0 ].Name , "browser" )
239
239
}
240
240
241
241
func TestConfDirDoesNotExist (t * testing.T ) {
242
242
err := loadQuotaFiles ("missing-dir" )
243
- AssertThat (t , err , Is { Not { nil }} )
243
+ assert . Error (t , err )
244
244
}
245
245
246
246
func TestConcurrentReload (t * testing.T ) {
247
247
go func () {
248
- loadQuotaFiles ("quota" )
248
+ _ = loadQuotaFiles ("quota" )
249
249
}()
250
- loadQuotaFiles ("quota" )
250
+ _ = loadQuotaFiles ("quota" )
251
251
}
252
252
253
253
func TestChoosingAllHosts (t * testing.T ) {
@@ -258,7 +258,7 @@ func TestChoosingAllHosts(t *testing.T) {
258
258
host , _ := choose (hosts )
259
259
chosenHosts [host .Name ]++
260
260
}
261
- AssertThat (t , chosenHosts ["first" ] > 0 , Is { true } )
262
- AssertThat (t , chosenHosts ["mid" ] > 0 , Is { true } )
263
- AssertThat (t , chosenHosts ["last" ] > 0 , Is { true } )
261
+ assert . True (t , chosenHosts ["first" ] > 0 )
262
+ assert . True (t , chosenHosts ["mid" ] > 0 )
263
+ assert . True (t , chosenHosts ["last" ] > 0 )
264
264
}
0 commit comments