Skip to content

Commit

Permalink
Add diagnosticsToString function to convert diag.Diagnostics to string
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro J. Nuñez Madrazo <[email protected]>
  • Loading branch information
alejandrojnm committed Jan 27, 2024
1 parent 0c6eb31 commit 93b7212
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions civo/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package civo

import (
"context"
"strings"

"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestProvider(t *testing.T) {
if err := Provider().InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
t.Fatalf("err: %s", err.Error())
}
}

Expand All @@ -27,6 +29,15 @@ func TestToken(t *testing.T) {

diags := rawProvider.Configure(context.Background(), terraform.NewResourceConfigRaw(raw))
if diags.HasError() {
t.Fatalf("provider configure failed: %s", diags)
t.Fatalf("provider configure failed: %s", diagnosticsToString(diags))
}
}

func diagnosticsToString(diags diag.Diagnostics) string {
diagsAsStrings := make([]string, len(diags))
for i, diag := range diags {
diagsAsStrings[i] = diag.Summary
}

return strings.Join(diagsAsStrings, "; ")
}

0 comments on commit 93b7212

Please sign in to comment.