Skip to content

Commit

Permalink
chore: test creating a project in space
Browse files Browse the repository at this point in the history
* Test creating a project in space

* Save changes

* Too many applies
tothegills authored Oct 24, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 440321f commit 62d4b66
Showing 7 changed files with 161 additions and 0 deletions.
86 changes: 86 additions & 0 deletions integration_test.go
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ import (
"fmt"
"os"
"path/filepath"
"sort"
"strings"
"testing"

@@ -1337,6 +1338,91 @@ 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
}

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

spaces, err := spaces.GetAll(client)

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)
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{}
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 in space"
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 in space"
project_group_id = octopusdeploy_project_group.project_group_test.id
tenanted_deployment_participation = "Untenanted"
space_id = octopusdeploy_space.octopus_project_space_test.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 of the provider"
}
7 changes: 7 additions & 0 deletions terraform/19b-projectspace/space.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "octopusdeploy_space" "octopus_project_space_test" {
name = "Project Space Test"
is_default = false
is_task_queue_stopped = false
description = "My test space"
space_managers_teams = ["teams-administrators"]
}

0 comments on commit 62d4b66

Please sign in to comment.