package collector import ( "context" "testing" ) func TestRegistry_Register(t *testing.T) { r := NewRegistry() mock := &mockCollector{name: "test"} err := r.Register(mock) if err != nil { t.Fatalf("unexpected error: %v", err) } // Duplicate registration should fail err = r.Register(mock) if err == nil { t.Fatal("expected error for duplicate registration") } } func TestRegistry_Get(t *testing.T) { r := NewRegistry() mock := &mockCollector{name: "test"} _ = r.Register(mock) c, ok := r.Get("test") if !ok { t.Fatal("expected to find collector") } if c.Name() != "test" { t.Fatalf("expected name 'test', got '%s'", c.Name()) } _, ok = r.Get("nonexistent") if ok { t.Fatal("expected not to find collector") } } func TestRegistry_List(t *testing.T) { r := NewRegistry() _ = r.Register(&mockCollector{name: "a", category: CategoryRuntime}) _ = r.Register(&mockCollector{name: "b", category: CategoryEditor}) _ = r.Register(&mockCollector{name: "c", category: CategoryRuntime}) all := r.List() if len(all) != 3 { t.Fatalf("expected 3 collectors, got %d", len(all)) } runtime := r.ListByCategory(CategoryRuntime) if len(runtime) != 2 { t.Fatalf("expected 2 runtime collectors, got %d", len(runtime)) } } // mockCollector implements Collector for testing type mockCollector struct { name string category Category available bool } func (m *mockCollector) Name() string { return m.name } func (m *mockCollector) DisplayName() string { return m.name } func (m *mockCollector) Description() string { return "mock collector" } func (m *mockCollector) Category() Category { return m.category } func (m *mockCollector) IsAvailable(ctx context.Context) bool { return m.available } func (m *mockCollector) Scan(ctx context.Context, opts ScanOptions) (*ScanResult, error) { return &ScanResult{Collector: m.name, Category: m.category}, nil } func (m *mockCollector) Capture(ctx context.Context, targetDir string, opts CaptureOptions) error { return nil } func (m *mockCollector) Restore(ctx context.Context, sourceDir string, opts RestoreOptions) error { return nil } func (m *mockCollector) Verify(ctx context.Context) (*VerifyResult, error) { return &VerifyResult{Success: true}, nil }