Skip to content

Commit

Permalink
Cleaned up go.mod, updated test containers, and added an example test (
Browse files Browse the repository at this point in the history
…#6)

* Cleaned up go.mod, updated test containers, and added an example test

* Merged changes from main

* Fixed tests in workflow
  • Loading branch information
mcasperson authored Jul 19, 2024
1 parent f42871b commit 8ce08b0
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pr_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ jobs:
run: go build -v ./...
- name: Test
run: go test ./...
env:
LICENSE: ${{ secrets.LICENSE }}

12 changes: 10 additions & 2 deletions terraform/1-singlespace/space.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
resource "octopusdeploy_space" "octopus_space_test" {
name = "${var.octopus_space_name}"
name = var.octopus_space_name
is_default = false
is_task_queue_stopped = false
description = "My test space"
description = var.octopus_space_description
space_managers_teams = ["teams-administrators"]
}

Expand All @@ -17,3 +17,11 @@ variable "octopus_space_name" {
description = "The name of the new space"
default = "Test"
}

variable "octopus_space_description" {
type = string
nullable = false
sensitive = false
description = "The description of the new space"
default = "My test space"
}
5 changes: 5 additions & 0 deletions terraform/2-simpleexample/config.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
terraform {
required_providers {
octopusdeploy = { source = "OctopusDeployLabs/octopusdeploy", version = "0.21.4" }
}
}
20 changes: 20 additions & 0 deletions terraform/2-simpleexample/environments.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resource "octopusdeploy_environment" "development_environment" {
allow_dynamic_infrastructure = true
description = "A development environment"
name = "Development"
use_guided_failure = false
}

resource "octopusdeploy_environment" "test_environment" {
allow_dynamic_infrastructure = true
description = "A test environment"
name = "Test"
use_guided_failure = false
}

resource "octopusdeploy_environment" "production_environment" {
allow_dynamic_infrastructure = true
description = "A production environment"
name = "Production"
use_guided_failure = false
}
5 changes: 5 additions & 0 deletions terraform/2-simpleexample/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/2-simpleexample/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"
}
3 changes: 3 additions & 0 deletions terraform/2-simpleexample/space.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "octopus_space_id" {
value = var.octopus_space_id
}
38 changes: 38 additions & 0 deletions test/octopus_container_test_framework_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package test

import (
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/environments"
"github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework/octoclient"
"path/filepath"
"testing"
)

Expand Down Expand Up @@ -60,3 +64,37 @@ func TestContainerWithNoSpecifiedVersionWillUseLatest(t *testing.T) {
t.Errorf("The OctopusServer version is %v", version)
}
}

// TestCreateEnvironments is an example of the kind of tests that can be written using the OctopusContainerTest framework.
func TestCreateEnvironments(t *testing.T) {
testFramework := OctopusContainerTest{}
testFramework.ArrangeTest(t, func(t *testing.T, container *OctopusContainer, client *client.Client) error {
// Act
newSpaceId, err := testFramework.Act(
t,
container,
filepath.Join("..", "terraform"), "2-simpleexample", []string{})

if err != nil {
return err
}

newSpaceClient, err := octoclient.CreateClient(container.URI, newSpaceId, ApiKey)

if err != nil {
return err
}

testEnvironments, err := environments.GetAll(newSpaceClient, newSpaceId)

if err != nil {
return err
}

if len(testEnvironments) != 3 {
t.Fatalf("Expected 3 environments, got %d", len(testEnvironments))
}

return nil
})
}

0 comments on commit 8ce08b0

Please sign in to comment.