mirror of
https://github.com/lukaszraczylo/harness-sync.git
synced 2026-10-12 00:45:22 +00:00
feat(adapter): registry with detect filtering and duplicate guard
This commit is contained in:
@@ -3,6 +3,7 @@ package adapter
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/lukaszraczylo/harness-sync/internal/canonical"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -23,3 +24,37 @@ func TestKindString(t *testing.T) {
|
||||
assert.Equal(t, "rendered", RenderedFile.String())
|
||||
assert.Equal(t, "symlink-file", SymlinkFile.String())
|
||||
}
|
||||
|
||||
type fakeAdapter struct {
|
||||
name string
|
||||
detect bool
|
||||
}
|
||||
|
||||
func (f *fakeAdapter) Name() string { return f.name }
|
||||
func (f *fakeAdapter) Detect() bool { return f.detect }
|
||||
func (f *fakeAdapter) Render(_ *canonical.Bundle) (*FileSet, error) { return NewFileSet(), nil }
|
||||
func (f *fakeAdapter) Import(_ string) (*ImportResult, error) { return &ImportResult{}, nil }
|
||||
|
||||
func TestRegistry(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
a := &fakeAdapter{name: "a", detect: true}
|
||||
b := &fakeAdapter{name: "b", detect: false}
|
||||
r.Register(a)
|
||||
r.Register(b)
|
||||
|
||||
assert.Equal(t, []string{"a", "b"}, r.Names())
|
||||
assert.Equal(t, []string{"a"}, r.DetectedNames())
|
||||
|
||||
got, ok := r.Get("a")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "a", got.Name())
|
||||
|
||||
_, ok = r.Get("missing")
|
||||
assert.False(t, ok)
|
||||
}
|
||||
|
||||
func TestRegistryDuplicatePanics(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
r.Register(&fakeAdapter{name: "x"})
|
||||
assert.Panics(t, func() { r.Register(&fakeAdapter{name: "x"}) })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user