Skip to content

Commit

Permalink
update integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
kevjt committed May 2, 2024
1 parent 9eaf344 commit f71d98b
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 15 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/OctopusDeploy/terraform-provider-octopusdeploy
go 1.21

require (
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.41.0
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.41.1
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240409225949-b27d14ff2bcb
github.com/google/uuid v1.6.0
github.com/gruntwork-io/terratest v0.41.11
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8=
github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.41.0 h1:11fXSFfz0YQ9/e4KX7v7XW99z2+Q8qgyL9Z9E195YgM=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.41.0/go.mod h1:GZmFu6LmN8Yg0tEoZx3ytk9FnaH+84cWm7u5TdWZC6E=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.41.1 h1:CpKfSXxI8HlwD6wOY4x2jpRHjQCZNssHZ5qr0HyB7PQ=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.41.1/go.mod h1:GZmFu6LmN8Yg0tEoZx3ytk9FnaH+84cWm7u5TdWZC6E=
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240409225949-b27d14ff2bcb h1:4Lzs6TsvSZkahw99VlIDP5aAihQiJZPoCQKTw1A9el4=
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240409225949-b27d14ff2bcb/go.mod h1:Nyg+7cyTrSQ/lMIy5YY1UdJekRuoMWf4uHIPfaGmgTM=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ=
Expand Down
19 changes: 15 additions & 4 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3553,18 +3553,20 @@ func TestPackageFeedCreateReleaseTriggerResources(t *testing.T) {
return err
}

if len(project_triggers) != 2 {
t.Fatal("There must be exactly 2 project triggers")
if len(project_triggers) != 3 {
t.Fatal("There must be exactly 3 project triggers")
}

tr1Name := "My first trigger"
tr2Name := "My second trigger"
tr3Name := "My third trigger"

tr1Index := stdslices.IndexFunc(project_triggers, func(t *triggers.ProjectTrigger) bool { return t.Name == tr1Name })
tr2Index := stdslices.IndexFunc(project_triggers, func(t *triggers.ProjectTrigger) bool { return t.Name == tr2Name })
tr3Index := stdslices.IndexFunc(project_triggers, func(t *triggers.ProjectTrigger) bool { return t.Name == tr3Name })

if tr1Index == -1 || tr2Index == -1 {
t.Fatalf("Unable to find both triggers. Expecting there to be \"%s\" and \"%s\".", tr1Name, tr2Name)
if tr1Index == -1 || tr2Index == -1 || tr3Index == -1 {
t.Fatalf("Unable to find all triggers. Expecting there to be \"%s\", \"%s\", and \"%s\".", tr1Name, tr2Name, tr3Name)
}

if project_triggers[0].Filter.GetFilterType() != filters.FeedFilter || project_triggers[1].Filter.GetFilterType() != filters.FeedFilter {
Expand All @@ -3579,8 +3581,13 @@ func TestPackageFeedCreateReleaseTriggerResources(t *testing.T) {
t.Fatalf("The trigger \"%s\" should be disabled", tr2Name)
}

if project_triggers[tr3Index].IsDisabled {
t.Fatalf("The trigger \"%s\" should not be disabled", tr3Name)
}

tr1Filter := project_triggers[tr1Index].Filter.(*filters.FeedTriggerFilter)
tr2Filter := project_triggers[tr2Index].Filter.(*filters.FeedTriggerFilter)
tr3Filter := project_triggers[tr3Index].Filter.(*filters.FeedTriggerFilter)

if len(tr1Filter.Packages) != 2 {
t.Fatalf("The trigger \"%s\" should have 2 package references", tr1Name)
Expand All @@ -3590,6 +3597,10 @@ func TestPackageFeedCreateReleaseTriggerResources(t *testing.T) {
t.Fatalf("The trigger \"%s\" should have 1 package reference", tr2Name)
}

if len(tr3Filter.Packages) != 3 {
t.Fatalf("The trigger \"%s\" should have 3 package reference", tr3Name)
}

return nil
})
}
Expand Down
78 changes: 78 additions & 0 deletions terraform/52-packagefeedcreatereleasetrigger/deployment_process.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,82 @@ resource "octopusdeploy_deployment_process" "example" {
}
}
}
step {
condition = "Success"
name = "Helm one"
package_requirement = "LetOctopusDecide"
start_trigger = "StartAfterPrevious"

action {
action_type = "Octopus.HelmChartUpgrade"
name = "Helm one"
condition = "Success"
run_on_server = true
is_disabled = false
can_be_used_for_project_versioning = true
is_required = false
worker_pool_id = ""
properties = {
"Octopus.Action.Helm.ClientVersion" = "V3"
"Octopus.Action.Helm.Namespace" = "dev"
"Octopus.Action.Package.DownloadOnTentacle" = "False"
"Octopus.Action.Helm.ResetValues" = "True"
}
environments = []
excluded_environments = []
channels = []
tenant_tags = []

primary_package {
package_id = "redis"
acquisition_location = "Server"
feed_id = "${octopusdeploy_helm_feed.feed_helm_charts.id}"
properties = { SelectionMode = "immediate" }
}

features = []
}

properties = {}
target_roles = ["k8s"]
}
step {
condition = "Success"
name = "Helm two"
package_requirement = "LetOctopusDecide"
start_trigger = "StartAfterPrevious"

action {
action_type = "Octopus.HelmChartUpgrade"
name = "Helm two"
condition = "Success"
run_on_server = true
is_disabled = false
can_be_used_for_project_versioning = true
is_required = false
worker_pool_id = ""
properties = {
"Octopus.Action.Helm.ClientVersion" = "V3"
"Octopus.Action.Helm.Namespace" = "dev"
"Octopus.Action.Package.DownloadOnTentacle" = "False"
"Octopus.Action.Helm.ResetValues" = "True"
}
environments = []
excluded_environments = []
channels = []
tenant_tags = []

primary_package {
package_id = "prometheus"
acquisition_location = "Server"
feed_id = "${octopusdeploy_helm_feed.feed_helm_charts.id}"
properties = { SelectionMode = "immediate" }
}

features = []
}

properties = {}
target_roles = ["k8s"]
}
}
8 changes: 7 additions & 1 deletion terraform/52-packagefeedcreatereleasetrigger/feed.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
resource "octopusdeploy_docker_container_registry" "docker_feed" {
feed_uri = "https://index.docker.io"
name = "Test Docker Container Registry"
}
}

