2024-03-21 10:37:05 +00:00
|
|
|
package config_tests
|
2023-07-25 11:35:08 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-07-26 09:02:17 +00:00
|
|
|
"path/filepath"
|
2023-07-25 11:35:08 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/bundle"
|
2023-08-07 09:55:30 +00:00
|
|
|
"github.com/databricks/cli/bundle/libraries"
|
2023-07-25 11:35:08 +00:00
|
|
|
"github.com/databricks/cli/bundle/phases"
|
2024-08-14 09:03:44 +00:00
|
|
|
mockfiler "github.com/databricks/cli/internal/mocks/libs/filer"
|
|
|
|
"github.com/databricks/cli/libs/filer"
|
|
|
|
"github.com/stretchr/testify/mock"
|
2023-07-25 11:35:08 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2024-03-21 10:37:05 +00:00
|
|
|
func TestPythonWheelBuild(t *testing.T) {
|
2024-09-09 09:56:16 +00:00
|
|
|
b := loadTarget(t, "./python_wheel/python_wheel", "default")
|
2023-07-25 11:35:08 +00:00
|
|
|
|
2024-09-09 09:56:16 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
diags := bundle.Apply(ctx, b, phases.Build())
|
2024-03-25 14:18:47 +00:00
|
|
|
require.NoError(t, diags.Error())
|
2023-07-25 11:35:08 +00:00
|
|
|
|
2024-03-21 10:37:05 +00:00
|
|
|
matches, err := filepath.Glob("./python_wheel/python_wheel/my_test_code/dist/my_test_code-*.whl")
|
2023-07-25 11:35:08 +00:00
|
|
|
require.NoError(t, err)
|
2023-07-26 09:02:17 +00:00
|
|
|
require.Equal(t, 1, len(matches))
|
2023-08-07 09:55:30 +00:00
|
|
|
|
2024-08-14 09:03:44 +00:00
|
|
|
match := libraries.ExpandGlobReferences()
|
2024-03-25 14:18:47 +00:00
|
|
|
diags = bundle.Apply(ctx, b, match)
|
|
|
|
require.NoError(t, diags.Error())
|
2023-07-25 11:35:08 +00:00
|
|
|
}
|
2023-07-26 10:07:26 +00:00
|
|
|
|
2024-03-21 10:37:05 +00:00
|
|
|
func TestPythonWheelBuildAutoDetect(t *testing.T) {
|
2024-09-09 09:56:16 +00:00
|
|
|
b := loadTarget(t, "./python_wheel/python_wheel_no_artifact", "default")
|
2023-07-26 10:07:26 +00:00
|
|
|
|
2024-09-09 09:56:16 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
diags := bundle.Apply(ctx, b, phases.Build())
|
2024-03-25 14:18:47 +00:00
|
|
|
require.NoError(t, diags.Error())
|
2023-07-26 10:07:26 +00:00
|
|
|
|
2024-03-21 10:37:05 +00:00
|
|
|
matches, err := filepath.Glob("./python_wheel/python_wheel_no_artifact/dist/my_test_code-*.whl")
|
2023-07-26 10:07:26 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 1, len(matches))
|
2023-08-07 09:55:30 +00:00
|
|
|
|
2024-08-14 09:03:44 +00:00
|
|
|
match := libraries.ExpandGlobReferences()
|
2024-03-25 14:18:47 +00:00
|
|
|
diags = bundle.Apply(ctx, b, match)
|
|
|
|
require.NoError(t, diags.Error())
|
2023-08-07 09:55:30 +00:00
|
|
|
}
|
|
|
|
|
2024-08-05 14:44:23 +00:00
|
|
|
func TestPythonWheelBuildAutoDetectWithNotebookTask(t *testing.T) {
|
2024-09-09 09:56:16 +00:00
|
|
|
b := loadTarget(t, "./python_wheel/python_wheel_no_artifact_notebook", "default")
|
2024-08-05 14:44:23 +00:00
|
|
|
|
2024-09-09 09:56:16 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
diags := bundle.Apply(ctx, b, phases.Build())
|
2024-08-05 14:44:23 +00:00
|
|
|
require.NoError(t, diags.Error())
|
|
|
|
|
|
|
|
matches, err := filepath.Glob("./python_wheel/python_wheel_no_artifact_notebook/dist/my_test_code-*.whl")
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 1, len(matches))
|
|
|
|
|
2024-08-14 09:03:44 +00:00
|
|
|
match := libraries.ExpandGlobReferences()
|
2024-08-05 14:44:23 +00:00
|
|
|
diags = bundle.Apply(ctx, b, match)
|
|
|
|
require.NoError(t, diags.Error())
|
|
|
|
}
|
|
|
|
|
2024-03-21 10:37:05 +00:00
|
|
|
func TestPythonWheelWithDBFSLib(t *testing.T) {
|
2024-09-09 09:56:16 +00:00
|
|
|
b := loadTarget(t, "./python_wheel/python_wheel_dbfs_lib", "default")
|
2023-08-07 09:55:30 +00:00
|
|
|
|
2024-09-09 09:56:16 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
diags := bundle.Apply(ctx, b, phases.Build())
|
2024-03-25 14:18:47 +00:00
|
|
|
require.NoError(t, diags.Error())
|
2023-08-07 09:55:30 +00:00
|
|
|
|
2024-08-14 09:03:44 +00:00
|
|
|
match := libraries.ExpandGlobReferences()
|
2024-03-25 14:18:47 +00:00
|
|
|
diags = bundle.Apply(ctx, b, match)
|
|
|
|
require.NoError(t, diags.Error())
|
2023-07-26 10:07:26 +00:00
|
|
|
}
|
2023-08-28 16:29:04 +00:00
|
|
|
|
2024-03-21 10:37:05 +00:00
|
|
|
func TestPythonWheelBuildNoBuildJustUpload(t *testing.T) {
|
2024-09-09 09:56:16 +00:00
|
|
|
b := loadTarget(t, "./python_wheel/python_wheel_no_artifact_no_setup", "default")
|
2023-08-28 16:29:04 +00:00
|
|
|
|
2024-09-09 09:56:16 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
diags := bundle.Apply(ctx, b, phases.Build())
|
|
|
|
require.NoError(t, diags.Error())
|
2023-08-28 16:29:04 +00:00
|
|
|
|
2024-08-14 09:03:44 +00:00
|
|
|
mockFiler := mockfiler.NewMockFiler(t)
|
|
|
|
mockFiler.EXPECT().Write(
|
|
|
|
mock.Anything,
|
|
|
|
filepath.Join("my_test_code-0.0.1-py3-none-any.whl"),
|
|
|
|
mock.AnythingOfType("*os.File"),
|
|
|
|
filer.OverwriteIfExists,
|
|
|
|
filer.CreateParentDirectories,
|
|
|
|
).Return(nil)
|
2023-08-28 16:29:04 +00:00
|
|
|
|
2024-09-09 09:56:16 +00:00
|
|
|
diags = bundle.Apply(ctx, b, bundle.Seq(
|
|
|
|
libraries.ExpandGlobReferences(),
|
|
|
|
libraries.UploadWithClient(mockFiler),
|
|
|
|
))
|
2024-08-14 09:03:44 +00:00
|
|
|
require.NoError(t, diags.Error())
|
|
|
|
require.Empty(t, diags)
|
|
|
|
require.Equal(t, "/Workspace/foo/bar/.internal/my_test_code-0.0.1-py3-none-any.whl", b.Config.Resources.Jobs["test_job"].JobSettings.Tasks[0].Libraries[0].Whl)
|
2023-08-28 16:29:04 +00:00
|
|
|
}
|
2024-04-22 11:44:34 +00:00
|
|
|
|
|
|
|
func TestPythonWheelBuildWithEnvironmentKey(t *testing.T) {
|
2024-09-09 09:56:16 +00:00
|
|
|
b := loadTarget(t, "./python_wheel/environment_key", "default")
|
2024-04-22 11:44:34 +00:00
|
|
|
|
2024-09-09 09:56:16 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
diags := bundle.Apply(ctx, b, phases.Build())
|
2024-04-22 11:44:34 +00:00
|
|
|
require.NoError(t, diags.Error())
|
|
|
|
|
|
|
|
matches, err := filepath.Glob("./python_wheel/environment_key/my_test_code/dist/my_test_code-*.whl")
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 1, len(matches))
|
|
|
|
|
2024-08-14 09:03:44 +00:00
|
|
|
match := libraries.ExpandGlobReferences()
|
2024-04-22 11:44:34 +00:00
|
|
|
diags = bundle.Apply(ctx, b, match)
|
|
|
|
require.NoError(t, diags.Error())
|
|
|
|
}
|
2024-07-24 09:13:49 +00:00
|
|
|
|
|
|
|
func TestPythonWheelBuildMultiple(t *testing.T) {
|
2024-09-09 09:56:16 +00:00
|
|
|
b := loadTarget(t, "./python_wheel/python_wheel_multiple", "default")
|
2024-07-24 09:13:49 +00:00
|
|
|
|
2024-09-09 09:56:16 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
diags := bundle.Apply(ctx, b, phases.Build())
|
2024-07-24 09:13:49 +00:00
|
|
|
require.NoError(t, diags.Error())
|
|
|
|
|
|
|
|
matches, err := filepath.Glob("./python_wheel/python_wheel_multiple/my_test_code/dist/my_test_code*.whl")
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 2, len(matches))
|
|
|
|
|
2024-08-14 09:03:44 +00:00
|
|
|
match := libraries.ExpandGlobReferences()
|
2024-07-24 09:13:49 +00:00
|
|
|
diags = bundle.Apply(ctx, b, match)
|
|
|
|
require.NoError(t, diags.Error())
|
|
|
|
}
|
2024-08-06 09:54:58 +00:00
|
|
|
|
|
|
|
func TestPythonWheelNoBuild(t *testing.T) {
|
2024-09-09 09:56:16 +00:00
|
|
|
b := loadTarget(t, "./python_wheel/python_wheel_no_build", "default")
|
2024-08-06 09:54:58 +00:00
|
|
|
|
2024-09-09 09:56:16 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
diags := bundle.Apply(ctx, b, phases.Build())
|
2024-08-06 09:54:58 +00:00
|
|
|
require.NoError(t, diags.Error())
|
|
|
|
|
2024-08-14 09:03:44 +00:00
|
|
|
match := libraries.ExpandGlobReferences()
|
2024-08-06 09:54:58 +00:00
|
|
|
diags = bundle.Apply(ctx, b, match)
|
|
|
|
require.NoError(t, diags.Error())
|
|
|
|
}
|