Skip to content

Commit fcc397e

Browse files
Only run testarchive tests as part of nightlies (#3511)
These tests are not important to run regularly. This PR makes it a part of nightlies to get some signal but not have these tests run on every PR. In order to convert these tests to nightlies we also remove main.go. The DBR test runner can directly call the CreateArchive function instead. Addresses post merge comment: #3500 (comment)
1 parent 98e835c commit fcc397e

File tree

9 files changed

+55
-70
lines changed

9 files changed

+55
-70
lines changed
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
package main
1+
package testarchive
22

33
import (
44
"path/filepath"
55
"testing"
66

7+
"github.com/databricks/cli/internal/testarchive"
8+
"github.com/databricks/cli/internal/testutil"
79
"github.com/stretchr/testify/assert"
810
"github.com/stretchr/testify/require"
911
)
@@ -13,17 +15,19 @@ func TestArchive(t *testing.T) {
1315
t.Skip("Skipping test in short mode")
1416
}
1517

18+
testutil.GetEnvOrSkipTest(t, "CLOUD_ENV")
19+
1620
t.Parallel()
1721

1822
archiveDir := t.TempDir()
1923
binDir := t.TempDir()
2024
repoRoot := "../.."
2125

22-
err := createArchive(archiveDir, binDir, repoRoot)
26+
err := testarchive.CreateArchive(archiveDir, binDir, repoRoot)
2327
require.NoError(t, err)
2428

2529
assertDir := t.TempDir()
26-
err = extractTarGz(filepath.Join(archiveDir, "archive.tar.gz"), assertDir)
30+
err = testarchive.ExtractTarGz(filepath.Join(archiveDir, "archive.tar.gz"), assertDir)
2731
require.NoError(t, err)
2832

2933
// Go installation is a directory because it includes the

internal/testarchive/downloader_test.go renamed to integration/testarchive/downloader_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
package main
1+
package testarchive
22

33
import (
44
"os"
55
"path/filepath"
66
"testing"
77

8+
"github.com/databricks/cli/internal/testarchive"
9+
"github.com/databricks/cli/internal/testutil"
810
"github.com/stretchr/testify/assert"
911
"github.com/stretchr/testify/require"
1012
)
@@ -16,10 +18,12 @@ func TestUvDownloader(t *testing.T) {
1618

1719
t.Parallel()
1820

21+
testutil.GetEnvOrSkipTest(t, "CLOUD_ENV")
22+
1923
tmpDir := t.TempDir()
2024

2125
for _, arch := range []string{"arm64", "amd64"} {
22-
err := uvDownloader{arch: arch, binDir: tmpDir}.Download()
26+
err := testarchive.UvDownloader{Arch: arch, BinDir: tmpDir}.Download()
2327
require.NoError(t, err)
2428

2529
files, err := os.ReadDir(filepath.Join(tmpDir, arch))
@@ -37,10 +41,12 @@ func TestJqDownloader(t *testing.T) {
3741

3842
t.Parallel()
3943

44+
testutil.GetEnvOrSkipTest(t, "CLOUD_ENV")
45+
4046
tmpDir := t.TempDir()
4147

4248
for _, arch := range []string{"arm64", "amd64"} {
43-
err := jqDownloader{arch: arch, binDir: tmpDir}.Download()
49+
err := testarchive.JqDownloader{Arch: arch, BinDir: tmpDir}.Download()
4450
require.NoError(t, err)
4551

4652
files, err := os.ReadDir(filepath.Join(tmpDir, arch))
@@ -58,10 +64,12 @@ func TestGoDownloader(t *testing.T) {
5864

5965
t.Parallel()
6066

67+
testutil.GetEnvOrSkipTest(t, "CLOUD_ENV")
68+
6169
tmpDir := t.TempDir()
6270

6371
for _, arch := range []string{"arm64", "amd64"} {
64-
err := goDownloader{arch: arch, binDir: tmpDir}.Download()
72+
err := testarchive.GoDownloader{Arch: arch, BinDir: tmpDir}.Download()
6573
require.NoError(t, err)
6674

6775
entries, err := os.ReadDir(filepath.Join(tmpDir, arch))

internal/testarchive/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

internal/testarchive/archive.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package testarchive
22

33
import (
44
"archive/tar"
@@ -97,18 +97,18 @@ func addFileToArchive(tarWriter *tar.Writer, src, dst string) error {
9797
return nil
9898
}
9999

100-
// createArchive creates a tar.gz archive of all git-tracked files plus downloaded tools
101-
func createArchive(archiveDir, binDir, repoRoot string) error {
100+
// CreateArchive creates a tar.gz archive of all git-tracked files plus downloaded tools
101+
func CreateArchive(archiveDir, binDir, repoRoot string) error {
102102
archivePath := filepath.Join(archiveDir, "archive.tar.gz")
103103

104104
// Download tools for both arm and amd64 architectures.
105105
// The right architecture to use is decided at runtime on the serverless driver.
106106
// The Databricks platform explicitly does not provide any guarantees around
107107
// the CPU architecture to keep the door open for future optimizations.
108108
downloaders := []downloader{
109-
goDownloader{arch: "amd64", binDir: binDir},
110-
uvDownloader{arch: "amd64", binDir: binDir},
111-
jqDownloader{arch: "amd64", binDir: binDir},
109+
GoDownloader{Arch: "amd64", BinDir: binDir},
110+
UvDownloader{Arch: "amd64", BinDir: binDir},
111+
JqDownloader{Arch: "amd64", BinDir: binDir},
112112

113113
// TODO: Serverless clusters do not support arm64 yet.
114114
// Enable ARM64 once serverless clusters support it.

internal/testarchive/go.go

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package testarchive
22

33
import (
44
"bufio"
@@ -10,24 +10,16 @@ import (
1010
"strings"
1111
)
1212

13-
// Initialize these to prevent linter from complaining about unused types.
14-
// This can be removed once we actually use these downloaders.
15-
var (
16-
_ = goDownloader{}
17-
_ = uvDownloader{}
18-
_ = jqDownloader{}
19-
)
20-
2113
type downloader interface {
2214
Download() error
2315
}
2416

25-
type goDownloader struct {
26-
binDir string
27-
arch string
17+
type GoDownloader struct {
18+
BinDir string
19+
Arch string
2820
}
2921

30-
func (g goDownloader) readGoVersionFromMod() (string, error) {
22+
func (g GoDownloader) readGoVersionFromMod() (string, error) {
3123
goModPath := filepath.Join("..", "..", "go.mod")
3224

3325
file, err := os.Open(goModPath)
@@ -57,21 +49,21 @@ func (g goDownloader) readGoVersionFromMod() (string, error) {
5749
}
5850

5951
// Download downloads and extracts Go for Linux
60-
func (g goDownloader) Download() error {
52+
func (g GoDownloader) Download() error {
6153
goVersion, err := g.readGoVersionFromMod()
6254
if err != nil {
6355
return fmt.Errorf("failed to read Go version from go.mod: %w", err)
6456
}
6557

6658
// Create the directory for the download if it doesn't exist
67-
dir := filepath.Join(g.binDir, g.arch)
59+
dir := filepath.Join(g.BinDir, g.Arch)
6860
err = os.MkdirAll(dir, 0o755)
6961
if err != nil {
7062
return err
7163
}
7264

7365
// Download the tar archive.
74-
fileName := fmt.Sprintf("go%s.linux-%s.tar.gz", goVersion, g.arch)
66+
fileName := fmt.Sprintf("go%s.linux-%s.tar.gz", goVersion, g.Arch)
7567
url := "https://go.dev/dl/" + fileName
7668

7769
tempFile := filepath.Join(dir, fileName)
@@ -80,7 +72,7 @@ func (g goDownloader) Download() error {
8072
return err
8173
}
8274

83-
err = extractTarGz(tempFile, dir)
75+
err = ExtractTarGz(tempFile, dir)
8476
if err != nil {
8577
return err
8678
}

internal/testarchive/jq.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
package main
1+
package testarchive
22

33
import (
44
"fmt"
55
"os"
66
"path/filepath"
77
)
88

9-
// jqDownloader handles downloading and extracting jq releases
10-
type jqDownloader struct {
11-
binDir string
12-
arch string
9+
// JqDownloader handles downloading and extracting jq releases
10+
type JqDownloader struct {
11+
BinDir string
12+
Arch string
1313
}
1414

1515
// Download downloads and extracts jq for Linux
16-
func (j jqDownloader) Download() error {
16+
func (j JqDownloader) Download() error {
1717
// create the directory for the download if it doesn't exist
18-
dir := filepath.Join(j.binDir, j.arch)
18+
dir := filepath.Join(j.BinDir, j.Arch)
1919
err := os.MkdirAll(dir, 0o755)
2020
if err != nil {
2121
return err
2222
}
2323

2424
// Construct the download URL for the latest release
25-
url := "https://github.com/jqlang/jq/releases/latest/download/jq-linux-" + j.arch
25+
url := "https://github.com/jqlang/jq/releases/latest/download/jq-linux-" + j.Arch
2626

2727
binaryPath := filepath.Join(dir, "jq")
2828
if err := downloadFile(url, binaryPath); err != nil {

internal/testarchive/main.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

internal/testarchive/utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package testarchive
22

33
import (
44
"archive/tar"
@@ -36,8 +36,8 @@ func downloadFile(url, outputPath string) error {
3636
return nil
3737
}
3838

39-
// extractTarGz extracts a tar.gz file to the specified directory
40-
func extractTarGz(archivePath, destDir string) error {
39+
// ExtractTarGz extracts a tar.gz file to the specified directory
40+
func ExtractTarGz(archivePath, destDir string) error {
4141
fmt.Printf("Extracting %s to %s\n", archivePath, destDir)
4242

4343
file, err := os.Open(archivePath)

internal/testarchive/uv.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
package main
1+
package testarchive
22

33
import (
44
"fmt"
55
"os"
66
"path/filepath"
77
)
88

9-
// uvDownloader handles downloading and extracting UV releases
10-
type uvDownloader struct {
11-
binDir string
12-
arch string
9+
// UvDownloader handles downloading and extracting UV releases
10+
type UvDownloader struct {
11+
BinDir string
12+
Arch string
1313
}
1414

1515
// uvDownloader creates a new UV downloader
1616

1717
// mapArchitecture maps our architecture names to UV's naming convention
18-
func (u uvDownloader) mapArchitecture(arch string) (string, error) {
18+
func (u UvDownloader) mapArchitecture(arch string) (string, error) {
1919
switch arch {
2020
case "arm64":
2121
return "aarch64", nil
@@ -27,15 +27,15 @@ func (u uvDownloader) mapArchitecture(arch string) (string, error) {
2727
}
2828

2929
// Download downloads and extracts UV for Linux
30-
func (u uvDownloader) Download() error {
30+
func (u UvDownloader) Download() error {
3131
// Map architecture names to UV's naming convention
32-
uvArch, err := u.mapArchitecture(u.arch)
32+
uvArch, err := u.mapArchitecture(u.Arch)
3333
if err != nil {
3434
return err
3535
}
3636

3737
// create the directory for the download if it doesn't exist
38-
dir := filepath.Join(u.binDir, u.arch)
38+
dir := filepath.Join(u.BinDir, u.Arch)
3939
err = os.MkdirAll(dir, 0o755)
4040
if err != nil {
4141
return err
@@ -52,7 +52,7 @@ func (u uvDownloader) Download() error {
5252
}
5353

5454
// Extract the archive to the directory
55-
if err := extractTarGz(tempFile, dir); err != nil {
55+
if err := ExtractTarGz(tempFile, dir); err != nil {
5656
return err
5757
}
5858

0 commit comments

Comments
 (0)