Skip to content

Commit

Permalink
fix: Allow empty result when looking for storage integration on refre…
Browse files Browse the repository at this point in the history
…sh (#692)
  • Loading branch information
bneijt committed Nov 30, 2021
1 parent 5fefd92 commit 16363cf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/resources/storage_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ func ReadStorageIntegration(d *schema.ResourceData, meta interface{}) error {
// Some properties can come from the SHOW INTEGRATION call

s, err := snowflake.ScanStorageIntegration(row)
if err == sql.ErrNoRows {
// If not found, mark resource to be removed from statefile during apply or refresh
log.Printf("[DEBUG] storage integration (%s) not found", d.Id())
d.SetId("")
return nil
}
if err != nil {
return fmt.Errorf("Could not show storage integration: %w", err)
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/resources/storage_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ func TestStorageIntegrationRead(t *testing.T) {
})
}

func TestStorageIntegrationReadEmpty(t *testing.T) {
r := require.New(t)

d := storageIntegration(t, "test_storage_integration", map[string]interface{}{"name": "not_existing_storage_integration"})

WithMockDb(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
expectReadStorageIntegrationEmpty(mock)

err := resources.ReadStorageIntegration(d, db)
r.Nil(err)
})
}

func TestStorageIntegrationUpdate(t *testing.T) {
r := require.New(t)

Expand Down Expand Up @@ -134,3 +147,10 @@ func expectReadStorageIntegrationForGCS(mock sqlmock.Sqlmock) {

mock.ExpectQuery(`DESCRIBE STORAGE INTEGRATION "test_storage_integration"$`).WillReturnRows(descRows)
}

func expectReadStorageIntegrationEmpty(mock sqlmock.Sqlmock) {
noRows := sqlmock.NewRows([]string{
"name", "type", "category", "enabled", "created_on"},
)
mock.ExpectQuery(`^SHOW STORAGE INTEGRATIONS.*`).WillReturnRows(noRows)
}

0 comments on commit 16363cf

Please sign in to comment.