Skip to content

Commit

Permalink
Remove unused function TFStringSetToStringSlice
Browse files Browse the repository at this point in the history
  • Loading branch information
michal-futurice committed Jul 24, 2024
1 parent 6c16175 commit 08da040
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 98 deletions.
29 changes: 0 additions & 29 deletions internal/utils/terraform.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package utils

import (
"context"
"fmt"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)

// ParseUUID parses the UUID value returning a possible error as Diagnostics instead of error.
Expand All @@ -21,29 +18,3 @@ func ParseUUID(uuidString string) (uuid.UUID, diag.Diagnostics) {

return id, diags
}

// TFStringSetToStringSlice extracts strings from a string SetValue.
func TFStringSetToStringSlice(ctx context.Context, tfSet basetypes.SetValue) ([]string, diag.Diagnostics) {
var diags diag.Diagnostics

if tfSet.IsUnknown() {
return nil, diags
}

if tfSet.IsNull() {
return nil, diags
}

tfStrings := make([]types.String, 0, len(tfSet.Elements()))
diags = tfSet.ElementsAs(ctx, &tfStrings, false)
if diags.HasError() {
return nil, diags
}

strings := make([]string, len(tfStrings))
for i, tfString := range tfStrings {
strings[i] = tfString.ValueString()
}

return strings, diags
}
69 changes: 0 additions & 69 deletions internal/utils/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package utils_test

import (
"context"
"github.com/futurice/terraform-provider-dependencytrack/internal/utils"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-framework/types"
"reflect"
"testing"
)

Expand All @@ -29,69 +26,3 @@ func TestParseUUID_invalid(t *testing.T) {
t.Errorf("Error expected, but received none")
}
}

func TestTFStringSetToStringSlice_basic(t *testing.T) {
ctx := context.Background()

testStrings := []string{"a", "b"}
testSet, _ := types.SetValueFrom(ctx, types.StringType, testStrings)

result, diags := utils.TFStringSetToStringSlice(ctx, testSet)

if !reflect.DeepEqual(result, testStrings) {
t.Errorf("Parsed strings [%v] are different than expected [%v]", result, testStrings)
}

if diags.HasError() {
t.Errorf("Unexpected error: %v", diags)
}
}

func TestTFStringSetToStringSlice_empty(t *testing.T) {
ctx := context.Background()

var testStrings []string
testSet, _ := types.SetValueFrom(ctx, types.StringType, testStrings)

result, diags := utils.TFStringSetToStringSlice(ctx, testSet)

if !reflect.DeepEqual(result, testStrings) {
t.Errorf("Parsed strings [%v] are different than expected [%v]", result, testStrings)
}

if diags.HasError() {
t.Errorf("Unexpected error: %v", diags)
}
}

func TestTFStringSetToStringSlice_unknown(t *testing.T) {
ctx := context.Background()

testSet := types.SetUnknown(types.StringType)

result, diags := utils.TFStringSetToStringSlice(ctx, testSet)

if result != nil {
t.Errorf("Expected nil, got strings [%v]", result)
}

if diags.HasError() {
t.Errorf("Unexpected error: %v", diags)
}
}

func TestTFStringSetToStringSlice_null(t *testing.T) {
ctx := context.Background()

testSet := types.SetNull(types.StringType)

result, diags := utils.TFStringSetToStringSlice(ctx, testSet)

if result != nil {
t.Errorf("Expected nil, got strings [%v]", result)
}

if diags.HasError() {
t.Errorf("Unexpected error: %v", diags)
}
}

0 comments on commit 08da040

Please sign in to comment.