Skip to content

Commit

Permalink
Test creating a project in space
Browse files Browse the repository at this point in the history
  • Loading branch information
tothegills committed Oct 24, 2023
1 parent faf3715 commit d22b9e8
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 0 deletions.
92 changes: 92 additions & 0 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"fmt"
"os"
"path/filepath"
"sort"
"strings"
"testing"

Expand Down Expand Up @@ -1337,6 +1338,97 @@ func TestProjectResource(t *testing.T) {
})
}

func TestProjectInSpaceResource(t *testing.T) {
testFramework := test.OctopusContainerTest{}
testFramework.ArrangeTest(t, func(t *testing.T, container *test.OctopusContainer, spaceClient *client.Client) error {
// Act
newSpaceId, err := testFramework.Act(t, container, "./terraform", "19b-projectspace", []string{})

if err != nil {
return err
}

err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "19b-projectspace"), newSpaceId, []string{})

if err != nil {
return err
}

// Assert
client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey)

spaces, err := spaces.GetAll(client)

Check failure on line 1360 in integration_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: spaces.GetAll

if err != nil {
return err
}
idx := sort.Search(len(spaces), func(i int) bool { return spaces[i].Name == "Project Space Test" })
space := spaces[idx]

query := projects.ProjectsQuery{
PartialName: "Test project in space",
Skip: 0,
Take: 1,
}

resources, err := projects.Get(client, space.ID, query)

Check failure on line 1374 in integration_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: projects.Get
if err != nil {
return err
}

if len(resources.Items) == 0 {
t.Fatalf("Space must have a project called \"Test project in space\"")
}
resource := resources.Items[0]

if resource.Description != "Test project in space" {
t.Fatal("The project must be have a description of \"Test project in space\" (was \"" + resource.Description + "\")")
}

if resource.AutoCreateRelease {
t.Fatal("The project must not have auto release create enabled")
}

if resource.DefaultGuidedFailureMode != "EnvironmentDefault" {
t.Fatal("The project must be have a DefaultGuidedFailureMode of \"EnvironmentDefault\" (was \"" + resource.DefaultGuidedFailureMode + "\")")
}

if resource.DefaultToSkipIfAlreadyInstalled {
t.Fatal("The project must not have DefaultToSkipIfAlreadyInstalled enabled")
}

if resource.IsDisabled {
t.Fatal("The project must not have IsDisabled enabled")
}

if resource.IsVersionControlled {
t.Fatal("The project must not have IsVersionControlled enabled")
}

if resource.TenantedDeploymentMode != "Untenanted" {
t.Fatal("The project must be have a TenantedDeploymentMode of \"Untenanted\" (was \"" + resource.TenantedDeploymentMode + "\")")
}

if len(resource.IncludedLibraryVariableSets) != 0 {
t.Fatal("The project must not have any library variable sets")
}

if resource.ConnectivityPolicy.AllowDeploymentsToNoTargets {
t.Fatal("The project must not have ConnectivityPolicy.AllowDeploymentsToNoTargets enabled")
}

if resource.ConnectivityPolicy.ExcludeUnhealthyTargets {
t.Fatal("The project must not have ConnectivityPolicy.AllowDeploymentsToNoTargets enabled")
}

if resource.ConnectivityPolicy.SkipMachineBehavior != "SkipUnavailableMachines" {
t.Log("BUG: The project must be have a ConnectivityPolicy.SkipMachineBehavior of \"SkipUnavailableMachines\" (was \"" + resource.ConnectivityPolicy.SkipMachineBehavior + "\") - Known issue where the value returned by /api/Spaces-#/ProjectGroups/ProjectGroups-#/projects is different to /api/Spaces-/Projects")
}

return nil
})
}

// TestProjectChannelResource verifies that a project channel can be reimported with the correct settings
func TestProjectChannelResource(t *testing.T) {
testFramework := test.OctopusContainerTest{}
Expand Down
7 changes: 7 additions & 0 deletions terraform/19b-projectspace/config.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
required_providers {
octopusdeploy = { source = "OctopusDeployLabs/octopusdeploy", version = "0.11.3" }
// Use the option below when debugging
// octopusdeploy = { source = "octopus.com/com/octopusdeploy" }
}
}
33 changes: 33 additions & 0 deletions terraform/19b-projectspace/project.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
data "octopusdeploy_lifecycles" "lifecycle_default_lifecycle" {
ids = null
partial_name = "Default Lifecycle"
skip = 0
take = 1
}


resource "octopusdeploy_project" "deploy_frontend_project" {
auto_create_release = false
default_guided_failure_mode = "EnvironmentDefault"
default_to_skip_if_already_installed = false
description = "Test project"
discrete_channel_release = false
is_disabled = false
is_discrete_channel_release = false
is_version_controlled = false
lifecycle_id = data.octopusdeploy_lifecycles.lifecycle_default_lifecycle.lifecycles[0].id
name = "Test"
project_group_id = octopusdeploy_project_group.project_group_test.id
tenanted_deployment_participation = "Untenanted"
space_id = var.octopus_space_id
included_library_variable_sets = []
versioning_strategy {
template = "#{Octopus.Version.LastMajor}.#{Octopus.Version.LastMinor}.#{Octopus.Version.LastPatch}.#{Octopus.Version.NextRevision}"
}

connectivity_policy {
allow_deployments_to_no_targets = false
exclude_unhealthy_targets = false
skip_machine_behavior = "SkipUnavailableMachines"
}
}
5 changes: 5 additions & 0 deletions terraform/19b-projectspace/project_group_test.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "octopusdeploy_project_group" "project_group_test" {
name = "Test"
description = "Test Description"
space_id = octopusdeploy_space.octopus_project_space_test.id
}
5 changes: 5 additions & 0 deletions terraform/19b-projectspace/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
provider "octopusdeploy" {
address = "${var.octopus_server}"
api_key = "${var.octopus_apikey}"
space_id = "${var.octopus_space_id}"
}
18 changes: 18 additions & 0 deletions terraform/19b-projectspace/provider_vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
variable "octopus_server" {
type = string
nullable = false
sensitive = false
description = "The URL of the Octopus server e.g. https://myinstance.octopus.app."
}
variable "octopus_apikey" {
type = string
nullable = false
sensitive = true
description = "The API key used to access the Octopus server. See https://octopus.com/docs/octopus-rest-api/how-to-create-an-api-key for details on creating an API key."
}
variable "octopus_space_id" {
type = string
nullable = false
sensitive = false
description = "The space ID to populate"
}
4 changes: 4 additions & 0 deletions terraform/19b-projectspace/space.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "octopusdeploy_space" "project_space" {
name = "Project space"
description = "Test Description"
}

0 comments on commit d22b9e8

Please sign in to comment.