Skip to content

Commit 1e37662

Browse files
author
Jamey Cribbs
committed
refactored tests to work with gocyclo on goreportcard
1 parent b998082 commit 1e37662

File tree

6 files changed

+261
-25
lines changed

6 files changed

+261
-25
lines changed

datastores/disk/disk_test.go

Lines changed: 79 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ import (
55
"os"
66
"reflect"
77
"sort"
8-
"strconv"
98
"testing"
109

1110
"github.com/jameycribbs/hare/dberr"
1211
)
1312

14-
//gocyclo:ignore
15-
func TestAllDiskTests(t *testing.T) {
13+
func TestNewCloseDiskTests(t *testing.T) {
1614
var tests = []func(t *testing.T){
1715
func(t *testing.T) {
1816
//New...
@@ -32,10 +30,6 @@ func TestAllDiskTests(t *testing.T) {
3230
t.Errorf("want %v; got %v", want, got)
3331
}
3432

35-
// DO I STILL NEED THESE?
36-
//tf := newTestTableFile(t)
37-
//defer tf.close()
38-
3933
wantOffsets := make(map[int]int64)
4034
wantOffsets[1] = 0
4135
wantOffsets[2] = 101
@@ -67,6 +61,13 @@ func TestAllDiskTests(t *testing.T) {
6761
t.Errorf("want %v; got %v", nil, got)
6862
}
6963
},
64+
}
65+
66+
runTestFns(t, tests)
67+
}
68+
69+
func TestCreateTableDiskTests(t *testing.T) {
70+
var tests = []func(t *testing.T){
7071
func(t *testing.T) {
7172
//CreateTable...
7273

@@ -107,6 +108,13 @@ func TestAllDiskTests(t *testing.T) {
107108
t.Errorf("want %v; got %v", wantErr, gotErr)
108109
}
109110
},
111+
}
112+
113+
runTestFns(t, tests)
114+
}
115+
116+
func TestDeleteRecDiskTests(t *testing.T) {
117+
var tests = []func(t *testing.T){
110118
func(t *testing.T) {
111119
//DeleteRec...
112120

@@ -138,6 +146,13 @@ func TestAllDiskTests(t *testing.T) {
138146
t.Errorf("want %v; got %v", wantErr, gotErr)
139147
}
140148
},
149+
}
150+
151+
runTestFns(t, tests)
152+
}
153+
154+
func TestGetLastIDDiskTests(t *testing.T) {
155+
var tests = []func(t *testing.T){
141156
func(t *testing.T) {
142157
//GetLastID...
143158

@@ -167,6 +182,13 @@ func TestAllDiskTests(t *testing.T) {
167182
t.Errorf("want %v; got %v", wantErr, gotErr)
168183
}
169184
},
185+
}
186+
187+
runTestFns(t, tests)
188+
}
189+
190+
func TestIDsDiskTests(t *testing.T) {
191+
var tests = []func(t *testing.T){
170192
func(t *testing.T) {
171193
//IDs...
172194

@@ -205,6 +227,13 @@ func TestAllDiskTests(t *testing.T) {
205227
t.Errorf("want %v; got %v", wantErr, gotErr)
206228
}
207229
},
230+
}
231+
232+
runTestFns(t, tests)
233+
}
234+
235+
func TestInsertRecDiskTests(t *testing.T) {
236+
var tests = []func(t *testing.T){
208237
func(t *testing.T) {
209238
//InsertRec...
210239

@@ -265,6 +294,13 @@ func TestAllDiskTests(t *testing.T) {
265294
t.Errorf("want %v; got %v", want, got)
266295
}
267296
},
297+
}
298+
299+
runTestFns(t, tests)
300+
}
301+
302+
func TestReadRecDiskTests(t *testing.T) {
303+
var tests = []func(t *testing.T){
268304
func(t *testing.T) {
269305
//ReadRec...
270306

@@ -296,6 +332,13 @@ func TestAllDiskTests(t *testing.T) {
296332
t.Errorf("want %v; got %v", wantErr, gotErr)
297333
}
298334
},
335+
}
336+
337+
runTestFns(t, tests)
338+
}
339+
340+
func TestRemoveTableDiskTests(t *testing.T) {
341+
var tests = []func(t *testing.T){
299342
func(t *testing.T) {
300343
//RemoveTable...
301344

@@ -336,6 +379,13 @@ func TestAllDiskTests(t *testing.T) {
336379
t.Errorf("want %v; got %v", wantErr, gotErr)
337380
}
338381
},
382+
}
383+
384+
runTestFns(t, tests)
385+
}
386+
387+
func TestTableExistsDiskTests(t *testing.T) {
388+
var tests = []func(t *testing.T){
339389
func(t *testing.T) {
340390
//TableExists...
341391

@@ -356,6 +406,13 @@ func TestAllDiskTests(t *testing.T) {
356406
t.Errorf("want %v; got %v", want, got)
357407
}
358408
},
409+
}
410+
411+
runTestFns(t, tests)
412+
}
413+
414+
func TestTableNamesDiskTests(t *testing.T) {
415+
var tests = []func(t *testing.T){
359416
func(t *testing.T) {
360417
//TableNames...
361418

@@ -378,6 +435,13 @@ func TestAllDiskTests(t *testing.T) {
378435
}
379436
}
380437
},
438+
}
439+
440+
runTestFns(t, tests)
441+
}
442+
443+
func TestUpdateRecDiskTests(t *testing.T) {
444+
var tests = []func(t *testing.T){
381445
func(t *testing.T) {
382446
//UpdateRec...
383447

@@ -414,6 +478,13 @@ func TestAllDiskTests(t *testing.T) {
414478
t.Errorf("want %v; got %v", wantErr, gotErr)
415479
}
416480
},
481+
}
482+
483+
runTestFns(t, tests)
484+
}
485+
486+
func TestCloseTableDiskTests(t *testing.T) {
487+
var tests = []func(t *testing.T){
417488
func(t *testing.T) {
418489
//closeTable...
419490

@@ -440,9 +511,5 @@ func TestAllDiskTests(t *testing.T) {
440511
},
441512
}
442513

443-
for i, fn := range tests {
444-
testSetup(t)
445-
t.Run(strconv.Itoa(i), fn)
446-
testTeardown(t)
447-
}
514+
runTestFns(t, tests)
448515
}

datastores/disk/tablefile_test.go

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/jameycribbs/hare/dberr"
1212
)
1313

