Skip to content

Commit

Permalink
Test resource init errors during update (#2776)
Browse files Browse the repository at this point in the history
This adds an integration test for resourceInitErrors during `Update`.
Similar to the `Create` test in
#2713

fixes #2772
  • Loading branch information
VenelinMartinov authored Dec 19, 2024
1 parent 5c9f559 commit 662d3af
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions pkg/tests/schema_pulumi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,58 @@ resources:
require.Len(t, initErrors, 1)
require.Contains(t, initErrors[0], "INIT TEST ERROR")
}

func TestUpdateResourceInitFailure(t *testing.T) {
t.Parallel()

resMap := map[string]*schema.Resource{
"prov_test": {
Schema: map[string]*schema.Schema{
"test": {
Type: schema.TypeString,
Required: true,
},
},
UpdateContext: func(ctx context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics {
return diag.Errorf("UPDATE TEST ERROR")
},
},
}
prov := &schema.Provider{ResourcesMap: resMap}
bridgedProvider := pulcheck.BridgedProvider(t, "prov", prov)

program := `
name: test
runtime: yaml
resources:
mainRes:
type: prov:index:Test
properties:
test: %s
`

pt := pulcheck.PulCheck(t, bridgedProvider, fmt.Sprintf(program, "hello"))
pt.Up(t)
pt.WritePulumiYaml(t, fmt.Sprintf(program, "hello2"))

_, err := pt.CurrentStack().Up(pt.Context())
require.Error(t, err)
require.ErrorContains(t, err, "UPDATE TEST ERROR")

stack := pt.ExportStack(t)

data, err := stack.Deployment.MarshalJSON()
require.NoError(t, err)

var stateMap map[string]interface{}
err = json.Unmarshal(data, &stateMap)
require.NoError(t, err)

resourcesList := stateMap["resources"].([]interface{})
// stack, provider, resource
require.Len(t, resourcesList, 3)
mainResState := resourcesList[2].(map[string]interface{})
initErrors := mainResState["initErrors"].([]interface{})
require.Len(t, initErrors, 1)
require.Contains(t, initErrors[0], "UPDATE TEST ERROR")
}

0 comments on commit 662d3af

Please sign in to comment.