48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package mock
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/example/storage-appliance/internal/domain"
|
|
"github.com/example/storage-appliance/internal/service"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
var (
|
|
_ service.DiskService = (*MockDiskService)(nil)
|
|
_ service.ZFSService = (*MockZFSService)(nil)
|
|
_ service.JobRunner = (*MockJobRunner)(nil)
|
|
)
|
|
|
|
type MockDiskService struct{}
|
|
|
|
func (m *MockDiskService) List(ctx context.Context) ([]domain.Disk, error) {
|
|
return []domain.Disk{{ID: domain.UUID(uuid.New().String()), Path: "/dev/sda", Serial: "XYZ123", Model: "ACME 1TB", Size: 1 << 40, Health: "ONLINE"}}, nil
|
|
}
|
|
|
|
func (m *MockDiskService) Inspect(ctx context.Context, path string) (domain.Disk, error) {
|
|
return domain.Disk{ID: domain.UUID(uuid.New().String()), Path: path, Serial: "XYZ123", Model: "ACME 1TB", Size: 1 << 40, Health: "ONLINE"}, nil
|
|
}
|
|
|
|
type MockZFSService struct{}
|
|
|
|
func (m *MockZFSService) ListPools(ctx context.Context) ([]domain.Pool, error) {
|
|
return []domain.Pool{{Name: "tank", GUID: "g-uuid-1", Health: "ONLINE", Capacity: "1TiB"}}, nil
|
|
}
|
|
|
|
func (m *MockZFSService) CreatePool(ctx context.Context, name string, vdevs []string) (string, error) {
|
|
// spawn instant job id for mock
|
|
return "job-" + uuid.New().String(), nil
|
|
}
|
|
|
|
type MockJobRunner struct{}
|
|
|
|
func (m *MockJobRunner) Enqueue(ctx context.Context, j domain.Job) (string, error) {
|
|
// simulate queueing job and running immediately
|
|
go func() {
|
|
time.Sleep(100 * time.Millisecond)
|
|
}()
|
|
return uuid.New().String(), nil
|
|
}
|