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>
46 lines
1 KiB
Go
46 lines
1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"net/url"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/Snider/Borg/pkg/storage"
|
|
)
|
|
|
|
func TestPullCmd(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
localPath := filepath.Join(tmpDir, "testfile.txt")
|
|
|
|
// Mock the storage backend
|
|
storage.NewStorage = func(u *url.URL) (storage.Storage, error) {
|
|
return &MockStorage{
|
|
ReadFunc: func(path string) (io.ReadCloser, error) {
|
|
if path != "/remote/path" {
|
|
t.Errorf("expected path '/remote/path', got '%s'", path)
|
|
}
|
|
return io.NopCloser(bytes.NewReader([]byte("pull test"))), nil
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
// Execute the pull command
|
|
root := NewRootCmd()
|
|
root.AddCommand(NewPullCmd())
|
|
_, err := executeCommand(root, "pull", "mock://bucket/remote/path", localPath)
|
|
if err != nil {
|
|
t.Fatalf("pull command failed: %v", err)
|
|
}
|
|
|
|
// Assertions
|
|
data, err := os.ReadFile(localPath)
|
|
if err != nil {
|
|
t.Fatalf("failed to read pulled file: %v", err)
|
|
}
|
|
if string(data) != "pull test" {
|
|
t.Errorf("expected data 'pull test', got '%s'", string(data))
|
|
}
|
|
}
|