Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 41 additions & 7 deletions internal/cli/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,22 +564,56 @@ func TestCrossCompileFullsend_ProducesBinary(t *testing.T) {
}

func TestResolveLinuxBinary_Download(t *testing.T) {
if testing.Short() {
t.Skip("skipping download test in short mode")
}
// Build a valid tar.gz containing a mock "fullsend" binary.
var tarBuf bytes.Buffer
gw := gzip.NewWriter(&tarBuf)
tw := tar.NewWriter(gw)
content := []byte("mock fullsend binary")
require.NoError(t, tw.WriteHeader(&tar.Header{
Name: "fullsend",
Size: int64(len(content)),
Mode: 0o755,
Typeflag: tar.TypeReg,
}))
_, err := tw.Write(content)
require.NoError(t, err)
require.NoError(t, tw.Close())
require.NoError(t, gw.Close())

tarBytes := tarBuf.Bytes()
h := sha256.Sum256(tarBytes)
correctHash := hex.EncodeToString(h[:])

checksumBody := fmt.Sprintf("%s fullsend_0.4.0_linux_amd64.tar.gz\n", correctHash)

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/v0.4.0/checksums.txt":
fmt.Fprint(w, checksumBody)
case "/v0.4.0/fullsend_0.4.0_linux_amd64.tar.gz":
w.Write(tarBytes)
default:
http.NotFound(w, r)
}
}))
defer srv.Close()

origBaseURL := releaseBaseURL
releaseBaseURL = srv.URL
defer func() { releaseBaseURL = origBaseURL }()

tmpDir := t.TempDir()
binPath := filepath.Join(tmpDir, "fullsend")
err := downloadReleaseBinary("0.4.0", "amd64", binPath)
err = downloadReleaseBinary("0.4.0", "amd64", binPath)
require.NoError(t, err)

info, err := os.Stat(binPath)
require.NoError(t, err)
assert.True(t, info.Size() > 0, "downloaded binary should be non-empty")

// Verify the downloaded artifact is a valid Linux ELF for the requested arch.
t.Setenv("FULLSEND_SANDBOX_ARCH", "amd64")
assert.NoError(t, validateLinuxBinary(binPath), "downloaded binary should be a valid Linux/amd64 ELF")
data, err := os.ReadFile(binPath)
require.NoError(t, err)
assert.Equal(t, "mock fullsend binary", string(data))
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] test-coverage-regression

The removal of the validateLinuxBinary assertion reduces integration-level validation that downloadReleaseBinary produces a valid ELF. This is a necessary trade-off for the mock strategy, since the mock binary is not a real ELF, and validateLinuxBinary is independently tested by TestValidateLinuxBinary_* tests (lines 454-475).

Suggested fix: Consider adding a comment explaining why validateLinuxBinary is not called (e.g., '// Mock binary is not a real ELF; validateLinuxBinary is tested separately in TestValidateLinuxBinary_*').


func TestReadOIDCAuthFile_Success(t *testing.T) {
Expand Down
Loading