-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup remote file path on bundle destroy (#1374)
## Changes The sync struct initialization would recreate the deleted `file_path`. This PR moves to not initializing the sync object to delete the snapshot, thus fixing the lingering `file_path` after `bundle destroy`. ## Tests Manually, and a integration test to prevent regression.
- Loading branch information
1 parent
f6c4d6d
commit e008c2b
Showing
4 changed files
with
89 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package bundle | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/databricks/cli/internal/acc" | ||
"github.com/databricks/databricks-sdk-go/apierr" | ||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAccBundleDestroy(t *testing.T) { | ||
ctx, wt := acc.WorkspaceTest(t) | ||
w := wt.W | ||
|
||
uniqueId := uuid.New().String() | ||
bundleRoot, err := initTestTemplate(t, ctx, "deploy_then_remove_resources", map[string]any{ | ||
"unique_id": uniqueId, | ||
}) | ||
require.NoError(t, err) | ||
|
||
snapshotsDir := filepath.Join(bundleRoot, ".databricks", "bundle", "default", "sync-snapshots") | ||
|
||
// Assert the snapshot file does not exist | ||
_, err = os.ReadDir(snapshotsDir) | ||
assert.ErrorIs(t, err, os.ErrNotExist) | ||
|
||
// deploy pipeline | ||
err = deployBundle(t, ctx, bundleRoot) | ||
require.NoError(t, err) | ||
|
||
// Assert the snapshot file exists | ||
entries, err := os.ReadDir(snapshotsDir) | ||
assert.NoError(t, err) | ||
assert.Len(t, entries, 1) | ||
|
||
// Assert bundle deployment path is created | ||
remoteRoot := getBundleRemoteRootPath(w, t, uniqueId) | ||
_, err = w.Workspace.GetStatusByPath(ctx, remoteRoot) | ||
assert.NoError(t, err) | ||
|
||
// assert pipeline is created | ||
pipelineName := "test-bundle-pipeline-" + uniqueId | ||
pipeline, err := w.Pipelines.GetByName(ctx, pipelineName) | ||
require.NoError(t, err) | ||
assert.Equal(t, pipeline.Name, pipelineName) | ||
|
||
// destroy bundle | ||
err = destroyBundle(t, ctx, bundleRoot) | ||
require.NoError(t, err) | ||
|
||
// assert pipeline is deleted | ||
_, err = w.Pipelines.GetByName(ctx, pipelineName) | ||
assert.ErrorContains(t, err, "does not exist") | ||
|
||
// Assert snapshot file is deleted | ||
entries, err = os.ReadDir(snapshotsDir) | ||
require.NoError(t, err) | ||
assert.Len(t, entries, 0) | ||
|
||
// Assert bundle deployment path is deleted | ||
_, err = w.Workspace.GetStatusByPath(ctx, remoteRoot) | ||
apiErr := &apierr.APIError{} | ||
assert.True(t, errors.As(err, &apiErr)) | ||
assert.Equal(t, "RESOURCE_DOES_NOT_EXIST", apiErr.ErrorCode) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters