Skip to content

Commit 20e1607

Browse files
committed
Re-use BuildCLI and create release artifacts in the build sub-directory
1 parent 839b086 commit 20e1607

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

acceptance/acceptance_test.go

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,7 @@ func testAccept(t *testing.T, inprocessMode bool, singleTest string) int {
153153
// Consistent behavior of locale-dependent tools, such as 'sort'
154154
t.Setenv("LC_ALL", "C")
155155

156-
buildDir := filepath.Join(cwd, "build", fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH))
157-
err = os.MkdirAll(buildDir, os.ModePerm)
158-
require.NoError(t, err)
156+
buildDir := getBuildDir(t, cwd, runtime.GOOS, runtime.GOARCH)
159157

160158
terraformDir := TerraformDir
161159
if terraformDir == "" {
@@ -190,7 +188,7 @@ func testAccept(t *testing.T, inprocessMode bool, singleTest string) int {
190188
if UseVersion != "" {
191189
execPath = DownloadCLI(t, buildDir, UseVersion)
192190
} else {
193-
execPath = BuildCLI(t, buildDir, coverDir)
191+
execPath = BuildCLI(t, buildDir, coverDir, runtime.GOOS, runtime.GOARCH)
194192
}
195193
}
196194

@@ -236,7 +234,7 @@ func testAccept(t *testing.T, inprocessMode bool, singleTest string) int {
236234

237235
if cloudEnv != "" && UseVersion == "" {
238236
// Create linux release artifacts, to be used by the cloud-only ssh tunnel tests
239-
releasesDir := CreateReleaseArtifacts(t, cwd, "linux")
237+
releasesDir := CreateReleaseArtifacts(t, cwd, coverDir, "linux")
240238
t.Setenv("CLI_RELEASES_DIR", releasesDir)
241239
}
242240

@@ -877,9 +875,20 @@ func readMergedScriptContents(t *testing.T, dir string) string {
877875
return strings.Join(prepares, "\n")
878876
}
879877

880-
func BuildCLI(t *testing.T, buildDir, coverDir string) string {
878+
func getBuildDirRoot(cwd string) string {
879+
return filepath.Join(cwd, "build")
880+
}
881+
882+
func getBuildDir(t *testing.T, cwd, osName, arch string) string {
883+
buildDir := filepath.Join(getBuildDirRoot(cwd), fmt.Sprintf("%s_%s", osName, arch))
884+
err := os.MkdirAll(buildDir, os.ModePerm)
885+
require.NoError(t, err)
886+
return buildDir
887+
}
888+
889+
func BuildCLI(t *testing.T, buildDir, coverDir, osName, arch string) string {
881890
execPath := filepath.Join(buildDir, "databricks")
882-
if runtime.GOOS == "windows" {
891+
if osName == "windows" {
883892
execPath += ".exe"
884893
}
885894

@@ -891,37 +900,33 @@ func BuildCLI(t *testing.T, buildDir, coverDir string) string {
891900
args = append(args, "-cover")
892901
}
893902

894-
if runtime.GOOS == "windows" {
903+
if osName == "windows" {
895904
// Get this error on my local Windows:
896905
// error obtaining VCS status: exit status 128
897906
// Use -buildvcs=false to disable VCS stamping.
898907
args = append(args, "-buildvcs=false")
899908
}
900909

901-
RunCommand(t, args, "..", []string{})
910+
RunCommand(t, args, "..", []string{"GOOS=" + osName, "GOARCH=" + arch})
902911
return execPath
903912
}
904913

905914
// CreateReleaseArtifacts builds release artifacts for the given OS using amd64 and arm64 architectures,
906915
// archives them into zip files, and returns the directory containing the release artifacts.
907-
func CreateReleaseArtifacts(t *testing.T, cwd, osName string) string {
908-
releasesDir := filepath.Join(cwd, "build", "releases")
916+
func CreateReleaseArtifacts(t *testing.T, cwd, coverDir, osName string) string {
917+
releasesDir := filepath.Join(getBuildDirRoot(cwd), "releases")
909918
require.NoError(t, os.MkdirAll(releasesDir, os.ModePerm))
910-
arches := []string{"amd64", "arm64"}
911-
for _, arch := range arches {
912-
CreateReleaseArtifact(t, cwd, releasesDir, osName, arch)
919+
for _, arch := range []string{"amd64", "arm64"} {
920+
CreateReleaseArtifact(t, cwd, releasesDir, coverDir, osName, arch)
913921
}
914922
return releasesDir
915923
}
916924

917-
func CreateReleaseArtifact(t *testing.T, cwd, releasesDir, osName, arch string) {
918-
tempBuildDir := filepath.Join(releasesDir, "tmp_"+arch)
919-
require.NoError(t, os.MkdirAll(tempBuildDir, os.ModePerm))
920-
defer os.RemoveAll(tempBuildDir)
921-
922-
execPath := filepath.Join(tempBuildDir, "databricks")
923-
args := []string{"go", "build", "-o", execPath}
924-
RunCommand(t, args, "..", []string{"GOOS=" + osName, "GOARCH=" + arch})
925+
func CreateReleaseArtifact(t *testing.T, cwd, releasesDir, coverDir, osName, arch string) {
926+
buildDir := getBuildDir(t, cwd, osName, arch)
927+
execPath := BuildCLI(t, buildDir, coverDir, osName, arch)
928+
execInfo, err := os.Stat(execPath)
929+
require.NoError(t, err)
925930

926931
zipName := fmt.Sprintf("databricks_cli_%s_%s.zip", osName, arch)
927932
zipPath := filepath.Join(releasesDir, zipName)
@@ -933,10 +938,7 @@ func CreateReleaseArtifact(t *testing.T, cwd, releasesDir, osName, arch string)
933938
zipWriter := zip.NewWriter(zipFile)
934939
defer zipWriter.Close()
935940

936-
info, err := os.Stat(execPath)
937-
require.NoError(t, err)
938-
939-
header, err := zip.FileInfoHeader(info)
941+
header, err := zip.FileInfoHeader(execInfo)
940942
require.NoError(t, err)
941943
header.Name = "databricks"
942944
header.Method = zip.Deflate
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Connection successful
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
Connection successful

acceptance/ssh/connection/script

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
errcode $CLI ssh connect --cluster=$TEST_DEFAULT_CLUSTER_ID --releases-dir=$CLI_RELEASES_DIR -- "echo 'Connection successful'" >LOG.stdout 2>LOG.stderr
1+
errcode $CLI ssh connect --cluster=$TEST_DEFAULT_CLUSTER_ID --releases-dir=$CLI_RELEASES_DIR -- "echo 'Connection successful'" >out.stdout.txt 2>LOG.stderr
22

3-
cat LOG.stdout
4-
5-
if ! grep -q "Connection successful" LOG.stdout; then
3+
if ! grep -q "Connection successful" out.stdout.txt; then
64
run_id=$(cat LOG.stderr | grep -o "Job submitted successfully with run ID: [0-9]*" | grep -o "[0-9]*$")
75
trace $CLI jobs get-run "$run_id" > LOG.job
86
fi

0 commit comments

Comments
 (0)