44package commands
55
66import (
7+ "encoding/base64"
78 "encoding/json"
89 "errors"
910 "fmt"
@@ -37,6 +38,7 @@ func TestDeployCommand(t *testing.T) {
3738 workerName : "wk-0" ,
3839 serverBehavior : common .NewServerStub (t ).
3940 WithGetOneEndpoint ().
41+ WithOptionsEndpoint ().
4042 WithCreateEndpoint (
4143 expectDeployRequest (
4244 actionsMeta ,
@@ -60,6 +62,7 @@ func TestDeployCommand(t *testing.T) {
6062 workerName : "wk-1" ,
6163 serverBehavior : common .NewServerStub (t ).
6264 WithGetOneEndpoint ().
65+ WithOptionsEndpoint ().
6366 WithUpdateEndpoint (
6467 expectDeployRequest (actionsMeta , "wk-1" , "GENERIC_EVENT" , "" ),
6568 ).
@@ -73,6 +76,7 @@ func TestDeployCommand(t *testing.T) {
7376 workerName : "wk-2" ,
7477 serverBehavior : common .NewServerStub (t ).
7578 WithGetOneEndpoint ().
79+ WithOptionsEndpoint ().
7680 WithUpdateEndpoint (
7781 expectDeployRequest (
7882 actionsMeta ,
@@ -102,6 +106,7 @@ func TestDeployCommand(t *testing.T) {
102106 workerName : "wk-1" ,
103107 serverBehavior : common .NewServerStub (t ).
104108 WithGetOneEndpoint ().
109+ WithOptionsEndpoint ().
105110 WithCreateEndpoint (
106111 expectDeployRequest (actionsMeta , "wk-1" , "GENERIC_EVENT" , "proj-1" ),
107112 ),
@@ -113,7 +118,7 @@ func TestDeployCommand(t *testing.T) {
113118 name : "should validate schedule" ,
114119 workerAction : "SCHEDULED_EVENT" ,
115120 workerName : "wk-3" ,
116- serverBehavior : common .NewServerStub (t ).WithGetOneEndpoint (),
121+ serverBehavior : common .NewServerStub (t ).WithGetOneEndpoint (). WithOptionsEndpoint () ,
117122 patchManifest : func (mf * model.Manifest ) {
118123 mf .FilterCriteria = & model.FilterCriteria {
119124 Schedule : & model.ScheduleFilterCriteria {
@@ -129,6 +134,7 @@ func TestDeployCommand(t *testing.T) {
129134 commandArgs : []string {"--" + model .FlagTimeout , "500" },
130135 serverBehavior : common .NewServerStub (t ).
131136 WithDelay (1 * time .Second ).
137+ WithOptionsEndpoint ().
132138 WithCreateEndpoint (nil ),
133139 wantErr : errors .New ("request timed out after 500ms" ),
134140 },
@@ -155,6 +161,58 @@ func TestDeployCommand(t *testing.T) {
155161 ),
156162 commandArgs : []string {"--" + model .FlagChangesVersion , "version number" , "--" + model .FlagChangesDescription , "version description" , "--" + model .FlagChangesCommitSha , "version commitsha" },
157163 },
164+ {
165+ name : "create with base64 encoding" ,
166+ workerAction : "BEFORE_UPLOAD" ,
167+ workerName : "wk-0" ,
168+ commandArgs : []string {"--" + model .FlagBase64 },
169+ serverBehavior : common .NewServerStub (t ).
170+ WithGetOneEndpoint ().
171+ WithOptionsEndpoint ().
172+ WithCreateEndpoint (
173+ expectDeployRequestBase64 (actionsMeta , "wk-0" , "BEFORE_UPLOAD" , "" ),
174+ ),
175+ },
176+ {
177+ name : "update with base64 encoding" ,
178+ workerAction : "GENERIC_EVENT" ,
179+ workerName : "wk-1" ,
180+ commandArgs : []string {"--" + model .FlagBase64 },
181+ serverBehavior : common .NewServerStub (t ).
182+ WithGetOneEndpoint ().
183+ WithOptionsEndpoint ().
184+ WithUpdateEndpoint (
185+ expectDeployRequestBase64 (actionsMeta , "wk-1" , "GENERIC_EVENT" , "" ),
186+ ).
187+ WithWorkers (& model.WorkerDetails {
188+ Key : "wk-1" ,
189+ }),
190+ },
191+ {
192+ name : "create with base64 from options" ,
193+ workerAction : "BEFORE_UPLOAD" ,
194+ workerName : "wk-0" ,
195+ serverBehavior : common .NewServerStub (t ).
196+ WithGetOneEndpoint ().
197+ WithBase64OptionsEndpoint ().
198+ WithCreateEndpoint (
199+ expectDeployRequestBase64 (actionsMeta , "wk-0" , "BEFORE_UPLOAD" , "" ),
200+ ),
201+ },
202+ {
203+ name : "update with base64 from options" ,
204+ workerAction : "GENERIC_EVENT" ,
205+ workerName : "wk-1" ,
206+ serverBehavior : common .NewServerStub (t ).
207+ WithGetOneEndpoint ().
208+ WithBase64OptionsEndpoint ().
209+ WithUpdateEndpoint (
210+ expectDeployRequestBase64 (actionsMeta , "wk-1" , "GENERIC_EVENT" , "" ),
211+ ).
212+ WithWorkers (& model.WorkerDetails {
213+ Key : "wk-1" ,
214+ }),
215+ },
158216 {
159217 name : "fails when version invalid" ,
160218 serverBehavior : common .NewServerStub (t ).
@@ -239,6 +297,17 @@ func expectDeployRequest(actionsMeta common.ActionsMetadata, workerName, actionN
239297 }
240298}
241299
300+ func expectDeployRequestBase64 (actionsMeta common.ActionsMetadata , workerName , actionName , projectKey string , secrets ... * model.Secret ) common.BodyValidator {
301+ return func (t require.TestingT , body []byte ) {
302+ want := getExpectedDeployRequestForAction (t , actionsMeta , workerName , actionName , projectKey , secrets ... )
303+ want .SourceCode = "base64:" + base64 .StdEncoding .EncodeToString ([]byte (want .SourceCode ))
304+ got := & deployRequest {}
305+ err := json .Unmarshal (body , got )
306+ require .NoError (t , err )
307+ assertDeployRequestEquals (t , want , got )
308+ }
309+ }
310+
242311func getExpectedDeployRequestForAction (
243312 t require.TestingT ,
244313 actionsMeta common.ActionsMetadata ,
0 commit comments