These tests ensure that given the right input, we call the server's API appropriately they all run in automation mode where survey is disabled; they'd error if they tried to ask questions
(t *testing.T)
| 1199 | // These tests ensure that given the right input, we call the server's API appropriately |
| 1200 | // they all run in automation mode where survey is disabled; they'd error if they tried to ask questions |
| 1201 | func TestReleaseCreate_AutomationMode(t *testing.T) { |
| 1202 | fakeRepoUrl, _ := url.Parse("https://gitserver/repo") |
| 1203 | |
| 1204 | const cacProjectID = "Projects-92" |
| 1205 | |
| 1206 | space1 := fixtures.NewSpace("Spaces-1", "Default Space") |
| 1207 | |
| 1208 | depProcess := fixtures.NewDeploymentProcessForProject(space1.ID, cacProjectID) |
| 1209 | |
| 1210 | protectedBranchNamePatterns := []string{} |
| 1211 | cacProject := fixtures.NewProject(space1.ID, cacProjectID, "CaC Project", "Lifecycles-1", "ProjectGroups-1", depProcess.ID) |
| 1212 | cacProject.PersistenceSettings = projects.NewGitPersistenceSettings( |
| 1213 | ".octopus", |
| 1214 | credentials.NewAnonymous(), |
| 1215 | "main", |
| 1216 | protectedBranchNamePatterns, |
| 1217 | fakeRepoUrl, |
| 1218 | ) |
| 1219 | |
| 1220 | tests := []struct { |
| 1221 | name string |
| 1222 | run func(t *testing.T, api *testutil.MockHttpServer, rootCmd *cobra.Command, stdOut *bytes.Buffer, stdErr *bytes.Buffer) |
| 1223 | }{ |
| 1224 | {"release creation requires a project name", func(t *testing.T, api *testutil.MockHttpServer, rootCmd *cobra.Command, stdOut *bytes.Buffer, stdErr *bytes.Buffer) { |
| 1225 | cmdReceiver := testutil.GoBegin2(func() (*cobra.Command, error) { |
| 1226 | defer api.Close() |
| 1227 | rootCmd.SetArgs([]string{"release", "create"}) |
| 1228 | return rootCmd.ExecuteC() |
| 1229 | }) |
| 1230 | |
| 1231 | api.ExpectRequest(t, "GET", "/api/").RespondWith(rootResource) |
| 1232 | api.ExpectRequest(t, "GET", "/api/Spaces-1").RespondWith(rootResource) |
| 1233 | |
| 1234 | _, err := testutil.ReceivePair(cmdReceiver) |
| 1235 | assert.EqualError(t, err, "project must be specified") |
| 1236 | |
| 1237 | assert.Equal(t, "", stdOut.String()) |
| 1238 | // At first glance it may appear a bit weird that stdErr doesn't contain the error message here. |
| 1239 | // This is fine though, the main program entrypoint prints any errors that bubble up to it. |
| 1240 | assert.Equal(t, "", stdErr.String()) |
| 1241 | }}, |
| 1242 | |
| 1243 | {"release creation specifying project only (bare minimum)", func(t *testing.T, api *testutil.MockHttpServer, rootCmd *cobra.Command, stdOut *bytes.Buffer, stdErr *bytes.Buffer) { |
| 1244 | cmdReceiver := testutil.GoBegin2(func() (*cobra.Command, error) { |
| 1245 | defer api.Close() |
| 1246 | rootCmd.SetArgs([]string{"release", "create", "--project", cacProject.Name}) |
| 1247 | return rootCmd.ExecuteC() |
| 1248 | }) |
| 1249 | |
| 1250 | api.ExpectRequest(t, "GET", "/api/").RespondWith(rootResource) |
| 1251 | api.ExpectRequest(t, "GET", "/api/Spaces-1").RespondWith(rootResource) |
| 1252 | api.ExpectRequest(t, "GET", "/api/Spaces-1/projects/CaC Project").RespondWith(cacProject) |
| 1253 | |
| 1254 | req := api.ExpectRequest(t, "POST", "/api/Spaces-1/releases/create/v1") |
| 1255 | |
| 1256 | // check that it sent the server the right request body |
| 1257 | requestBody, err := testutil.ReadJson[releases.CreateReleaseCommandV1](req.Request.Body) |
| 1258 | assert.Nil(t, err) |
nothing calls this directly
no test coverage detected