diff --git a/pkg/runtime/runtime.go b/pkg/runtime/runtime.go index 3e331071..d1cafe5c 100644 --- a/pkg/runtime/runtime.go +++ b/pkg/runtime/runtime.go @@ -163,8 +163,8 @@ func (r *Runtime) Reconcile(ctx context.Context) error { bounded := make(map[uuid.UUID]spec.Spec) for _, id := range r.symbolTable.Keys() { - sb, ok := r.symbolTable.Lookup(id) - if ok && r.scheme.IsBound(sb.Spec, secrets...) { + sb := r.symbolTable.Lookup(id) + if sb != nil && r.scheme.IsBound(sb.Spec, secrets...) { bounded[sb.Spec.GetID()] = sb.Spec } } diff --git a/pkg/symbol/loader.go b/pkg/symbol/loader.go index d29e9e7a..b9a002b4 100644 --- a/pkg/symbol/loader.go +++ b/pkg/symbol/loader.go @@ -85,8 +85,8 @@ func (l *Loader) Load(ctx context.Context, specs ...spec.Spec) error { continue } - sb, ok := l.table.Lookup(decode.GetID()) - if !ok || !reflect.DeepEqual(sb.Spec, decode) { + sb := l.table.Lookup(decode.GetID()) + if sb == nil || !reflect.DeepEqual(sb.Spec, decode) { n, err := l.scheme.Compile(decode) if err != nil { errs = append(errs, err) @@ -108,8 +108,8 @@ func (l *Loader) Load(ctx context.Context, specs ...spec.Spec) error { } for _, id := range l.table.Keys() { - sb, ok := l.table.Lookup(id) - if ok && len(resource.Match(sb.Spec, examples...)) > 0 { + sb := l.table.Lookup(id) + if sb != nil && len(resource.Match(sb.Spec, examples...)) > 0 { ok := false for _, s := range symbols { if s.ID() == id { diff --git a/pkg/symbol/loader_test.go b/pkg/symbol/loader_test.go index 7ce9b46b..1d98379c 100644 --- a/pkg/symbol/loader_test.go +++ b/pkg/symbol/loader_test.go @@ -77,15 +77,9 @@ func TestLoader_Load(t *testing.T) { err := loader.Load(ctx, meta1, meta2, meta3) assert.NoError(t, err) - - _, ok := table.Lookup(meta1.GetID()) - assert.True(t, ok) - - _, ok = table.Lookup(meta2.GetID()) - assert.True(t, ok) - - _, ok = table.Lookup(meta3.GetID()) - assert.True(t, ok) + assert.NotNil(t, table.Lookup(meta1.GetID())) + assert.NotNil(t, table.Lookup(meta2.GetID())) + assert.NotNil(t, table.Lookup(meta3.GetID())) }) t.Run("ReloadWithSameID", func(t *testing.T) { @@ -166,9 +160,7 @@ func TestLoader_Load(t *testing.T) { err = loader.Load(ctx, meta) assert.NoError(t, err) - - _, ok := table.Lookup(meta.GetID()) - assert.False(t, ok) + assert.NotNil(t, table.Lookup(meta.GetID())) }) t.Run("LoadMultipleSecrets", func(t *testing.T) { @@ -214,9 +206,7 @@ func TestLoader_Load(t *testing.T) { err := loader.Load(ctx, meta) assert.NoError(t, err) - - _, ok := table.Lookup(meta.GetID()) - assert.True(t, ok) + assert.NotNil(t, table.Lookup(meta.GetID())) }) t.Run("LoadNonExistSecret", func(t *testing.T) { @@ -252,8 +242,6 @@ func TestLoader_Load(t *testing.T) { err := loader.Load(ctx, meta) assert.Error(t, err) - - _, ok := table.Lookup(meta.GetID()) - assert.False(t, ok) + assert.NotNil(t, table.Lookup(meta.GetID())) }) } diff --git a/pkg/symbol/table.go b/pkg/symbol/table.go index c350e6d1..c7ab5437 100644 --- a/pkg/symbol/table.go +++ b/pkg/symbol/table.go @@ -55,10 +55,7 @@ func (t *Table) Insert(sb *Symbol) error { if _, err := t.free(sb.ID()); err != nil { return err } - if err := t.insert(sb); err != nil { - return err - } - return nil + return t.insert(sb) } // Free removes a symbol from the table by its ID. @@ -74,12 +71,11 @@ func (t *Table) Free(id uuid.UUID) (bool, error) { } // Lookup retrieves a symbol from the table by its ID. -func (t *Table) Lookup(id uuid.UUID) (*Symbol, bool) { +func (t *Table) Lookup(id uuid.UUID) *Symbol { t.mu.RLock() defer t.mu.RUnlock() - sb, ok := t.symbols[id] - return sb, ok + return t.symbols[id] } // Keys returns all IDs of symbols in the table. diff --git a/pkg/symbol/table_test.go b/pkg/symbol/table_test.go index bd54f291..254af7c2 100644 --- a/pkg/symbol/table_test.go +++ b/pkg/symbol/table_test.go @@ -396,12 +396,10 @@ func TestTable_LookupByID(t *testing.T) { } sb := &Symbol{Spec: meta, Node: node.NewOneToOneNode(nil)} + err := tb.Insert(sb) assert.NoError(t, err) - - r, ok := tb.Lookup(sb.ID()) - assert.True(t, ok) - assert.Equal(t, sb, r) + assert.Equal(t, sb, tb.Lookup(sb.ID())) } func TestTable_Keys(t *testing.T) {