-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
153 lines (139 loc) · 4.54 KB
/
config_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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package redmine
import (
"testing"
"github.com/rs/zerolog"
)
func TestNewConfig(t *testing.T) {
logger := zerolog.New(nil)
cfg := NewConfig(
WithLog(&logger),
WithHost("https://redmine.example.com"),
WithAPIKey("your_api_key"),
WithProjectIdentifier("my-project"),
WithTrackerID(1),
WithWaitingForOperatorStatusID(1),
WithWaitingForCustomerStatusID(2),
WithDoneStatusID(3),
)
if cfg.Log == nil {
t.Error("Expected cfg.Log to be set, but it was nil")
}
if cfg.Host != "https://redmine.example.com" {
t.Errorf("Expected Host to be 'https://redmine.example.com', but got '%s'", cfg.Host)
}
if cfg.APIKey != "your_api_key" {
t.Errorf("Expected APIKey to be 'your_api_key', but got '%s'", cfg.APIKey)
}
if cfg.ProjectIdentifier != "my-project" {
t.Errorf("Expected ProjectIdentifier to be 'my-project', but got '%s'", cfg.ProjectIdentifier)
}
if cfg.TrackerID != 1 {
t.Errorf("Expected TrackerID to be 1, but got %d", cfg.TrackerID)
}
if cfg.WaitingForOperatorStatusID != 1 {
t.Errorf("Expected WaitingForOperatorStatusID to be 1, but got %d", cfg.WaitingForOperatorStatusID)
}
if cfg.WaitingForCustomerStatusID != 2 {
t.Errorf("Expected WaitingForCustomerStatusID to be 2, but got %d", cfg.WaitingForCustomerStatusID)
}
if cfg.DoneStatusID != 3 {
t.Errorf("Expected DoneStatusID to be 3, but got %d", cfg.DoneStatusID)
}
}
func TestConfigEnabled(t *testing.T) {
logger := zerolog.New(nil)
cfg := NewConfig(
WithLog(&logger),
WithHost("https://redmine.example.com"),
WithAPIKey("your_api_key"),
WithProjectIdentifier("my-project"),
WithTrackerID(1),
WithWaitingForOperatorStatusID(1),
WithWaitingForCustomerStatusID(2),
WithDoneStatusID(3),
)
if !cfg.Enabled() {
t.Error("Expected cfg.Enabled() to return true, but it returned false")
}
cfg.Host = ""
if cfg.Enabled() {
t.Error("Expected cfg.Enabled() to return false, but it returned true")
}
}
func TestConfigDefaults(t *testing.T) {
cfg := NewConfig()
if cfg.Log == nil {
t.Error("Expected cfg.Log to be set, but it was nil")
}
if cfg.Host != "" {
t.Errorf("Expected Host to be '', but got '%s'", cfg.Host)
}
if cfg.APIKey != "" {
t.Errorf("Expected APIKey to be '', but got '%s'", cfg.APIKey)
}
if cfg.ProjectIdentifier != "" {
t.Errorf("Expected ProjectIdentifier to be '', but got '%s'", cfg.ProjectIdentifier)
}
if cfg.ProjectID != 0 {
t.Errorf("Expected ProjectID to be 0, but got %d", cfg.ProjectID)
}
if cfg.UserID != 0 {
t.Errorf("Expected UserID to be 0, but got %d", cfg.UserID)
}
if cfg.TrackerID != 0 {
t.Errorf("Expected TrackerID to be 0, but got %d", cfg.TrackerID)
}
if cfg.WaitingForOperatorStatusID != 0 {
t.Errorf("Expected WaitingForOperatorStatusID to be 0, but got %d", cfg.WaitingForOperatorStatusID)
}
if cfg.WaitingForCustomerStatusID != 0 {
t.Errorf("Expected WaitingForCustomerStatusID to be 0, but got %d", cfg.WaitingForCustomerStatusID)
}
if cfg.DoneStatusID != 0 {
t.Errorf("Expected DoneStatusID to be 0, but got %d", cfg.DoneStatusID)
}
}
func TestConfigOptions(t *testing.T) {
logger := zerolog.New(nil)
cfg := &Config{}
WithLog(&logger)(cfg)
WithHost("https://redmine.example.com")(cfg)
WithAPIKey("your_api_key")(cfg)
WithProjectIdentifier("my-project")(cfg)
WithProjectID(123)(cfg)
WithUserID(456)(cfg)
WithTrackerID(1)(cfg)
WithWaitingForOperatorStatusID(1)(cfg)
WithWaitingForCustomerStatusID(2)(cfg)
WithDoneStatusID(3)(cfg)
if cfg.Log != &logger {
t.Error("Expected cfg.Log to be set to the provided logger, but it was not")
}
if cfg.Host != "https://redmine.example.com" {
t.Errorf("Expected Host to be 'https://redmine.example.com', but got '%s'", cfg.Host)
}
if cfg.APIKey != "your_api_key" {
t.Errorf("Expected APIKey to be 'your_api_key', but got '%s'", cfg.APIKey)
}
if cfg.ProjectIdentifier != "my-project" {
t.Errorf("Expected ProjectIdentifier to be 'my-project', but got '%s'", cfg.ProjectIdentifier)
}
if cfg.ProjectID != 123 {
t.Errorf("Expected ProjectID to be 123, but got %d", cfg.ProjectID)
}
if cfg.UserID != 456 {
t.Errorf("Expected UserID to be 456, but got %d", cfg.UserID)
}
if cfg.TrackerID != 1 {
t.Errorf("Expected TrackerID to be 1, but got %d", cfg.TrackerID)
}
if cfg.WaitingForOperatorStatusID != 1 {
t.Errorf("Expected WaitingForOperatorStatusID to be 1, but got %d", cfg.WaitingForOperatorStatusID)
}
if cfg.WaitingForCustomerStatusID != 2 {
t.Errorf("Expected WaitingForCustomerStatusID to be 2, but got %d", cfg.WaitingForCustomerStatusID)
}
if cfg.DoneStatusID != 3 {
t.Errorf("Expected DoneStatusID to be 3, but got %d", cfg.DoneStatusID)
}
}