| 30 | } |
| 31 | |
| 32 | func CreateCommonProject(t *testing.T, apiClient *octopusApiClient.Client, runId uuid.UUID) (*CommonProjectFixture, error) { |
| 33 | // pre-requisites |
| 34 | projectGroup := projectgroups.NewProjectGroup(fmt.Sprintf("pg-%s", runId)) |
| 35 | projectGroup, err := apiClient.ProjectGroups.Add(projectGroup) |
| 36 | if !testutil.AssertSuccess(t, err) { |
| 37 | return nil, err |
| 38 | } |
| 39 | t.Cleanup(func() { assert.Nil(t, apiClient.ProjectGroups.DeleteByID(projectGroup.ID)) }) |
| 40 | |
| 41 | lifecycle := lifecycles.NewLifecycle(fmt.Sprintf("lifecycle-%s", runId)) |
| 42 | lifecycle, err = apiClient.Lifecycles.Add(lifecycle) |
| 43 | if !testutil.AssertSuccess(t, err) { |
| 44 | return nil, err |
| 45 | } |
| 46 | t.Cleanup(func() { assert.Nil(t, apiClient.Lifecycles.DeleteByID(lifecycle.ID)) }) |
| 47 | |
| 48 | // The project creates its own Default channel, using the specified lifecycle |
| 49 | project := projects.NewProject(fmt.Sprintf("project-%s", runId), lifecycle.ID, projectGroup.ID) |
| 50 | project, err = apiClient.Projects.Add(project) |
| 51 | if !testutil.AssertSuccess(t, err) { |
| 52 | return nil, err |
| 53 | } |
| 54 | t.Cleanup(func() { assert.Nil(t, apiClient.Projects.DeleteByID(project.ID)) }) |
| 55 | |
| 56 | projectChannels, err := apiClient.Projects.GetChannels(project) |
| 57 | testutil.RequireSuccess(t, err) |
| 58 | assert.Equal(t, 1, len(projectChannels)) |
| 59 | projectDefaultChannel := projectChannels[0] |
| 60 | |
| 61 | return &CommonProjectFixture{ |
| 62 | ProjectGroup: projectGroup, |
| 63 | Lifecycle: lifecycle, |
| 64 | Project: project, |
| 65 | ProjectDefaultChannel: projectDefaultChannel, |
| 66 | }, nil |
| 67 | } |