mirror of https://github.com/databricks/cli.git
Function to return bundle's cache directory (#109)
Parallel of `project.CacheDir()` introduced in https://github.com/databricks/bricks/pull/82.
This commit is contained in:
parent
e1669b0352
commit
4064a21797
|
@ -1,6 +1,7 @@
|
||||||
package bundle
|
package bundle
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -49,3 +50,22 @@ func (b *Bundle) WorkspaceClient() *databricks.WorkspaceClient {
|
||||||
})
|
})
|
||||||
return b.client
|
return b.client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cacheDirName = filepath.Join(".databricks", "bundle")
|
||||||
|
|
||||||
|
// CacheDir returns directory to use for temporary files for this bundle.
|
||||||
|
// Scoped to the bundle's environment.
|
||||||
|
func (b *Bundle) CacheDir() (string, error) {
|
||||||
|
if b.Config.Bundle.Environment == "" {
|
||||||
|
panic("environment not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make directory if it doesn't exist yet.
|
||||||
|
dir := filepath.Join(b.Config.Path, cacheDirName, b.Config.Bundle.Environment)
|
||||||
|
err := os.MkdirAll(dir, 0700)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return dir, nil
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package bundle
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -19,3 +21,21 @@ func TestLoadExists(t *testing.T) {
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.Equal(t, "basic", b.Config.Bundle.Name)
|
assert.Equal(t, "basic", b.Config.Bundle.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBundleCacheDir(t *testing.T) {
|
||||||
|
projectDir := t.TempDir()
|
||||||
|
f1, err := os.Create(filepath.Join(projectDir, "bundle.yml"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
f1.Close()
|
||||||
|
|
||||||
|
bundle, err := Load(projectDir)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Artificially set environment.
|
||||||
|
// This is otherwise done by [mutators.SelectEnvironment].
|
||||||
|
bundle.Config.Bundle.Environment = "default"
|
||||||
|
|
||||||
|
cacheDir, err := bundle.CacheDir()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.True(t, strings.HasPrefix(cacheDir, projectDir))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue