-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
118 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
language: go | ||
go: | ||
- "1.13.5" | ||
|
||
install: | ||
- go get ./... | ||
|
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 bolthold_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/timshannon/bolthold" | ||
) | ||
|
||
func TestForEach(t *testing.T) { | ||
testWrap(t, func(store *bolthold.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