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"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2024-03-21 10:37:05 +00:00
|
|
|
func TestPythonWheelBuild(t *testing.T) {
|
2023-08-11 12:28:05 +00:00
|
|
|
ctx := context.Background()
|
2024-03-21 10:37:05 +00:00
|
|
|
b, err := bundle.Load(ctx, "./python_wheel/python_wheel")
|
2023-07-25 11:35:08 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-03-27 10:49:05 +00:00
|
|
|
diags := bundle.Apply(ctx, b, bundle.Seq(phases.Load(), 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
|
|
|
|
|
|
|
match := libraries.MatchWithArtifacts()
|
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) {
|
2023-08-11 12:28:05 +00:00
|
|
|
ctx := context.Background()
|
2024-03-21 10:37:05 +00:00
|
|
|
b, err := bundle.Load(ctx, "./python_wheel/python_wheel_no_artifact")
|
2023-07-26 10:07:26 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-03-27 10:49:05 +00:00
|
|
|
diags := bundle.Apply(ctx, b, bundle.Seq(phases.Load(), 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
|
|
|
|
|
|
|
match := libraries.MatchWithArtifacts()
|
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-03-21 10:37:05 +00:00
|
|
|
func TestPythonWheelWithDBFSLib(t *testing.T) {
|
2023-08-11 12:28:05 +00:00
|
|
|
ctx := context.Background()
|
2024-03-21 10:37:05 +00:00
|
|
|
b, err := bundle.Load(ctx, "./python_wheel/python_wheel_dbfs_lib")
|
2023-08-07 09:55:30 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-03-27 10:49:05 +00:00
|
|
|
diags := bundle.Apply(ctx, b, bundle.Seq(phases.Load(), phases.Build()))
|
2024-03-25 14:18:47 +00:00
|
|
|
require.NoError(t, diags.Error())
|
2023-08-07 09:55:30 +00:00
|
|
|
|
|
|
|
match := libraries.MatchWithArtifacts()
|
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) {
|
2023-08-28 16:29:04 +00:00
|
|
|
ctx := context.Background()
|
2024-03-21 10:37:05 +00:00
|
|
|
b, err := bundle.Load(ctx, "./python_wheel/python_wheel_no_artifact_no_setup")
|
2023-08-28 16:29:04 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-03-27 10:49:05 +00:00
|
|
|
diags := bundle.Apply(ctx, b, bundle.Seq(phases.Load(), phases.Build()))
|
2024-03-25 14:18:47 +00:00
|
|
|
require.NoError(t, diags.Error())
|
2023-08-28 16:29:04 +00:00
|
|
|
|
|
|
|
match := libraries.MatchWithArtifacts()
|
2024-03-25 14:18:47 +00:00
|
|
|
diags = bundle.Apply(ctx, b, match)
|
|
|
|
require.ErrorContains(t, diags.Error(), "./non-existing/*.whl")
|
2023-08-28 16:29:04 +00:00
|
|
|
|
|
|
|
require.NotZero(t, len(b.Config.Artifacts))
|
|
|
|
|
|
|
|
artifact := b.Config.Artifacts["my_test_code-0.0.1-py3-none-any.whl"]
|
|
|
|
require.NotNil(t, artifact)
|
|
|
|
require.Empty(t, artifact.BuildCommand)
|
2024-03-27 09:03:24 +00:00
|
|
|
require.Contains(t, artifact.Files[0].Source, filepath.Join(b.RootPath, "package",
|
2023-08-28 16:29:04 +00:00
|
|
|
"my_test_code-0.0.1-py3-none-any.whl",
|
|
|
|
))
|
|
|
|
}
|