Skip to content

Commit

Permalink
fix(queue): match props first then stringer
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Sep 30, 2024
1 parent f564f34 commit 4ef02d8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/queue/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,22 @@ func (i *Item) Equals(o resource.Resource) bool {
return false
}

iStringer, iOK := i.Resource.(resource.LegacyStringer)
oStringer, oOK := o.(resource.LegacyStringer)
iGetter, iOK := i.Resource.(resource.PropertyGetter)
oGetter, oOK := o.(resource.PropertyGetter)
if iOK != oOK {
return false
}
if iOK && oOK {
return iStringer.String() == oStringer.String()
return iGetter.Properties().Equals(oGetter.Properties())
}

iGetter, iOK := i.Resource.(resource.PropertyGetter)
oGetter, oOK := o.(resource.PropertyGetter)
iStringer, iOK := i.Resource.(resource.LegacyStringer)
oStringer, oOK := o.(resource.LegacyStringer)
if iOK != oOK {
return false
}
if iOK && oOK {
return iGetter.Properties().Equals(oGetter.Properties())
return iStringer.String() == oStringer.String()
}

return false
Expand Down
36 changes: 36 additions & 0 deletions pkg/queue/item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package queue
import (
"context"
"testing"
"time"

"github.com/stretchr/testify/assert"

Expand Down Expand Up @@ -236,3 +237,38 @@ func Test_ItemEqualNothing(t *testing.T) {

assert.False(t, i.Equals(i.Resource))
}

// ------------------------------------------------------------------------

type TestItemResourceRevenant struct {
Props types.Properties
}

func (r *TestItemResourceRevenant) Remove(_ context.Context) error {
return nil
}
func (r *TestItemResourceRevenant) Properties() types.Properties {
return r.Props
}

func Test_ItemRevenant(t *testing.T) {
i := &Item{
Resource: &TestItemResourceRevenant{
Props: types.NewProperties().Set("CreatedAt", time.Now().UTC()),
},
State: ItemStateNew,
Reason: "brand new",
Type: "TestResource",
}

j := &Item{
Resource: &TestItemResourceRevenant{
Props: types.NewProperties().Set("CreatedAt", time.Now().UTC().Add(4*time.Minute)),
},
State: ItemStateNew,
Reason: "brand new",
Type: "TestResource",
}

assert.False(t, j.Equals(i.Resource))
}

0 comments on commit 4ef02d8

Please sign in to comment.