-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_ok_test.go
89 lines (70 loc) · 2.28 KB
/
main_ok_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
package main
import (
"strings"
"testing"
)
func TestMainLogicNoArgs(t *testing.T) {
mockKubectl := new(MockKubectl)
mockWriter := new(MockWriter)
namespace := ""
_, err := mainLogic(mockKubectl, mockWriter, namespace, []string{})
if err != nil {
t.Errorf("Expected no error")
}
}
func assertThereIsSomeDiff(t *testing.T, writer *MockWriter) {
output := writer.GetOutput()
lines := strings.Split(output, "\n")
plusFound := false
minusFound := false
for _, line := range lines {
if strings.HasPrefix(line, "-") {
minusFound = true
} else if strings.HasPrefix(line, "+") {
plusFound = true
}
}
if !(plusFound && minusFound) {
t.Errorf("Output does not contain both + and - line prefixes")
}
}
func TestShowingDiffBetweenTwoRevisions(t *testing.T) {
mockKubectl := new(MockKubectl)
mockKubectl.On("getRolloutHistoryWithRevision", "deployment", "nginx", 1, "").Return("some output 1", nil)
mockKubectl.On("getRolloutHistoryWithRevision", "deployment", "nginx", 2, "").Return("some output 2", nil)
mockWriter := new(MockWriter)
namespace := ""
_, err := mainLogic(mockKubectl, mockWriter, namespace, []string{"deployment", "nginx", "1", "2"})
if err != nil {
t.Errorf("Expected no error")
}
assertThereIsSomeDiff(t, mockWriter)
}
func TestShowingRollbackHistoryWhenNoRevisionIsSpecified(t *testing.T) {
mockKubectl := new(MockKubectl)
mockKubectl.On("getRolloutHistory", "deployment", "nginx", "").Return("history", nil)
mockWriter := new(MockWriter)
namespace := ""
_, err := mainLogic(mockKubectl, mockWriter, namespace, []string{"deployment/nginx"})
if err != nil {
t.Errorf("Expected no error")
}
output := mockWriter.GetOutput()
if !strings.Contains(output, "history") {
t.Errorf("Expected output to contain history")
}
}
func TestShowingRollbackHistoryWhenNoRevisionIsSpecifiedAndNamespaceIs(t *testing.T) {
mockKubectl := new(MockKubectl)
mockKubectl.On("getRolloutHistory", "daemonset", "busybox", "default").Return("history", nil)
mockWriter := new(MockWriter)
namespace := "default"
_, err := mainLogic(mockKubectl, mockWriter, namespace, []string{"daemonset/busybox"})
if err != nil {
t.Errorf("Expected no error")
}
output := mockWriter.GetOutput()
if !strings.Contains(output, "history") {
t.Errorf("Expected output to contain history")
}
}