generated from rizalgowandy/library-template-go
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
context_test.go
119 lines (116 loc) · 2.24 KB
/
context_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
119
package cronx
import (
"context"
"reflect"
"testing"
)
func TestGetJobMetadata(t *testing.T) {
type args struct {
ctx context.Context
}
tests := []struct {
name string
args args
want JobMetadata
want1 bool
}{
{
name: "Nil",
args: args{},
want: JobMetadata{},
want1: false,
},
{
name: "Broken type",
args: args{
ctx: context.WithValue(context.Background(), CtxKeyJobMetadata, "this is string"),
},
want: JobMetadata{},
want1: false,
},
{
name: "Exists",
args: args{
ctx: context.WithValue(context.Background(), CtxKeyJobMetadata, JobMetadata{
EntryID: 1,
Wave: 2,
TotalWave: 3,
IsLastWave: true,
}),
},
want: JobMetadata{
EntryID: 1,
Wave: 2,
TotalWave: 3,
IsLastWave: true,
},
want1: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, got1 := GetJobMetadata(tt.args.ctx)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetJobMetadata() got = %v, want %v", got, tt.want)
}
if got1 != tt.want1 {
t.Errorf("GetJobMetadata() got1 = %v, want %v", got1, tt.want1)
}
})
}
}
func TestSetJobMetadata(t *testing.T) {
type args struct {
ctx context.Context
meta JobMetadata
}
tests := []struct {
name string
args args
want context.Context
}{
{
name: "Nil",
args: args{
ctx: nil,
meta: JobMetadata{
EntryID: 1,
Wave: 2,
TotalWave: 3,
IsLastWave: true,
},
},
want: context.WithValue(context.Background(), CtxKeyJobMetadata, JobMetadata{
EntryID: 1,
Wave: 2,
TotalWave: 3,
IsLastWave: true,
}),
},
{
name: "Exists",
args: args{
ctx: context.Background(),
meta: JobMetadata{
EntryID: 1,
Wave: 2,
TotalWave: 3,
IsLastWave: true,
},
},
want: context.WithValue(context.Background(), CtxKeyJobMetadata, JobMetadata{
EntryID: 1,
Wave: 2,
TotalWave: 3,
IsLastWave: true,
}),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := SetJobMetadata(tt.args.ctx, tt.args.meta); !reflect.DeepEqual(got, tt.want) {
t.Errorf("SetJobMetadata() = %v, want %v", got, tt.want)
}
})
}
}