14-
func TestAllTableFileTests(t *testing.T) {
14+
func TestNewCloseTableFileTests(t *testing.T) {
1515
var tests = []func(t *testing.T){
1616
func(t *testing.T) {
1717
//New...
@@ -50,6 +50,13 @@ func TestAllTableFileTests(t *testing.T) {
5050
t.Errorf("want %v; got %v", nil, got)
5151
}
5252
},
53+
}
54+
55+
runTestFns(t, tests)
56+
}
57+
58+
func TestDeleteRecTableFileTests(t *testing.T) {
59+
var tests = []func(t *testing.T){
5360
func(t *testing.T) {
5461
//deleteRec...
5562

@@ -81,6 +88,13 @@ func TestAllTableFileTests(t *testing.T) {
8188
t.Errorf("want %v; got %v", want, got)
8289
}
8390
},
91+
}
92+
93+
runTestFns(t, tests)
94+
}
95+
96+
func TestGetLastIDTableFileTests(t *testing.T) {
97+
var tests = []func(t *testing.T){
8498
func(t *testing.T) {
8599
//getLastID...
86100

@@ -94,6 +108,13 @@ func TestAllTableFileTests(t *testing.T) {
94108
t.Errorf("want %v; got %v", want, got)
95109
}
96110
},
111+
}
112+
113+
runTestFns(t, tests)
114+
}
115+
116+
func TestIDsTableFileTests(t *testing.T) {
117+
var tests = []func(t *testing.T){
97118
func(t *testing.T) {
98119
//ids...
99120

@@ -115,6 +136,13 @@ func TestAllTableFileTests(t *testing.T) {
115136
}
116137
}
117138
},
139+
}
140+
141+
runTestFns(t, tests)
142+
}
143+
144+
func TestOffsetsTableFileTests(t *testing.T) {
145+
var tests = []func(t *testing.T){
118146
func(t *testing.T) {
119147
//offsetForWritingRec...
120148

@@ -163,6 +191,13 @@ func TestAllTableFileTests(t *testing.T) {
163191
}
164192
}
165193
},
194+
}
195+
196+
runTestFns(t, tests)
197+
}
198+
199+
func TestOverwriteRecTableFileTests(t *testing.T) {
200+
var tests = []func(t *testing.T){
166201
func(t *testing.T) {
167202
//overwriteRec...
168203

@@ -194,6 +229,13 @@ func TestAllTableFileTests(t *testing.T) {
194229
t.Errorf("want %v; got %v", want, got)
195230
}
196231
},
232+
}
233+
234+
runTestFns(t, tests)
235+
}
236+
237+
func TestReadRecTableFileTests(t *testing.T) {
238+
var tests = []func(t *testing.T){
197239
func(t *testing.T) {
198240
//readRec...
199241

@@ -212,6 +254,13 @@ func TestAllTableFileTests(t *testing.T) {
212254
t.Errorf("want %v; got %v", want, got)
213255
}
214256
},
257+
}
258+
259+
runTestFns(t, tests)
260+
}
261+
262+
func TestUpdateRecTableFileTests(t *testing.T) {
263+
var tests = []func(t *testing.T){
215264
func(t *testing.T) {
216265
//updateRec (fits on same line)...
217266

@@ -272,6 +321,13 @@ func TestAllTableFileTests(t *testing.T) {
272321
t.Errorf("want %v; got %v", want, got)
273322
}
274323
},
324+
}
325+
326+
runTestFns(t, tests)
327+
}
328+
329+
func TestPadRecTableFileTests(t *testing.T) {
330+
var tests = []func(t *testing.T){
275331
func(t *testing.T) {
276332
//padRec...
277333

datastores/disk/testutils_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@ package disk
33
import (
44
"os"
55
"os/exec"
6+
"strconv"
67
"testing"
78
)
89

10+
func runTestFns(t *testing.T, tests []func(t *testing.T)) {
11+
for i, fn := range tests {
12+
testSetup(t)
13+
t.Run(strconv.Itoa(i), fn)
14+
testTeardown(t)
15+
}
16+
}
17+
918
func newTestDisk(t *testing.T) *Disk {
1019
dsk, err := New("./testdata", ".json")
1120
if err != nil {

0 commit comments

Comments
 (0)