Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: mark invalid UUIDs as known#148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ethanndickson merged 2 commits intomainfromethan/uuid-fix
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletionsinternal/provider/user_data_source_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -57,6 +57,7 @@ func TestAccUserDataSource(t *testing.T) {
Username: ptr.Ref(user.Username),
}
resource.Test(t, resource.TestCase{
IsUnitTest: true,
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
Expand All@@ -75,6 +76,7 @@ func TestAccUserDataSource(t *testing.T) {
ID: ptr.Ref(user.ID.String()),
}
resource.Test(t, resource.TestCase{
IsUnitTest: true,
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
// User by ID
Expand All@@ -92,6 +94,7 @@ func TestAccUserDataSource(t *testing.T) {
Token: client.SessionToken(),
}
resource.Test(t, resource.TestCase{
IsUnitTest: true,
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
// Neither ID nor Username
Expand All@@ -104,6 +107,24 @@ func TestAccUserDataSource(t *testing.T) {
})
})

t.Run("InvalidUUIDError", func(t *testing.T) {
cfg := testAccUserDataSourceConfig{
URL: client.URL.String(),
Token: client.SessionToken(),
ID: ptr.Ref("invalid-uuid"),
}
resource.Test(t, resource.TestCase{
IsUnitTest: true,
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: cfg.String(t),
ExpectError: regexp.MustCompile(`The provided value cannot be parsed as a UUID`),
},
},
})
})
}

type testAccUserDataSourceConfig struct {
Expand Down
20 changes: 10 additions & 10 deletionsinternal/provider/uuid.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,16 +48,16 @@ func (t uuidType) ValueFromString(ctx context.Context, in basetypes.StringValue)
return NewUUIDUnknown(), diags
}

value, err := uuid.Parse(in.ValueString())
if err != nil {
//The framework doesn't want us to return validation errors here
//for some reason. They get caught by `ValidateAttribute` instead,
//and this function isn't called directly by our provider - UUIDValue
// takes a valid UUID instead of a string.
returnNewUUIDUnknown(), diags
}

return UUIDValue(value), diags
// This function deliberately does not handle invalid UUIDs.
// Instead, `ValidateAttribute` will be called
//on the stored string during `validate` `plan` and `apply`,
//which will also create an error diagnostic.
//For that reason, storing the zero UUID is fine.
v, _ := uuid.Parse(in.ValueString())
returnUUID{
StringValue: in,
value: v,
}, diags
}

// ValueFromTerraform implements basetypes.StringTypable.
Expand Down
10 changes: 7 additions & 3 deletionsinternal/provider/uuid_internal_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,7 @@ import (
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/hashicorp/terraform-plugin-go/tftypes"
"github.com/stretchr/testify/require"
)
Expand DownExpand Up@@ -37,9 +38,12 @@ func TestUUIDTypeValueFromTerraform(t *testing.T) {
expected: UUIDValue(ValidUUID),
},
{
name: "invalid UUID",
input: tftypes.NewValue(tftypes.String, "invalid"),
expected: NewUUIDUnknown(),
name: "invalid UUID",
input: tftypes.NewValue(tftypes.String, "invalid"),
expected: UUID{
StringValue: basetypes.NewStringValue("invalid"),
value: uuid.Nil,
},
},
}

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp