Skip to content

Commit

Permalink
Aargh this logic was wrong - returns true for an older route with a n…
Browse files Browse the repository at this point in the history
…amespace/name/uid which is greater. Only do it if the timestamps match - otherwise the

older route should win. Fix up tests to check on that as well.
  • Loading branch information
ramr committed Oct 14, 2016
1 parent 9b19838 commit 396ccb5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
17 changes: 11 additions & 6 deletions pkg/route/api/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ func RouteLessThan(route1, route2 *Route) bool {
if route1.CreationTimestamp.Before(route2.CreationTimestamp) {
return true
}
if route1.CreationTimestamp == route2.CreationTimestamp && route1.UID < route2.UID {
return true
}
if route1.Namespace < route2.Namespace {
return true

if route1.CreationTimestamp == route2.CreationTimestamp {
if route1.UID < route2.UID {
return true
}
if route1.Namespace < route2.Namespace {
return true
}
return route1.Name < route2.Name
}
return route1.Name < route2.Name

return false
}
26 changes: 25 additions & 1 deletion pkg/route/api/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import (
)

func TestRouteLessThan(t *testing.T) {
current := unversioned.Now()
older := unversioned.Time{Time: current.Add(-1 * time.Minute)}

r := Route{
ObjectMeta: kapi.ObjectMeta{
CreationTimestamp: unversioned.Now().Rfc3339Copy(),
CreationTimestamp: current.Rfc3339Copy(),
UID: "alpha",
Namespace: "alpha",
Name: "alpha",
Expand Down Expand Up @@ -49,6 +52,27 @@ func TestRouteLessThan(t *testing.T) {
Name: "beta",
},
}, true},
{Route{
ObjectMeta: kapi.ObjectMeta{
CreationTimestamp: older,
UID: r.UID,
Namespace: r.Namespace,
Name: "beta",
},
}, false},
{Route{
ObjectMeta: kapi.ObjectMeta{
CreationTimestamp: older,
UID: r.UID,
Name: "gamma",
},
}, false},
{Route{
ObjectMeta: kapi.ObjectMeta{
CreationTimestamp: older,
Name: "delta",
},
}, false},
{r, false},
}

Expand Down

0 comments on commit 396ccb5

Please sign in to comment.