2023-08-07 13:14:25 +00:00
|
|
|
package bundle
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-12-27 12:03:08 +00:00
|
|
|
"github.com/databricks/cli/libs/cmdio"
|
2023-08-07 13:14:25 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBundleInitIsRepoUrl(t *testing.T) {
|
|
|
|
assert.True(t, isRepoUrl("git@github.com:databricks/cli.git"))
|
|
|
|
assert.True(t, isRepoUrl("https://github.com/databricks/cli.git"))
|
|
|
|
|
|
|
|
assert.False(t, isRepoUrl("./local"))
|
|
|
|
assert.False(t, isRepoUrl("foo"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBundleInitRepoName(t *testing.T) {
|
|
|
|
// Test valid URLs
|
|
|
|
assert.Equal(t, "cli.git", repoName("git@github.com:databricks/cli.git"))
|
|
|
|
assert.Equal(t, "cli", repoName("https://github.com/databricks/cli/"))
|
|
|
|
|
|
|
|
// test invalid URLs. In these cases the error would be floated when the
|
|
|
|
// git clone operation fails.
|
|
|
|
assert.Equal(t, "git@github.com:databricks", repoName("git@github.com:databricks"))
|
|
|
|
assert.Equal(t, "invalid-url", repoName("invalid-url"))
|
|
|
|
assert.Equal(t, "www.github.com", repoName("https://www.github.com"))
|
|
|
|
}
|
2023-11-28 09:04:06 +00:00
|
|
|
|
|
|
|
func TestNativeTemplateOptions(t *testing.T) {
|
2023-12-27 12:03:08 +00:00
|
|
|
expected := []cmdio.Tuple{
|
|
|
|
{Name: "default-python", Id: "The default Python template for Notebooks / Delta Live Tables / Workflows"},
|
2024-06-04 08:57:13 +00:00
|
|
|
{Name: "default-sql", Id: "The default SQL template for .sql files that run with Databricks SQL"},
|
|
|
|
{Name: "dbt-sql", Id: "The dbt SQL template (databricks.com/blog/delivering-cost-effective-data-real-time-dbt-and-databricks)"},
|
2023-12-27 12:03:08 +00:00
|
|
|
{Name: "mlops-stacks", Id: "The Databricks MLOps Stacks template (github.com/databricks/mlops-stacks)"},
|
|
|
|
{Name: "custom...", Id: "Bring your own template"},
|
|
|
|
}
|
|
|
|
assert.Equal(t, expected, nativeTemplateOptions())
|
2023-11-28 09:04:06 +00:00
|
|
|
}
|
|
|
|
|
2023-12-27 12:03:08 +00:00
|
|
|
func TestNativeTemplateHelpDescriptions(t *testing.T) {
|
|
|
|
expected := `- default-python: The default Python template for Notebooks / Delta Live Tables / Workflows
|
2024-06-04 08:57:13 +00:00
|
|
|
- default-sql: The default SQL template for .sql files that run with Databricks SQL
|
|
|
|
- dbt-sql: The dbt SQL template (databricks.com/blog/delivering-cost-effective-data-real-time-dbt-and-databricks)
|
2023-12-27 12:03:08 +00:00
|
|
|
- mlops-stacks: The Databricks MLOps Stacks template (github.com/databricks/mlops-stacks)`
|
|
|
|
assert.Equal(t, expected, nativeTemplateHelpDescriptions())
|
2023-11-28 09:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetUrlForNativeTemplate(t *testing.T) {
|
|
|
|
assert.Equal(t, "https://github.com/databricks/mlops-stacks", getUrlForNativeTemplate("mlops-stacks"))
|
|
|
|
assert.Equal(t, "https://github.com/databricks/mlops-stacks", getUrlForNativeTemplate("mlops-stack"))
|
|
|
|
assert.Equal(t, "", getUrlForNativeTemplate("default-python"))
|
|
|
|
assert.Equal(t, "", getUrlForNativeTemplate("invalid"))
|
|
|
|
}
|