Fix bundle destroy integration test (#1435)

I've updated the `deploy_then_remove_resources` test template in the
previous PR, but didn't notice that it was used in the destroy test too.
Now destroy test also checks deletion of jobs
This commit is contained in:
Ilia Babanov 2024-05-16 11:32:55 +02:00 committed by GitHub
parent 216d2b058a
commit 157877a152
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 2 deletions

View File

@ -6,7 +6,9 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/databricks/cli/internal"
"github.com/databricks/cli/internal/acc" "github.com/databricks/cli/internal/acc"
"github.com/databricks/cli/libs/env"
"github.com/databricks/databricks-sdk-go/apierr" "github.com/databricks/databricks-sdk-go/apierr"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -17,9 +19,12 @@ func TestAccBundleDestroy(t *testing.T) {
ctx, wt := acc.WorkspaceTest(t) ctx, wt := acc.WorkspaceTest(t)
w := wt.W w := wt.W
nodeTypeId := internal.GetNodeTypeId(env.Get(ctx, "CLOUD_ENV"))
uniqueId := uuid.New().String() uniqueId := uuid.New().String()
bundleRoot, err := initTestTemplate(t, ctx, "deploy_then_remove_resources", map[string]any{ bundleRoot, err := initTestTemplate(t, ctx, "deploy_then_remove_resources", map[string]any{
"unique_id": uniqueId, "unique_id": uniqueId,
"node_type_id": nodeTypeId,
"spark_version": defaultSparkVersion,
}) })
require.NoError(t, err) require.NoError(t, err)
@ -29,7 +34,7 @@ func TestAccBundleDestroy(t *testing.T) {
_, err = os.ReadDir(snapshotsDir) _, err = os.ReadDir(snapshotsDir)
assert.ErrorIs(t, err, os.ErrNotExist) assert.ErrorIs(t, err, os.ErrNotExist)
// deploy pipeline // deploy resources
err = deployBundle(t, ctx, bundleRoot) err = deployBundle(t, ctx, bundleRoot)
require.NoError(t, err) require.NoError(t, err)
@ -49,6 +54,12 @@ func TestAccBundleDestroy(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, pipeline.Name, pipelineName) assert.Equal(t, pipeline.Name, pipelineName)
// assert job is created
jobName := "test-bundle-job-" + uniqueId
job, err := w.Jobs.GetBySettingsName(ctx, jobName)
require.NoError(t, err)
assert.Equal(t, job.Settings.Name, jobName)
// destroy bundle // destroy bundle
err = destroyBundle(t, ctx, bundleRoot) err = destroyBundle(t, ctx, bundleRoot)
require.NoError(t, err) require.NoError(t, err)
@ -57,6 +68,10 @@ func TestAccBundleDestroy(t *testing.T) {
_, err = w.Pipelines.GetByName(ctx, pipelineName) _, err = w.Pipelines.GetByName(ctx, pipelineName)
assert.ErrorContains(t, err, "does not exist") assert.ErrorContains(t, err, "does not exist")
// assert job is deleted
_, err = w.Jobs.GetBySettingsName(ctx, jobName)
assert.ErrorContains(t, err, "does not exist")
// Assert snapshot file is deleted // Assert snapshot file is deleted
entries, err = os.ReadDir(snapshotsDir) entries, err = os.ReadDir(snapshotsDir)
require.NoError(t, err) require.NoError(t, err)