-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathheaders_test.go
118 lines (114 loc) · 2.25 KB
/
headers_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Package stormrpc provides the functionality for creating RPC servers/clients that communicate via NATS.
package stormrpc
import (
"reflect"
"strconv"
"testing"
"time"
"github.com/nats-io/nats.go"
)
func Test_parseErrorHeader(t *testing.T) {
type args struct {
header nats.Header
}
tests := []struct {
name string
args args
want *Error
}{
{
name: "no error header",
args: args{
header: nats.Header{},
},
want: nil,
},
{
name: "weirdly formatted error header",
args: args{
header: nats.Header{
errorHeader: []string{"BIG HEADER", "NICE ERROR"},
},
},
want: &Error{
Code: ErrorCodeUnknown,
Message: "unknown error",
},
},
{
name: "not found error",
args: args{
header: nats.Header{
errorHeader: []string{"STORMRPC_CODE_NOT_FOUND: new error"},
},
},
want: &Error{
Code: ErrorCodeNotFound,
Message: "new error",
},
},
{
name: "unknown error",
args: args{
header: nats.Header{
errorHeader: []string{"STORMRPC_CODE_UNKNOWN: xD"},
},
},
want: &Error{
Code: ErrorCodeUnknown,
Message: "unknown error",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := parseErrorHeader(tt.args.header); !reflect.DeepEqual(got, tt.want) {
t.Errorf("parseErrorHeader() = %v, want %v", got, tt.want)
}
})
}
}
func Test_parseDeadlineHeader(t *testing.T) {
type args struct {
header nats.Header
}
tests := []struct {
name string
args args
want time.Time
}{
// TODO: Add test cases.
{
name: "no header",
args: args{
header: nats.Header{},
},
want: time.Time{},
},
{
name: "header non int",
args: args{
header: nats.Header{
deadlineHeader: []string{"bob"},
},
},
want: time.Time{},
},
{
name: "header with unix time",
args: args{
header: nats.Header{
deadlineHeader: []string{strconv.FormatInt(time.Now().Round(1*time.Minute).Unix(), 10)},
},
},
want: time.Now().Round(1 * time.Minute),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := parseDeadlineHeader(tt.args.header); !reflect.DeepEqual(got, tt.want) {
t.Errorf("parseDeadlineHeader() = %v, want %v", got, tt.want)
}
})
}
}