-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathstream_batch_test.go
More file actions
105 lines (98 loc) · 2.69 KB
/
Copy pathstream_batch_test.go
File metadata and controls
105 lines (98 loc) · 2.69 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package scyllacdc
import (
"errors"
"fmt"
"testing"
"github.com/gocql/gocql"
)
// mockRequestError implements gocql.RequestError for testing.
type mockRequestError struct {
code int
message string
}
func (e *mockRequestError) Error() string { return e.message }
func (e *mockRequestError) Code() int { return e.code }
func (e *mockRequestError) Message() string { return e.message }
// Verify mockRequestError implements gocql.RequestError.
var _ gocql.RequestError = (*mockRequestError)(nil)
func TestIsTableMissingError(t *testing.T) {
tests := []struct {
name string
err error
expected bool
}{
{
name: "ErrNotFound",
err: gocql.ErrNotFound,
expected: true,
},
{
name: "wrapped ErrNotFound",
err: fmt.Errorf("some context: %w", gocql.ErrNotFound),
expected: true,
},
{
name: "ErrKeyspaceDoesNotExist",
err: gocql.ErrKeyspaceDoesNotExist,
expected: true,
},
{
name: "wrapped ErrKeyspaceDoesNotExist",
err: fmt.Errorf("some context: %w", gocql.ErrKeyspaceDoesNotExist),
expected: true,
},
{
name: "RequestError with no such table",
err: &mockRequestError{code: gocql.ErrCodeInvalid, message: "no such table ks.tbl"},
expected: true,
},
{
name: "RequestError with unconfigured table",
err: &mockRequestError{code: gocql.ErrCodeInvalid, message: "unconfigured table tbl"},
expected: true,
},
{
name: "RequestError with does not exist",
err: &mockRequestError{code: gocql.ErrCodeInvalid, message: "table ks.tbl does not exist"},
expected: true,
},
{
name: "RequestError with wrong code but matching message falls through to string match",
err: &mockRequestError{code: gocql.ErrCodeSyntax, message: "no such table ks.tbl"},
expected: true,
},
{
name: "RequestError with unrelated message",
err: &mockRequestError{code: gocql.ErrCodeInvalid, message: "invalid query syntax"},
expected: false,
},
{
name: "generic error with no such table",
err: errors.New("no such table ks.tbl"),
expected: true,
},
{
name: "generic error with unconfigured table",
err: errors.New("unconfigured table tbl"),
expected: true,
},
{
name: "generic error with does not exist",
err: errors.New("keyspace does not exist"),
expected: true,
},
{
name: "unrelated error",
err: errors.New("connection refused"),
expected: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := isTableMissingError(tt.err)
if got != tt.expected {
t.Errorf("isTableMissingError(%v) = %v, want %v", tt.err, got, tt.expected)
}
})
}
}