Skip to content

Commit

Permalink
test: Add final tests, use generated SDK instead of the local one
Browse files Browse the repository at this point in the history
  • Loading branch information
adeatcu-ionos committed Dec 18, 2024
1 parent 70563a8 commit 4a50080
Show file tree
Hide file tree
Showing 29 changed files with 318 additions and 187 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module github.com/ionos-cloud/terraform-provider-ionoscloud/v6

go 1.22.0

replace github.com/ionos-cloud/sdk-go-bundle/products/monitoring/v2 => ./../sdks/generated_locally/go-monitoring

require (
github.com/aws/aws-sdk-go v1.55.5
github.com/cenkalti/backoff/v4 v4.3.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ github.com/ionos-cloud/sdk-go-bundle/products/cdn/v2 v2.1.0 h1:8fRICa4i+GJHrCgnL
github.com/ionos-cloud/sdk-go-bundle/products/cdn/v2 v2.1.0/go.mod h1:BF6R+j1GdJEMImxkeh32qjIVWqsBfgi6VgyfsY5ezIA=
github.com/ionos-cloud/sdk-go-bundle/products/logging/v2 v2.1.1 h1:GXxdNKl7haQnHO1QewZeXazur5+LDCpHqvP+nNObGaA=
github.com/ionos-cloud/sdk-go-bundle/products/logging/v2 v2.1.1/go.mod h1:N0ifRq3ENqGg6qht1WPrVgSkcavPS5SRWlNfkHUZbfQ=
github.com/ionos-cloud/sdk-go-bundle/products/monitoring/v2 v2.0.0 h1:gVh+jd0o8ROtJLWqUB6/VU8vSLdj/kRYAz/qbMO7z7I=
github.com/ionos-cloud/sdk-go-bundle/products/monitoring/v2 v2.0.0/go.mod h1:PRdc/x/r7tMEV7rh2uZYJ8ososjfIF/cXiGX/D6FdTs=
github.com/ionos-cloud/sdk-go-bundle/products/vpn/v2 v2.0.2 h1:qR/ul88v/3ZF+ZLFFv6LE9TrjZS1qM4R10UlXCaQzcs=
github.com/ionos-cloud/sdk-go-bundle/products/vpn/v2 v2.0.2/go.mod h1:V6WHbWsQDlZsLtHqgsXO81Z9eJBsczE3Q6VY8J+rutc=
github.com/ionos-cloud/sdk-go-bundle/shared v0.1.1 h1:NWobgIhmUJKG6ohFXefMj+KmpEEvLYEDUgGzpns6HQE=
Expand Down
16 changes: 0 additions & 16 deletions internal/errs/must.go

This file was deleted.

74 changes: 74 additions & 0 deletions internal/framework/services/monitoring/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package monitoring_test
import (
"context"
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand All @@ -28,6 +29,7 @@ func TestAccPipeline(t *testing.T) {
resource.TestCheckResourceAttr("ionoscloud_monitoring_pipeline.test", "name", "TFTestPipeline"),
resource.TestCheckResourceAttrSet("ionoscloud_monitoring_pipeline.test", "grafana_endpoint"),
resource.TestCheckResourceAttrSet("ionoscloud_monitoring_pipeline.test", "http_endpoint"),
resource.TestCheckResourceAttrSet("ionoscloud_monitoring_pipeline.test", "key"),
),
},
{
Expand All @@ -48,6 +50,36 @@ func TestAccPipeline(t *testing.T) {
resource.TestCheckResourceAttrSet("data.ionoscloud_monitoring_pipeline.test", "http_endpoint"),
),
},
{
Config: invalidDSConfigBothNameID,
ExpectError: regexp.MustCompile("Invalid Attribute Combination"),
},
{
Config: invalidDSConfigNoNameNoID,
ExpectError: regexp.MustCompile("Missing Attribute Configuration"),
},
{
Config: invalidDSConfigMultipleOccurrences,
ExpectError: regexp.MustCompile("multiple Monitoring pipelines found with the same name"),
},
{
Config: invalidDSConfigInvalidName,
ExpectError: regexp.MustCompile("no Monitoring pipeline found with the specified name"),
},
{
Config: invalidDSConfigInvalidID,
ExpectError: regexp.MustCompile("failed to get Monitoring pipeline"),
},
{
Config: pipelineBasicUpdateConfig,
Check: resource.ComposeTestCheckFunc(
checkPipelineExists(context.Background(), "ionoscloud_monitoring_pipeline.test"),
resource.TestCheckResourceAttr("ionoscloud_monitoring_pipeline.test", "name", "updatedTestName"),
resource.TestCheckResourceAttrSet("ionoscloud_monitoring_pipeline.test", "grafana_endpoint"),
resource.TestCheckResourceAttrSet("ionoscloud_monitoring_pipeline.test", "http_endpoint"),
resource.TestCheckResourceAttrSet("ionoscloud_monitoring_pipeline.test", "key"),
),
},
},
})
}
Expand All @@ -59,6 +91,12 @@ const (
}
`

pipelineBasicUpdateConfig = `
resource "ionoscloud_monitoring_pipeline" "test" {
name = "updatedTestName"
}
`

dataSourceByName = pipelineBasicConfig + `
data "ionoscloud_monitoring_pipeline" "test" {
name = ionoscloud_monitoring_pipeline.test.name
Expand All @@ -70,6 +108,42 @@ const (
id = ionoscloud_monitoring_pipeline.test.id
}
`

invalidDSConfigBothNameID = pipelineBasicConfig + `
data "ionoscloud_monitoring_pipeline" "test" {
id = ionoscloud_monitoring_pipeline.test.id
name = ionoscloud_monitoring_pipeline.test.name
}
`

invalidDSConfigNoNameNoID = pipelineBasicConfig + `
data "ionoscloud_monitoring_pipeline" "test" {
}
`

// This works because we can create two pipelines with the same name
invalidDSConfigMultipleOccurrences = pipelineBasicConfig + `
resource "ionoscloud_monitoring_pipeline" "secondPipeline" {
name = "TFTestPipeline"
}
data "ionoscloud_monitoring_pipeline" "test" {
name = ionoscloud_monitoring_pipeline.test.name
}
`

invalidDSConfigInvalidName = pipelineBasicConfig + `
data "ionoscloud_monitoring_pipeline" "test" {
name = "itdoesntexist"
}
`

invalidDSConfigInvalidID = pipelineBasicConfig + `
data "ionoscloud_monitoring_pipeline" "test" {
id = "itdoesntexist"
}
`
)

func checkPipelineExists(ctx context.Context, accessPath string) resource.TestCheckFunc {
Expand Down
9 changes: 0 additions & 9 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,3 @@ func CleanURL(url string) string {

return url
}

// ConcatenateLists concatenates multiple lists into one list.
func ConcatenateLists(lists ...[]any) []any {
var result []any
for _, list := range lists {
result = append(result, list...)
}
return result
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4a50080

Please sign in to comment.