Skip to content

Commit

Permalink
refactor: remove unnessary bool return
Browse files Browse the repository at this point in the history
  • Loading branch information
siyul-park committed Oct 3, 2024
1 parent 8dd63a0 commit 912997b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 29 deletions.
8 changes: 4 additions & 4 deletions pkg/symbol/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
24 changes: 6 additions & 18 deletions pkg/symbol/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()))
})
}
5 changes: 2 additions & 3 deletions pkg/symbol/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,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.
Expand Down
6 changes: 2 additions & 4 deletions pkg/symbol/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 912997b

Please sign in to comment.