|
4 | 4 | package commands |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "encoding/base64" |
7 | 8 | "encoding/json" |
8 | 9 | "errors" |
9 | 10 | "fmt" |
@@ -155,6 +156,31 @@ func TestDeployCommand(t *testing.T) { |
155 | 156 | ), |
156 | 157 | commandArgs: []string{"--" + model.FlagChangesVersion, "version number", "--" + model.FlagChangesDescription, "version description", "--" + model.FlagChangesCommitSha, "version commitsha"}, |
157 | 158 | }, |
| 159 | + { |
| 160 | + name: "create with base64 encoding", |
| 161 | + workerAction: "BEFORE_UPLOAD", |
| 162 | + workerName: "wk-0", |
| 163 | + commandArgs: []string{"--" + model.FlagBase64}, |
| 164 | + serverBehavior: common.NewServerStub(t). |
| 165 | + WithGetOneEndpoint(). |
| 166 | + WithCreateEndpoint( |
| 167 | + expectDeployRequestBase64(actionsMeta, "wk-0", "BEFORE_UPLOAD", ""), |
| 168 | + ), |
| 169 | + }, |
| 170 | + { |
| 171 | + name: "update with base64 encoding", |
| 172 | + workerAction: "GENERIC_EVENT", |
| 173 | + workerName: "wk-1", |
| 174 | + commandArgs: []string{"--" + model.FlagBase64}, |
| 175 | + serverBehavior: common.NewServerStub(t). |
| 176 | + WithGetOneEndpoint(). |
| 177 | + WithUpdateEndpoint( |
| 178 | + expectDeployRequestBase64(actionsMeta, "wk-1", "GENERIC_EVENT", ""), |
| 179 | + ). |
| 180 | + WithWorkers(&model.WorkerDetails{ |
| 181 | + Key: "wk-1", |
| 182 | + }), |
| 183 | + }, |
158 | 184 | { |
159 | 185 | name: "fails when version invalid", |
160 | 186 | serverBehavior: common.NewServerStub(t). |
@@ -239,6 +265,17 @@ func expectDeployRequest(actionsMeta common.ActionsMetadata, workerName, actionN |
239 | 265 | } |
240 | 266 | } |
241 | 267 |
|
| 268 | +func expectDeployRequestBase64(actionsMeta common.ActionsMetadata, workerName, actionName, projectKey string, secrets ...*model.Secret) common.BodyValidator { |
| 269 | + return func(t require.TestingT, body []byte) { |
| 270 | + want := getExpectedDeployRequestForAction(t, actionsMeta, workerName, actionName, projectKey, secrets...) |
| 271 | + want.SourceCode = "base64:" + base64.StdEncoding.EncodeToString([]byte(want.SourceCode)) |
| 272 | + got := &deployRequest{} |
| 273 | + err := json.Unmarshal(body, got) |
| 274 | + require.NoError(t, err) |
| 275 | + assertDeployRequestEquals(t, want, got) |
| 276 | + } |
| 277 | +} |
| 278 | + |
242 | 279 | func getExpectedDeployRequestForAction( |
243 | 280 | t require.TestingT, |
244 | 281 | actionsMeta common.ActionsMetadata, |
|
0 commit comments