github.com/martinohmann/rfoutlet@v1.2.1-0.20220707195255-8a66aa411105/internal/outlet/registry_test.go (about) 1 package outlet 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestRegistry(t *testing.T) { 11 r := NewRegistry() 12 13 require.NoError(t, r.RegisterGroups(&Group{ID: "foo"})) 14 assert.Len(t, r.GetGroups(), 1) 15 assert.Len(t, r.GetOutlets(), 0) 16 17 require.Error(t, r.RegisterGroups(&Group{ID: "foo"})) 18 require.NoError(t, r.RegisterGroups(&Group{ID: "bar", Outlets: []*Outlet{{ID: "baz"}}})) 19 require.Error(t, r.RegisterGroups(&Group{ID: "baz", Outlets: []*Outlet{{ID: "baz"}}})) 20 assert.Len(t, r.GetGroups(), 2) 21 assert.Len(t, r.GetOutlets(), 1) 22 23 group, ok := r.GetGroup("foo") 24 assert.True(t, ok) 25 assert.Equal(t, &Group{ID: "foo"}, group) 26 27 _, ok = r.GetGroup("non-existent") 28 assert.False(t, ok) 29 30 outlet, ok := r.GetOutlet("baz") 31 assert.True(t, ok) 32 assert.Equal(t, &Outlet{ID: "baz"}, outlet) 33 34 _, ok = r.GetOutlet("non-existent") 35 assert.False(t, ok) 36 }