Skip to content

Commit 3d4e755

Browse files
committed
Extract context test
1 parent db2d0ab commit 3d4e755

2 files changed

Lines changed: 35 additions & 20 deletions

File tree

tests/context_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package tests
2+
3+
import (
4+
"context"
5+
"errors"
6+
"testing"
7+
8+
asserts "github.com/shamcode/assert"
9+
"github.com/shamcode/simd/executor"
10+
"github.com/shamcode/simd/indexes/hash"
11+
"github.com/shamcode/simd/namespace"
12+
"github.com/shamcode/simd/query"
13+
)
14+
15+
func Test_Context(t *testing.T) {
16+
// Arrange
17+
store := namespace.CreateNamespace[*User]()
18+
store.AddIndex(hash.NewComparableHashIndex(userID, true))
19+
asserts.Success(t, store.Insert(&User{ //nolint:exhaustruct
20+
ID: 1,
21+
Name: "First",
22+
Status: StatusActive,
23+
Score: 10,
24+
}))
25+
26+
ctx, cancel := context.WithCancel(context.Background())
27+
cancel()
28+
29+
// Act
30+
_, err := executor.CreateQueryExecutor[*User](store).FetchTotal(ctx, query.NewBuilder[*User]().Query())
31+
32+
// Assert
33+
asserts.Equals(t, "context canceled", err.Error(), "check error")
34+
asserts.Equals(t, true, errors.Is(err, context.Canceled), "error is context.Canceled")
35+
}

tests/simd_test.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package tests
33

44
import (
55
"context"
6-
"errors"
76
"regexp"
87
"testing"
98

@@ -427,22 +426,3 @@ func Test_FetchAllAndTotal(t *testing.T) { //nolint:maintidx
427426
})
428427
}
429428
}
430-
431-
func Test_Context(t *testing.T) {
432-
store := namespace.CreateNamespace[*User]()
433-
store.AddIndex(hash.NewComparableHashIndex(userID, true))
434-
asserts.Success(t, store.Insert(&User{
435-
ID: 1,
436-
Name: "First",
437-
Status: StatusActive,
438-
Score: 10,
439-
}))
440-
441-
ctx, cancel := context.WithCancel(context.Background())
442-
cancel()
443-
444-
_, err := executor.CreateQueryExecutor[*User](store).FetchTotal(ctx, query.NewBuilder[*User]().Query())
445-
446-
asserts.Equals(t, "context canceled", err.Error(), "check error")
447-
asserts.Equals(t, true, errors.Is(err, context.Canceled), "error is context.Canceled")
448-
}

0 commit comments

Comments
 (0)