forked from databricks/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix locker unlock for destroy (databricks#492)
## Changes Adds ability for allowing unlock to succeed even if the deploy file is missing. ## Tests Using integration tests and manually
- Loading branch information
1 parent
4a03265
commit 5d036ab
Showing
6 changed files
with
115 additions
and
22 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
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
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"github.com/databricks/cli/libs/filer" | ||
lockpkg "github.com/databricks/cli/libs/locker" | ||
"github.com/databricks/databricks-sdk-go" | ||
"github.com/databricks/databricks-sdk-go/service/workspace" | ||
|
@@ -126,6 +127,7 @@ func TestAccLock(t *testing.T) { | |
// read active locker file | ||
r, err := lockers[indexOfActiveLocker].Read(ctx, "foo.json") | ||
require.NoError(t, err) | ||
defer r.Close() | ||
b, err := io.ReadAll(r) | ||
require.NoError(t, err) | ||
|
||
|
@@ -159,3 +161,67 @@ func TestAccLock(t *testing.T) { | |
assert.NoError(t, err) | ||
assert.True(t, lockers[indexOfAnInactiveLocker].Active) | ||
} | ||
|
||
func setupLockerTest(ctx context.Context, t *testing.T) (*lockpkg.Locker, filer.Filer) { | ||
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV")) | ||
|
||
w, err := databricks.NewWorkspaceClient() | ||
require.NoError(t, err) | ||
|
||
// create temp wsfs dir | ||
tmpDir := temporaryWorkspaceDir(t, w) | ||
f, err := filer.NewWorkspaceFilesClient(w, tmpDir) | ||
require.NoError(t, err) | ||
|
||
// create locker | ||
locker, err := lockpkg.CreateLocker("[email protected]", tmpDir, w) | ||
require.NoError(t, err) | ||
|
||
return locker, f | ||
} | ||
|
||
func TestAccLockUnlockWithoutAllowsLockFileNotExist(t *testing.T) { | ||
ctx := context.Background() | ||
locker, f := setupLockerTest(ctx, t) | ||
var err error | ||
|
||
// Acquire lock on tmp directory | ||
err = locker.Lock(ctx, false) | ||
require.NoError(t, err) | ||
|
||
// Assert lock file is created | ||
_, err = f.Stat(ctx, "deploy.lock") | ||
assert.NoError(t, err) | ||
|
||
// Manually delete lock file | ||
err = f.Delete(ctx, "deploy.lock") | ||
assert.NoError(t, err) | ||
|
||
// Assert error, because lock file does not exist | ||
err = locker.Unlock(ctx) | ||
assert.ErrorIs(t, err, fs.ErrNotExist) | ||
} | ||
|
||
func TestAccLockUnlockWithAllowsLockFileNotExist(t *testing.T) { | ||
ctx := context.Background() | ||
locker, f := setupLockerTest(ctx, t) | ||
var err error | ||
|
||
// Acquire lock on tmp directory | ||
err = locker.Lock(ctx, false) | ||
require.NoError(t, err) | ||
assert.True(t, locker.Active) | ||
|
||
// Assert lock file is created | ||
_, err = f.Stat(ctx, "deploy.lock") | ||
assert.NoError(t, err) | ||
|
||
// Manually delete lock file | ||
err = f.Delete(ctx, "deploy.lock") | ||
assert.NoError(t, err) | ||
|
||
// Assert error, because lock file does not exist | ||
err = locker.Unlock(ctx, lockpkg.AllowLockFileNotExist) | ||
assert.NoError(t, err) | ||
assert.False(t, locker.Active) | ||
} |
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