resource "octopusdeploy_helm_feed" "feed_helm_charts" {
name = "Test Helm Charts"
feed_uri = "https://charts.helm.sh/stable"
package_acquisition_location_options = ["ExecutionTarget", "NotAcquired"]
}
18 changes: 16 additions & 2 deletions terraform/52-packagefeedcreatereleasetrigger/project.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,22 @@ resource "octopusdeploy_project_group" "project_group_test" {
description = "Test Description"
}

resource "octopusdeploy_channel" "test_channel" {
name = "Test Channel"
resource "octopusdeploy_channel" "test_channel_1" {
name = "Test Channel 1"
project_id = "${octopusdeploy_project.deploy_frontend_project.id}"
space_id = var.octopus_space_id
lifecycle_id = data.octopusdeploy_lifecycles.lifecycle_default_lifecycle.lifecycles[0].id
}

resource "octopusdeploy_channel" "test_channel_2" {
name = "Test Channel 2"
project_id = "${octopusdeploy_project.deploy_frontend_project.id}"
space_id = var.octopus_space_id
lifecycle_id = data.octopusdeploy_lifecycles.lifecycle_default_lifecycle.lifecycles[0].id
}

resource "octopusdeploy_channel" "test_channel_3" {
name = "Test Channel 3"
project_id = "${octopusdeploy_project.deploy_frontend_project.id}"
space_id = var.octopus_space_id
lifecycle_id = data.octopusdeploy_lifecycles.lifecycle_default_lifecycle.lifecycles[0].id
Expand Down
40 changes: 35 additions & 5 deletions terraform/52-packagefeedcreatereleasetrigger/project_triggers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ resource "octopusdeploy_external_feed_create_release_trigger" "external_feed_tri
space_id = var.octopus_space_id
project_id = "${octopusdeploy_project.deploy_frontend_project.id}"
package {
deployment_action = octopusdeploy_deployment_process.example.step[0].run_script_action[0].name
deployment_action_slug = "hello-world-using-powershell-1"
package_reference = "busybox"
}
package {
deployment_action = octopusdeploy_deployment_process.example.step[0].run_script_action[0].name
deployment_action_slug = "hello-world-using-powershell-1"
package_reference = "nginx"
}
channel_id = octopusdeploy_channel.test_channel.id
channel_id = octopusdeploy_channel.test_channel_1.id

depends_on = [
octopusdeploy_deployment_process.example
]
}

resource "octopusdeploy_external_feed_create_release_trigger" "external_feed_trigger_2" {
Expand All @@ -19,8 +23,34 @@ resource "octopusdeploy_external_feed_create_release_trigger" "external_feed_tri
project_id = "${octopusdeploy_project.deploy_frontend_project.id}"
is_disabled = true
package {
deployment_action = octopusdeploy_deployment_process.example.step[1].run_script_action[0].name
deployment_action_slug = "hello-world-using-powershell-2"
package_reference = "scratch"
}
channel_id = octopusdeploy_channel.test_channel.id
channel_id = octopusdeploy_channel.test_channel_2.id

depends_on = [
octopusdeploy_deployment_process.example
]
}

resource "octopusdeploy_external_feed_create_release_trigger" "external_feed_trigger_3" {
name = "My third trigger"
space_id = var.octopus_space_id
project_id = "${octopusdeploy_project.deploy_frontend_project.id}"
is_disabled = false
package {
deployment_action_slug = "hello-world-using-powershell-1"
package_reference = "busybox"
}
primary_package {
deployment_action_slug = "helm-one"
}
primary_package {
deployment_action_slug = "helm-two"
}
channel_id = octopusdeploy_channel.test_channel_3.id

depends_on = [
octopusdeploy_deployment_process.example
]
}

0 comments on commit f71d98b

Please sign in to comment.