32 lines
823 B
Go
32 lines
823 B
Go
package storage
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestFakeBackendCapturesRequestAndReturnsItems(t *testing.T) {
|
|
fake := &FakeBackend{}
|
|
req := ArchiveRequest{SessionID: "s1", Items: []ArchiveItem{{Kind: "artifact", LocalPath: "artifacts/log.md"}}}
|
|
|
|
res, err := fake.Archive(context.Background(), req)
|
|
if err != nil {
|
|
t.Fatalf("Archive() error = %v", err)
|
|
}
|
|
if len(fake.Requests) != 1 || fake.Requests[0].SessionID != "s1" {
|
|
t.Fatalf("requests = %#v, want captured request", fake.Requests)
|
|
}
|
|
if len(res.Archived) != 1 {
|
|
t.Fatalf("archived len = %d, want 1", len(res.Archived))
|
|
}
|
|
}
|
|
|
|
func TestFakeBackendError(t *testing.T) {
|
|
fake := &FakeBackend{Err: errors.New("boom")}
|
|
_, err := fake.Archive(context.Background(), ArchiveRequest{})
|
|
if err == nil {
|
|
t.Fatal("expected error, got nil")
|
|
}
|
|
}
|