Skip to content

Commit 8ce08b0

Browse files
authored
Cleaned up go.mod, updated test containers, and added an example test (#6)
* Cleaned up go.mod, updated test containers, and added an example test * Merged changes from main * Fixed tests in workflow
1 parent f42871b commit 8ce08b0

File tree

8 files changed

+101
-2
lines changed

8 files changed

+101
-2
lines changed

.github/workflows/pr_checks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ jobs:
1818
run: go build -v ./...
1919
- name: Test
2020
run: go test ./...
21+
env:
22+
LICENSE: ${{ secrets.LICENSE }}
2123

terraform/1-singlespace/space.tf

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
resource "octopusdeploy_space" "octopus_space_test" {
2-
name = "${var.octopus_space_name}"
2+
name = var.octopus_space_name
33
is_default = false
44
is_task_queue_stopped = false
5-
description = "My test space"
5+
description = var.octopus_space_description
66
space_managers_teams = ["teams-administrators"]
77
}
88

@@ -17,3 +17,11 @@ variable "octopus_space_name" {
1717
description = "The name of the new space"
1818
default = "Test"
1919
}
20+
21+
variable "octopus_space_description" {
22+
type = string
23+
nullable = false
24+
sensitive = false
25+
description = "The description of the new space"
26+
default = "My test space"
27+
}

terraform/2-simpleexample/config.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
terraform {
2+
required_providers {
3+
octopusdeploy = { source = "OctopusDeployLabs/octopusdeploy", version = "0.21.4" }
4+
}
5+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
resource "octopusdeploy_environment" "development_environment" {
2+
allow_dynamic_infrastructure = true
3+
description = "A development environment"
4+
name = "Development"
5+
use_guided_failure = false
6+
}
7+
8+
resource "octopusdeploy_environment" "test_environment" {
9+
allow_dynamic_infrastructure = true
10+
description = "A test environment"
11+
name = "Test"
12+
use_guided_failure = false
13+
}
14+
15+
resource "octopusdeploy_environment" "production_environment" {
16+
allow_dynamic_infrastructure = true
17+
description = "A production environment"
18+
name = "Production"
19+
use_guided_failure = false
20+
}

terraform/2-simpleexample/provider.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
provider "octopusdeploy" {
2+
address = "${var.octopus_server}"
3+
api_key = "${var.octopus_apikey}"
4+
space_id = "${var.octopus_space_id}"
5+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
variable "octopus_server" {
2+
type = string
3+
nullable = false
4+
sensitive = false
5+
description = "The URL of the Octopus server e.g. https://myinstance.octopus.app."
6+
}
7+
variable "octopus_apikey" {
8+
type = string
9+
nullable = false
10+
sensitive = true
11+
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."
12+
}
13+
variable "octopus_space_id" {
14+
type = string
15+
nullable = false
16+
sensitive = false
17+
description = "The space ID to populate"
18+
}

terraform/2-simpleexample/space.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "octopus_space_id" {
2+
value = var.octopus_space_id
3+
}

test/octopus_container_test_framework_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package test
22

33
import (
4+
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
5+
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/environments"
6+
"github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework/octoclient"
7+
"path/filepath"
48
"testing"
59
)
610

@@ -60,3 +64,37 @@ func TestContainerWithNoSpecifiedVersionWillUseLatest(t *testing.T) {
6064
t.Errorf("The OctopusServer version is %v", version)
6165
}
6266
}
67+
68+
// TestCreateEnvironments is an example of the kind of tests that can be written using the OctopusContainerTest framework.
69+
func TestCreateEnvironments(t *testing.T) {
70+
testFramework := OctopusContainerTest{}
71+
testFramework.ArrangeTest(t, func(t *testing.T, container *OctopusContainer, client *client.Client) error {
72+
// Act
73+
newSpaceId, err := testFramework.Act(
74+
t,
75+
container,
76+
filepath.Join("..", "terraform"), "2-simpleexample", []string{})
77+
78+
if err != nil {
79+
return err
80+
}
81+
82+
newSpaceClient, err := octoclient.CreateClient(container.URI, newSpaceId, ApiKey)
83+
84+
if err != nil {
85+
return err
86+
}
87+
88+
testEnvironments, err := environments.GetAll(newSpaceClient, newSpaceId)
89+
90+
if err != nil {
91+
return err
92+
}
93+
94+
if len(testEnvironments) != 3 {
95+
t.Fatalf("Expected 3 environments, got %d", len(testEnvironments))
96+
}
97+
98+
return nil
99+
})
100+
}

0 commit comments

Comments
 (0)