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 4a98774
Show file tree
Hide file tree
Showing 34 changed files with 335 additions and 197 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.

2 changes: 1 addition & 1 deletion internal/framework/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (p *IonosCloudProvider) Configure(ctx context.Context, req provider.Configu
InMemoryDBClient: inmemorydb.NewInMemoryDBClient(username, password, token, cleanedEndpoint, version, terraformVersion, insecureBool),
S3Client: objectStorageService.NewClient(accessKey, secretKey, region, endpoint, insecureBool),
ObjectStorageManagementClient: objectStorageManagementService.NewClient(username, password, token, cleanedEndpoint, version, terraformVersion, insecureBool),
MonitoringClient: monitoringService.NewClient(username, password, token, cleanedEndpoint, terraformVersion, insecureBool),
MonitoringClient: monitoringService.NewClient(username, password, token, cleanedEndpoint, version, terraformVersion, insecureBool),
}

resp.DataSourceData = client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package monitoring
import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-framework-validators/datasourcevalidator"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
Expand Down
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
6 changes: 4 additions & 2 deletions internal/framework/services/monitoring/resource_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package monitoring
import (
"context"
"fmt"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
Expand All @@ -11,11 +14,10 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
monitoringSDK "github.com/ionos-cloud/sdk-go-bundle/products/monitoring/v2"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
monitoringService "github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services/monitoring"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils"
"strings"
"time"
)

var (
Expand Down
10 changes: 6 additions & 4 deletions services/monitoring/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package monitoring

import (
"fmt"
"net/http"
"runtime"

"github.com/hashicorp/terraform-plugin-sdk/v2/meta"
monitoring "github.com/ionos-cloud/sdk-go-bundle/products/monitoring/v2"
"github.com/ionos-cloud/sdk-go-bundle/shared"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils/constant"
"net/http"
"runtime"
)

// Client is a wrapper for the Monitoring SDK
Expand All @@ -17,14 +19,14 @@ type MonitoringClient struct {
}

// NewClient returns a new Monitoring client
func NewClient(username, password, token, url, terraformVersion string, insecure bool) *MonitoringClient {
func NewClient(username, password, token, url, version, terraformVersion string, insecure bool) *MonitoringClient {
config := shared.NewConfiguration(username, password, token, url)
config.MaxRetries = constant.MaxRetries
config.MaxWaitTime = constant.MaxWaitTime
config.HTTPClient = &http.Client{Transport: utils.CreateTransport(insecure)}
config.UserAgent = fmt.Sprintf(
"terraform-provider/%s_ionos-cloud-sdk-go-monitoring/%s_hashicorp-terraform/%s_terraform-plugin-sdk/%s_os/%s_arch/%s",
monitoring.Version, terraformVersion, meta.SDKVersionString(), runtime.GOOS, runtime.GOARCH) // nolint:staticcheck
version, monitoring.Version, terraformVersion, meta.SDKVersionString(), runtime.GOOS, runtime.GOARCH) // nolint:staticcheck

return &MonitoringClient{Client: *monitoring.NewAPIClient(config)}
}
8 changes: 5 additions & 3 deletions services/monitoring/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package monitoring
import (
"context"
"fmt"
"github.com/ionos-cloud/sdk-go-bundle/shared"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils/constant"
"log"
"os"
"strings"

"github.com/ionos-cloud/sdk-go-bundle/shared"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils/constant"

monitoringSDK "github.com/ionos-cloud/sdk-go-bundle/products/monitoring/v2"
)

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
}
Loading

0 comments on commit 4a98774

Please sign in to comment.