- Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathjetstream_errors_test.go
83 lines (65 loc) · 2.75 KB
/
jetstream_errors_test.go
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
package server
import (
"errors"
"testing"
)
funcTestIsNatsErr(t*testing.T) {
if!IsNatsErr(ApiErrors[JSNotEnabledForAccountErr], JSNotEnabledForAccountErr) {
t.Fatalf("Expected error match")
}
ifIsNatsErr(ApiErrors[JSNotEnabledForAccountErr], JSClusterNotActiveErr) {
t.Fatalf("Expected error mismatch")
}
ifIsNatsErr(ApiErrors[JSNotEnabledForAccountErr], JSClusterNotActiveErr, JSClusterNotAvailErr) {
t.Fatalf("Expected error mismatch")
}
if!IsNatsErr(ApiErrors[JSNotEnabledForAccountErr], JSClusterNotActiveErr, JSNotEnabledForAccountErr) {
t.Fatalf("Expected error match")
}
if!IsNatsErr(&ApiError{ErrCode: 10039}, 1, JSClusterNotActiveErr, JSNotEnabledForAccountErr) {
t.Fatalf("Expected error match")
}
ifIsNatsErr(&ApiError{ErrCode: 10039}, 1, 2, JSClusterNotActiveErr) {
t.Fatalf("Expected error mismatch")
}
ifIsNatsErr(nil, JSClusterNotActiveErr) {
t.Fatalf("Expected error mismatch")
}
ifIsNatsErr(errors.New("x"), JSClusterNotActiveErr) {
t.Fatalf("Expected error mismatch")
}
}
funcTestApiError_Error(t*testing.T) {
ifes:=ApiErrors[JSClusterNotActiveErr].Error(); es!="JetStream not in clustered mode (10006)" {
t.Fatalf("Expected 'JetStream not in clustered mode (10006)', got %q", es)
}
}
funcTestApiError_NewWithTags(t*testing.T) {
ne:=NewJSRestoreSubscribeFailedError(errors.New("failed error"), "the.subject")
ifne.Description!="JetStream unable to subscribe to restore snapshot the.subject: failed error" {
t.Fatalf("Expected 'JetStream unable to subscribe to restore snapshot the.subject: failed error' got %q", ne.Description)
}
ifne==ApiErrors[JSRestoreSubscribeFailedErrF] {
t.Fatalf("Expected a new instance")
}
}
funcTestApiError_NewWithUnless(t*testing.T) {
ifne:=NewJSStreamRestoreError(errors.New("failed error"), Unless(ApiErrors[JSNotEnabledForAccountErr])); !IsNatsErr(ne, JSNotEnabledForAccountErr) {
t.Fatalf("Expected JSNotEnabledForAccountErr got %s", ne)
}
ifne:=NewJSStreamRestoreError(errors.New("failed error")); !IsNatsErr(ne, JSStreamRestoreErrF) {
t.Fatalf("Expected JSStreamRestoreErrF got %s", ne)
}
ifne:=NewJSStreamRestoreError(errors.New("failed error"), Unless(errors.New("other error"))); !IsNatsErr(ne, JSStreamRestoreErrF) {
t.Fatalf("Expected JSStreamRestoreErrF got %s", ne)
}
ifne:=NewJSPeerRemapError(Unless(ApiErrors[JSNotEnabledForAccountErr])); !IsNatsErr(ne, JSNotEnabledForAccountErr) {
t.Fatalf("Expected JSNotEnabledForAccountErr got %s", ne)
}
ifne:=NewJSPeerRemapError(Unless(nil)); !IsNatsErr(ne, JSPeerRemapErr) {
t.Fatalf("Expected JSPeerRemapErr got %s", ne)
}
ifne:=NewJSPeerRemapError(Unless(errors.New("other error"))); !IsNatsErr(ne, JSPeerRemapErr) {
t.Fatalf("Expected JSPeerRemapErr got %s", ne)
}
}