1
1
package builder
2
2
3
3
import (
4
+ "reflect"
4
5
"testing"
5
6
)
6
7
@@ -17,5 +18,122 @@ func TestBuildTokenFlagsWithoutPrune(t *testing.T) {
17
18
if tokenParams != " --auth-token token --server host --insecure" {
18
19
t .Errorf ("Wrong \" %s\" token command " , tokenParams )
19
20
}
21
+ }
22
+
23
+ func TestRolloutWithoutWaitHealthy (t * testing.T ) {
24
+ builder := New ()
25
+ builder .Rollout (& RolloutArgs {
26
+ KubernetesContext : "kube-ctx" ,
27
+ RolloutName : "app" ,
28
+ RolloutNamespace : "default" ,
29
+ WaitHealthy : false ,
30
+ WaitAdditionalFlags : "" ,
31
+ Debug : false ,
32
+ }, "test" , "token" , "host" , "context" )
33
+
34
+ expectedLines := []string {
35
+ "#!/bin/bash -e" ,
36
+ "kubectl config get-contexts" ,
37
+ "kubectl config use-context \" kube-ctx\" " ,
38
+ "kubectl argo rollouts promote \" app\" -n \" default\" " ,
39
+ }
40
+
41
+ lines := builder .GetLines ()
42
+
43
+ if ! reflect .DeepEqual (expectedLines , lines ) {
44
+ t .Error ("Rollout commands is incorrect" )
45
+ }
46
+
47
+ }
48
+
49
+ func TestRolloutWithWaitHealthy (t * testing.T ) {
50
+ builder := New ()
51
+ builder .Rollout (& RolloutArgs {
52
+ KubernetesContext : "kube-ctx" ,
53
+ RolloutName : "app" ,
54
+ RolloutNamespace : "default" ,
55
+ WaitHealthy : true ,
56
+ WaitAdditionalFlags : "" ,
57
+ Debug : false ,
58
+ }, "test" , "token" , "host" , "context" )
59
+
60
+ expectedLines := []string {
61
+ "#!/bin/bash -e" ,
62
+ "kubectl config get-contexts" ,
63
+ "kubectl config use-context \" kube-ctx\" " ,
64
+ "kubectl argo rollouts promote \" app\" -n \" default\" " ,
65
+ `
66
+ cf-argo-plugin wait-rollout test --cf-host=$CF_URL --cf-token=$CF_API_KEY --cf-integration=context --pipeline-id=$CF_PIPELINE_NAME --build-id=$CF_BUILD_ID &
67
+ sleep 5s
68
+ ` ,
69
+ "argocd app wait test --auth-token token --server --insecure" ,
70
+ }
71
+
72
+ lines := builder .GetLines ()
73
+
74
+ if ! reflect .DeepEqual (expectedLines , lines ) {
75
+ t .Error ("Rollout commands is incorrect" )
76
+ }
77
+
78
+ }
79
+
80
+ func TestSyncWithoutWaitHealthy (t * testing.T ) {
81
+ builder := New ()
82
+ builder .Sync (& SyncArgs {
83
+ WaitHealthy : false ,
84
+ WaitAdditionalFlags : "" ,
85
+ Debug : false ,
86
+ Sync : true ,
87
+ }, "test" , "token" , "host" , "context" )
88
+
89
+ expectedLines := []string {
90
+ "#!/bin/bash -e" ,
91
+ "argocd app sync test --auth-token token --server --insecure" ,
92
+ }
93
+
94
+ lines := builder .GetLines ()
95
+
96
+ if ! reflect .DeepEqual (expectedLines , lines ) {
97
+ t .Error ("Sync commands is incorrect" )
98
+ }
99
+
100
+ }
101
+
102
+ func TestSyncWithWaitHealthy (t * testing.T ) {
103
+ builder := New ()
104
+ builder .Sync (& SyncArgs {
105
+ WaitHealthy : true ,
106
+ WaitAdditionalFlags : "" ,
107
+ Debug : false ,
108
+ Sync : true ,
109
+ }, "test" , "token" , "host" , "context" )
110
+
111
+ expectedLines := []string {
112
+ "#!/bin/bash -e" ,
113
+ `
114
+ cf-argo-plugin wait-rollout test --cf-host=$CF_URL --cf-token=$CF_API_KEY --cf-integration=context --pipeline-id=$CF_PIPELINE_NAME --build-id=$CF_BUILD_ID &
115
+ sleep 5s
116
+ ` ,
117
+ "argocd app sync test --auth-token token --server --insecure" ,
118
+ `
119
+ {
120
+ set +e
121
+ argocd app wait test --auth-token token --server --insecure 2> /codefresh/volume/sync_error.log
122
+ }
123
+ if [[ $? -ne 0 ]]; then
124
+ ARGO_SYNC_ERROR=$(cat /codefresh/volume/sync_error.log | grep -i fatal)
125
+ fi
126
+ echo ARGO_SYNC_ERROR="$ARGO_SYNC_ERROR"
127
+ cf_export ARGO_SYNC_ERROR="$ARGO_SYNC_ERROR"
128
+
129
+ wait
130
+ ` ,
131
+ }
132
+
133
+ lines := builder .GetLines ()
134
+
135
+ if ! reflect .DeepEqual (expectedLines , lines ) {
136
+ t .Error ("Sync commands is incorrect" )
137
+ }
20
138
21
139
}
0 commit comments