-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
176 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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/v2" | ||
) | ||
|
||
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) | ||
} | ||
}) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters