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>
36 lines
832 B
Go
36 lines
832 B
Go
package cmd
|
|
|
|
import (
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/Snider/Borg/pkg/storage"
|
|
)
|
|
|
|
func TestLsCmd(t *testing.T) {
|
|
// Mock the storage backend
|
|
storage.NewStorage = func(u *url.URL) (storage.Storage, error) {
|
|
return &MockStorage{
|
|
ListFunc: func(path string) ([]string, error) {
|
|
if path != "/remote/path" {
|
|
t.Errorf("expected path '/remote/path', got '%s'", path)
|
|
}
|
|
return []string{"file1.txt", "file2.txt"}, nil
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
// Execute the ls command
|
|
root := NewRootCmd()
|
|
root.AddCommand(NewLsCmd())
|
|
output, err := executeCommand(root, "ls", "mock://bucket/remote/path")
|
|
if err != nil {
|
|
t.Fatalf("ls command failed: %v", err)
|
|
}
|
|
|
|
// Assertions
|
|
expectedOutput := "file1.txt\nfile2.txt\n"
|
|
if output != expectedOutput {
|
|
t.Errorf("expected output '%s', got '%s'", expectedOutput, output)
|
|
}
|
|
}
|