Skip to content

Commit

Permalink
Add test for data source
Browse files Browse the repository at this point in the history
  • Loading branch information
tleed5 committed May 7, 2024
1 parent 40f5e9f commit cfe976f
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 0 deletions.
41 changes: 41 additions & 0 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3801,3 +3801,44 @@ func TestKubernetesDeploymentTargetResource(t *testing.T) {
return nil
})
}

func TestKubernetesDeploymentTargetData(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", "55-kubernetesagentdeploymenttarget", []string{})

if err != nil {
return err
}

err = testFramework.TerraformInitAndApply(t, container, filepath.Join("./terraform", "55a-kubernetesagentdeploymenttargetds"), newSpaceId, []string{})

// Assert
client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey)
query := machines.MachinesQuery{
DeploymentTargetTypes: []string{"KubernetesTentacle"},
PartialName: "minimum-agent",
Skip: 0,
Take: 1,
}

resources, err := machines.Get(client, newSpaceId, query)
if err != nil {
return err
}

var foundAgent = resources.Items[0]

lookup, err := testFramework.GetOutputVariable(t, filepath.Join("terraform", "55a-kubernetesagentdeploymenttargetds"), "data_lookup")
if err != nil {
return err
}

if lookup != foundAgent.ID {
t.Fatal("The target lookup did not succeed. Lookup value was \"" + lookup + "\" while the resource value was \"" + foundAgent.ID + "\".")
}

return nil
})
}
5 changes: 5 additions & 0 deletions terraform/55a-kubernetesagentdeploymenttargetds/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.18.1" }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
data "octopusdeploy_kubernetes_agent_deployment_targets" "test" {
take = 1
skip = 0
partial_name = "minimum-agent"
}

output "data_lookup" {
value = data.octopusdeploy_kubernetes_agent_deployment_targets.test.kubernetes_agent_deployment_targets[0].id
}
5 changes: 5 additions & 0 deletions terraform/55a-kubernetesagentdeploymenttargetds/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/55a-kubernetesagentdeploymenttargetds/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/55a-kubernetesagentdeploymenttargetds/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
}

0 comments on commit cfe976f

Please sign in to comment.