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>
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"net/url"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/Snider/Borg/pkg/storage"
|
|
)
|
|
|
|
// MockStorage is a mock implementation of the Storage interface for testing.
|
|
type MockStorage struct {
|
|
WriteFunc func(path string, data io.Reader) error
|
|
ReadFunc func(path string) (io.ReadCloser, error)
|
|
ListFunc func(path string) ([]string, error)
|
|
}
|
|
|
|
func (m *MockStorage) Write(path string, data io.Reader) error {
|
|
if m.WriteFunc != nil {
|
|
return m.WriteFunc(path, data)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *MockStorage) Read(path string) (io.ReadCloser, error) {
|
|
if m.ReadFunc != nil {
|
|
return m.ReadFunc(path)
|
|
}
|
|
return io.NopCloser(bytes.NewReader([]byte{})), nil
|
|
}
|
|
|
|
func (m *MockStorage) List(path string) ([]string, error) {
|
|
if m.ListFunc != nil {
|
|
return m.ListFunc(path)
|
|
}
|
|
return []string{}, nil
|
|
}
|
|
|
|
func TestMain(m *testing.M) {
|
|
// Mock the storage backend for all tests in this package
|
|
originalNewStorage := storage.NewStorage
|
|
storage.NewStorage = func(u *url.URL) (storage.Storage, error) {
|
|
if u.Scheme == "mock" {
|
|
return &MockStorage{}, nil
|
|
}
|
|
return originalNewStorage(u)
|
|
}
|
|
os.Exit(m.Run())
|
|
}
|