Skip to content

Commit

Permalink
Ensure all sdkv2 test providers have an id and an update method
Browse files Browse the repository at this point in the history
  • Loading branch information
VenelinMartinov committed Dec 12, 2024
1 parent 3a2e7a4 commit a350c93
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pkg/internal/tests/pulcheck/pulcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ func resourceNeedsUpdate(res *schema.Resource) bool {
// This is an experimental API.
func EnsureProviderValid(t T, tfp *schema.Provider) {
for _, r := range tfp.ResourcesMap {
if r.Schema["id"] == nil {
r.Schema["id"] = &schema.Schema{
Type: schema.TypeString,
Computed: true,
}
}

if !resourceNeedsUpdate(r) {
r.Schema["update_prop"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
}
}

if r.ReadContext == nil {
r.ReadContext = func(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
return nil
Expand All @@ -75,7 +89,7 @@ func EnsureProviderValid(t T, tfp *schema.Provider) {
}
}

if resourceNeedsUpdate(r) && r.UpdateContext == nil {
if r.UpdateContext == nil {
r.UpdateContext = func(
ctx context.Context, rd *schema.ResourceData, i interface{},
) diag.Diagnostics {
Expand Down

0 comments on commit a350c93

Please sign in to comment.