forked from timshannon/badgerhold
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforeach_test.go
More file actions
50 lines (43 loc) · 1.14 KB
/
Copy pathforeach_test.go
File metadata and controls
50 lines (43 loc) · 1.14 KB
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
// Copyright 2019 Tim Shannon. All rights reserved.
// Use of this source code is governed by the MIT license
// that can be found in the LICENSE file.
package badgerhold_test
import (
"fmt"
"testing"
"github.com/timshannon/badgerhold/v3"
)
func TestForEach(t *testing.T) {
testWrap(t, func(store *badgerhold.Store, t *testing.T) {
insertTestData(t, store)
for _, tst := range testResults {
t.Run(tst.name, func(t *testing.T) {
count := 0
err := store.ForEach(tst.query, func(record *ItemTest) error {
count++
found := false
for i := range tst.result {
if record.equal(&testData[tst.result[i]]) {
found = true
break
}
}
if !found {
if testing.Verbose() {
return fmt.Errorf("%v was not found in the result set! Full results: %v",
record, tst.result)
}
return fmt.Errorf("%v was not found in the result set!", record)
}
return nil
})
if count != len(tst.result) {
t.Fatalf("ForEach count is %d wanted %d.", count, len(tst.result))
}
if err != nil {
t.Fatalf("Error during ForEach iteration: %s", err)
}
})
}
})
}