-
Notifications
You must be signed in to change notification settings - Fork 15
/
main_test.go
170 lines (148 loc) · 4.33 KB
/
main_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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Copyright (c) 2016, M Bogus.
// This source file is part of the KUBE-AMQP-AUTOSCALE open source project
// Licensed under Apache License v2.0
// See LICENSE file for license information
package main
import "testing"
func TestSetVersion(t *testing.T) {
setVersion()
if got, want := appVersion, "(untracked build)"; got != want {
t.Errorf("Expected appVersion='%s', got: '%s'", want, got)
}
Version = "0.1"
BuildType = "RELEASE"
Build = "deadbeef"
setVersion()
if got, want := appVersion, "0.1 (deadbeef)"; got != want {
t.Errorf("Expected appVersion='%s', got: '%s'", want, got)
}
BuildType = "SNAPSHOT"
setVersion()
if got, want := appVersion, "0.1-SNAPSHOT (deadbeef)"; got != want {
t.Errorf("Expected appVersion='%s', got: '%s'", want, got)
}
BuildType = "DEV"
BuildDate = "2016-04-15T10:33:16+0100"
setVersion()
if got, want := appVersion, "0.1-DEV (+deadbeef 2016-04-15T10:33:16+0100)"; got != want {
t.Errorf("Expected appVersion='%s', got: '%s'", want, got)
}
}
func TestValidateParams(t *testing.T) {
err := validateParams()
if err == nil {
t.Fatal("Expected error")
}
if got, want := err.Error(), "Missing RabbitMQ URI"; got != want {
t.Errorf("Expected error='%s', got: '%s'", want, got)
}
brokerURIParam = "amqp://"
err = validateParams()
if err == nil {
t.Fatal("Expected error")
}
if got, want := err.Error(), "Missing RabbitMQ queue name"; got != want {
t.Errorf("Expected error='%s', got: '%s'", want, got)
}
queueNameParam = "queue"
err = validateParams()
if err == nil {
t.Fatal("Expected error")
}
if got, want := err.Error(), "Missing Kubernetes API URL"; got != want {
t.Errorf("Expected error='%s', got: '%s'", want, got)
}
apiURLParam = "http://"
intervalParam = 0
err = validateParams()
if err == nil {
t.Fatal("Expected error")
}
if got, want := err.Error(), "Invalid auto-scale interval '0'"; got != want {
t.Errorf("Expected error='%s', got: '%s'", want, got)
}
intervalParam = 10
thresholdParam = 0
err = validateParams()
if err == nil {
t.Fatal("Expected error")
}
if got, want := err.Error(), "Invalid threshold value '0'"; got != want {
t.Errorf("Expected error='%s', got: '%s'", want, got)
}
thresholdParam = 1
statsIntervalParam = 15
err = validateParams()
if err == nil {
t.Fatal("Expected error")
}
if got, want := err.Error(), "Interval for saving statistics '15' should be smaller than auto-scale interval '10'"; got != want {
t.Errorf("Expected error='%s', got: '%s'", want, got)
}
statsIntervalParam = 5
statsCoverageParam = 1.5
err = validateParams()
if err == nil {
t.Fatal("Expected error")
}
if got, want := err.Error(), "Invalid metrics coverage ratio '1.50'"; got != want {
t.Errorf("Expected error='%s', got: '%s'", want, got)
}
statsCoverageParam = 1.0
minParam = -1
err = validateParams()
if err == nil {
t.Fatal("Expected error")
}
if got, want := err.Error(), "Invalid lower limit for the number of pods '-1'"; got != want {
t.Errorf("Expected error='%s', got: '%s'", want, got)
}
minParam = 1
maxParam = 1
err = validateParams()
if err == nil {
t.Fatal("Expected error")
}
if got, want := err.Error(), "Upper limit for the number of pods '1' must be greater than lower limit '1'"; got != want {
t.Errorf("Expected error='%s', got: '%s'", want, got)
}
maxParam = 2
err = validateParams()
if err == nil {
t.Fatal("Expected error")
}
if got, want := err.Error(), "Missing name of the resource to autoscale"; got != want {
t.Errorf("Expected error='%s', got: '%s'", want, got)
}
nameParam = "pod"
kindParam = ""
err = validateParams()
if err == nil {
t.Fatal("Expected error")
}
if got, want := err.Error(), "Missing kind of the resource to autoscale"; got != want {
t.Errorf("Expected error='%s', got: '%s'", want, got)
}
kindParam = "X"
err = validateParams()
if err == nil {
t.Fatal("Expected error")
}
if got, want := err.Error(), "Invalid kind of the resource 'X'"; got != want {
t.Errorf("Expected error='%s', got: '%s'", want, got)
}
kindParam = "ReplicationController"
namespaceParam = ""
err = validateParams()
if err == nil {
t.Fatal("Expected error")
}
if got, want := err.Error(), "Missing namespace of the resource to autoscale"; got != want {
t.Errorf("Expected error='%s', got: '%s'", want, got)
}
namespaceParam = "default"
err = validateParams()
if err != nil {
t.Fatal(err)
}
}