Skip to content

Commit 24d5662

Browse files
committed
Add cloud-only acceptance tests for ssh tunnel
1 parent d307bfa commit 24d5662

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

acceptance/acceptance_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ func testAccept(t *testing.T, inprocessMode bool, singleTest string) int {
234234
}
235235
}
236236

237+
if cloudEnv != "" && UseVersion == "" {
238+
// Create linux release artifacts, to be used by the cloud-only ssh tunnel tests
239+
releasesDir := CreateReleaseArtifacts(t, cwd, "linux")
240+
t.Setenv("CLI_RELEASES_DIR", releasesDir)
241+
}
242+
237243
testDefaultWarehouseId := os.Getenv("TEST_DEFAULT_WAREHOUSE_ID")
238244
if testDefaultWarehouseId != "" {
239245
repls.Set(testDefaultWarehouseId, "[TEST_DEFAULT_WAREHOUSE_ID]")
@@ -903,6 +909,58 @@ func BuildCLI(t *testing.T, buildDir, coverDir string) string {
903909
return execPath
904910
}
905911

912+
// CreateReleaseArtifacts builds release artifacts for the given OS using amd64 and arm64 architectures,
913+
// archives them into zip files, and returns the directory containing the release artifacts.
914+
func CreateReleaseArtifacts(t *testing.T, cwd, osName string) string {
915+
releasesDir := filepath.Join(cwd, "build", "releases")
916+
require.NoError(t, os.MkdirAll(releasesDir, os.ModePerm))
917+
arches := []string{"amd64", "arm64"}
918+
for _, arch := range arches {
919+
CreateReleaseArtifact(t, cwd, releasesDir, osName, arch)
920+
}
921+
return releasesDir
922+
}
923+
924+
func CreateReleaseArtifact(t *testing.T, cwd, releasesDir, osName, arch string) {
925+
tempBuildDir := filepath.Join(releasesDir, "tmp_"+arch)
926+
require.NoError(t, os.MkdirAll(tempBuildDir, os.ModePerm))
927+
defer os.RemoveAll(tempBuildDir)
928+
929+
execPath := filepath.Join(tempBuildDir, "databricks")
930+
args := []string{"go", "build", "-o", execPath}
931+
RunCommand(t, args, "..", []string{"GOOS=" + osName, "GOARCH=" + arch})
932+
933+
zipName := fmt.Sprintf("databricks_cli_%s_%s.zip", osName, arch)
934+
zipPath := filepath.Join(releasesDir, zipName)
935+
936+
zipFile, err := os.Create(zipPath)
937+
require.NoError(t, err)
938+
defer zipFile.Close()
939+
940+
zipWriter := zip.NewWriter(zipFile)
941+
defer zipWriter.Close()
942+
943+
info, err := os.Stat(execPath)
944+
require.NoError(t, err)
945+
946+
header, err := zip.FileInfoHeader(info)
947+
require.NoError(t, err)
948+
header.Name = "databricks"
949+
header.Method = zip.Deflate
950+
951+
writer, err := zipWriter.CreateHeader(header)
952+
require.NoError(t, err)
953+
954+
binaryFile, err := os.Open(execPath)
955+
require.NoError(t, err)
956+
defer binaryFile.Close()
957+
958+
_, err = io.Copy(writer, binaryFile)
959+
require.NoError(t, err)
960+
961+
t.Logf("Created %s %s release: %s", osName, arch, zipPath)
962+
}
963+
906964
// DownloadCLI downloads a released CLI binary archive for the given version,
907965
// extracts the executable, and returns its path.
908966
func DownloadCLI(t *testing.T, buildDir, version string) string {

acceptance/ssh/connection/out.test.toml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Connection successful

acceptance/ssh/connection/script

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
errcode $CLI ssh connect --cluster=$TEST_DEFAULT_CLUSTER_ID --releases-dir=$CLI_RELEASES_DIR -- "echo 'Connection successful'" >LOG.stdout 2>LOG.stderr
2+
3+
cat LOG.stdout
4+
5+
if ! grep -q "Connection successful" LOG.stdout; then
6+
run_id=$(cat LOG.stderr | grep -o "Job submitted successfully with run ID: [0-9]*" | grep -o "[0-9]*$")
7+
trace $CLI jobs get-run "$run_id" > LOG.job
8+
fi
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Local = false
2+
Cloud = true
3+
RequiresCluster = true
4+
5+
[EnvMatrix]
6+
DATABRICKS_BUNDLE_ENGINE = ["direct-exp"]

0 commit comments

Comments
 (0)