Skip to content

Commit

Permalink
Add a test that asserts write-only fields are correctly decoded into …
Browse files Browse the repository at this point in the history
…ProviderSchemas structs
  • Loading branch information
SarahFrench committed Dec 11, 2024
1 parent 2c0964a commit 8091174
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions schemas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,26 @@ func TestProviderSchemasValidate(t *testing.T) {
})
}
}

// TestProviderSchemas_writeOnlyAttribute asserts that write-only attributes in a resource in a
// provider schema JSON file are marked as WriteOnly once decoded into a ProviderSchemas struct
func TestProviderSchemas_writeOnlyAttribute(t *testing.T) {
f, err := os.Open("testdata/write_only_attribute_on_resource/schemas.json")
if err != nil {
t.Fatal(err)
}
defer f.Close()

var schemas *ProviderSchemas
if err := json.NewDecoder(f).Decode(&schemas); err != nil {
t.Fatal(err)
}

resourceSchema := schemas.Schemas["terraform.io/builtin/terraform"].ResourceSchemas["terraform_example"]
if resourceSchema.Block.Attributes["wo_attr"].WriteOnly != true {
t.Fatal("expected terraform_example.wo_attr to be marked as write-only")
}
if resourceSchema.Block.Attributes["foo"].WriteOnly != false {
t.Fatal("expected terraform_example.foo to not be marked as write-only")
}
}

0 comments on commit 8091174

Please sign in to comment.