diff --git a/internal/utils/terraform.go b/internal/utils/terraform.go index dc36d9e..08b2b4e 100644 --- a/internal/utils/terraform.go +++ b/internal/utils/terraform.go @@ -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. @@ -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 -} diff --git a/internal/utils/utils_test.go b/internal/utils/utils_test.go index 38c56c8..eedb497 100644 --- a/internal/utils/utils_test.go +++ b/internal/utils/utils_test.go @@ -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" ) @@ -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) - } -}