2023-06-29 13:28:13 +00:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
2023-06-29 15:48:06 +00:00
|
|
|
"context"
|
|
|
|
"os"
|
2023-06-29 13:28:13 +00:00
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2023-06-29 16:47:56 +00:00
|
|
|
"github.com/databricks/cli/libs/cmdio"
|
2023-06-29 13:28:13 +00:00
|
|
|
"github.com/databricks/cli/libs/git"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2023-06-29 15:48:06 +00:00
|
|
|
// TODO: add assertion for error if git CLI is not found
|
2023-06-29 16:47:56 +00:00
|
|
|
func TestAccGitClonePublicRepository(t *testing.T) {
|
|
|
|
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
|
2023-06-29 15:48:06 +00:00
|
|
|
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
ctx := context.Background()
|
|
|
|
var err error
|
|
|
|
|
|
|
|
// We unset PATH to ensure that git.Clone cannot rely on the git CLI
|
|
|
|
t.Setenv("PATH", "")
|
|
|
|
|
|
|
|
err = git.Clone(ctx, git.CloneOptions{
|
|
|
|
Provider: "github",
|
|
|
|
Organization: "databricks",
|
|
|
|
RepositoryName: "cli",
|
|
|
|
Reference: "main",
|
|
|
|
TargetDir: tmpDir,
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.DirExists(t, filepath.Join(tmpDir, "cli-main"))
|
|
|
|
|
|
|
|
b, err := os.ReadFile(filepath.Join(tmpDir, "cli-main/NOTICE"))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, string(b), "Copyright (2023) Databricks, Inc.")
|
|
|
|
}
|
|
|
|
|
2023-06-29 16:47:56 +00:00
|
|
|
func TestAccGitClonePublicRepositoryForTagReference(t *testing.T) {
|
2023-06-29 15:48:06 +00:00
|
|
|
// t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
|
|
|
|
|
2023-06-29 13:28:13 +00:00
|
|
|
tmpDir := t.TempDir()
|
2023-06-29 15:48:06 +00:00
|
|
|
ctx := context.Background()
|
2023-06-29 16:47:56 +00:00
|
|
|
var err error
|
|
|
|
|
|
|
|
// We unset PATH to ensure that git.Clone cannot rely on the git CLI
|
|
|
|
t.Setenv("PATH", "")
|
|
|
|
|
|
|
|
err = git.Clone(ctx, git.CloneOptions{
|
|
|
|
Provider: "github",
|
|
|
|
Organization: "databricks",
|
|
|
|
RepositoryName: "cli",
|
|
|
|
Reference: "snapshot",
|
|
|
|
TargetDir: tmpDir,
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.DirExists(t, filepath.Join(tmpDir, "cli-snapshot"))
|
|
|
|
|
|
|
|
b, err := os.ReadFile(filepath.Join(tmpDir, "cli-snapshot/NOTICE"))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, string(b), "Copyright (2023) Databricks, Inc.")
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(file an issue before merge): create a dedicated databricks private repository
|
|
|
|
// and test this for branches and tags
|
|
|
|
func TestAccGitClonePrivateRepository(t *testing.T) {
|
|
|
|
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
|
|
|
|
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
cmdIO := cmdio.NewIO("text", os.Stdin, os.Stdout, os.Stderr, "")
|
|
|
|
ctx := cmdio.InContext(context.Background(), cmdIO)
|
2023-06-29 13:28:13 +00:00
|
|
|
|
|
|
|
// This is a private repository only accessible to databricks employees
|
2023-06-29 15:48:06 +00:00
|
|
|
err := git.Clone(ctx, git.CloneOptions{
|
|
|
|
Provider: "github",
|
|
|
|
Organization: "databricks",
|
|
|
|
RepositoryName: "bundle-samples-internal",
|
|
|
|
Reference: "main",
|
|
|
|
TargetDir: tmpDir,
|
|
|
|
})
|
2023-06-29 13:28:13 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// assert examples from the private repository
|
2023-06-29 15:48:06 +00:00
|
|
|
assert.DirExists(t, filepath.Join(tmpDir, "bundle-samples-internal-main", "shark_sightings"))
|
|
|
|
assert.DirExists(t, filepath.Join(tmpDir, "bundle-samples-internal-main", "wikipedia_clickstream"))
|
2023-06-29 13:28:13 +00:00
|
|
|
}
|