Borg/cmd/push_test.go
google-labs-jules[bot] 3ac7b365ef feat: S3/cloud storage backend
This commit introduces a new cloud storage backend with support for S3 and S3-compatible services.

Key changes:
- Created a `storage` package with a `Storage` interface.
- Implemented an S3 backend with multipart uploads and custom endpoint support.
- Added `push`, `pull`, `ls`, and `remote add` commands.
- Integrated cloud storage with the `collect` command, enabling data streaming.
- Added unit and integration tests for the new functionality.

Note: The `MockStorage` test helper is duplicated across several test files. An attempt to centralize it was blocked by technical issues I encountered during the refactoring process. This refactoring is left for a future commit.

Co-authored-by: Snider <631881+Snider@users.noreply.github.com>
2026-02-02 00:46:35 +00:00

52 lines
1.2 KiB
Go

package cmd
import (
"bytes"
"io"
"net/url"
"os"
"path/filepath"
"testing"
"github.com/Snider/Borg/pkg/storage"
)
func TestPushCmd(t *testing.T) {
// Create a temporary file to push
tmpDir := t.TempDir()
localPath := filepath.Join(tmpDir, "testfile.txt")
err := os.WriteFile(localPath, []byte("push test"), 0644)
if err != nil {
t.Fatalf("failed to create test file: %v", err)
}
var writtenPath string
var writtenData []byte
// Mock the storage backend
storage.NewStorage = func(u *url.URL) (storage.Storage, error) {
return &MockStorage{
WriteFunc: func(path string, data io.Reader) error {
writtenPath = path
writtenData, _ = io.ReadAll(data)
return nil
},
}, nil
}
// Execute the push command
root := NewRootCmd()
root.AddCommand(NewPushCmd())
_, err = executeCommand(root, "push", localPath, "mock://bucket/remote/path")
if err != nil {
t.Fatalf("push command failed: %v", err)
}
// Assertions
if writtenPath != "/remote/path" {
t.Errorf("expected path '/remote/path', got '%s'", writtenPath)
}
if string(writtenData) != "push test" {
t.Errorf("expected data 'push test', got '%s'", string(writtenData))
}
}