Skip to content

Commit ad6d8e6

Browse files
committed
Re-use BuildCLI and create release artifacts in the build sub-directory
1 parent f813e3f commit ad6d8e6

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

@@ -884,9 +882,20 @@ func readMergedScriptContents(t *testing.T, dir string) string {
884882
return strings.Join(prepares, "\n")
885883
}
886884

887-
func BuildCLI(t *testing.T, buildDir, coverDir string) string {
885+
func getBuildDirRoot(cwd string) string {
886+
return filepath.Join(cwd, "build")
887+
}
888+
889+
func getBuildDir(t *testing.T, cwd, osName, arch string) string {
890+
buildDir := filepath.Join(getBuildDirRoot(cwd), fmt.Sprintf("%s_%s", osName, arch))
891+
err := os.MkdirAll(buildDir, os.ModePerm)
892+
require.NoError(t, err)
893+
return buildDir
894+
}
895+
896+
func BuildCLI(t *testing.T, buildDir, coverDir, osName, arch string) string {
888897
execPath := filepath.Join(buildDir, "databricks")
889-
if runtime.GOOS == "windows" {
898+
if osName == "windows" {
890899
execPath += ".exe"
891900
}
892901

@@ -898,37 +907,33 @@ func BuildCLI(t *testing.T, buildDir, coverDir string) string {
898907
args = append(args, "-cover")
899908
}
900909

901-
if runtime.GOOS == "windows" {
910+
if osName == "windows" {
902911
// Get this error on my local Windows:
903912
// error obtaining VCS status: exit status 128
904913
// Use -buildvcs=false to disable VCS stamping.
905914
args = append(args, "-buildvcs=false")
906915
}
907916

908-
RunCommand(t, args, "..", []string{})
917+
RunCommand(t, args, "..", []string{"GOOS=" + osName, "GOARCH=" + arch})
909918
return execPath
910919
}
911920

912921
// CreateReleaseArtifacts builds release artifacts for the given OS using amd64 and arm64 architectures,
913922
// 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")
923+
func CreateReleaseArtifacts(t *testing.T, cwd, coverDir, osName string) string {
924+
releasesDir := filepath.Join(getBuildDirRoot(cwd), "releases")
916925
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)
926+
for _, arch := range []string{"amd64", "arm64"} {
927+
CreateReleaseArtifact(t, cwd, releasesDir, coverDir, osName, arch)
920928
}
921929
return releasesDir
922930
}
923931

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+
func CreateReleaseArtifact(t *testing.T, cwd, releasesDir, coverDir, osName, arch string) {
933+
buildDir := getBuildDir(t, cwd, osName, arch)
934+
execPath := BuildCLI(t, buildDir, coverDir, osName, arch)
935+
execInfo, err := os.Stat(execPath)
936+
require.NoError(t, err)
932937

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

943-
info, err := os.Stat(execPath)
944-
require.NoError(t, err)
945-
946-
header, err := zip.FileInfoHeader(info)
948+
header, err := zip.FileInfoHeader(execInfo)
947949
require.NoError(t, err)
948950
header.Name = "databricks"
949951
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)