We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 147b465 commit d2890f3Copy full SHA for d2890f3
pkg/tag/tag.go
@@ -117,6 +117,10 @@ func (il ImageTagList) SortByDate() SortableImageTagList {
117
sil = append(sil, v)
118
}
119
sort.Slice(sil, func(i, j int) bool {
120
+ if sil[i].TagDate.Equal(*sil[j].TagDate) {
121
+ // if an image has two tags, return the same consistently
122
+ return sil[i].TagName < sil[j].TagName
123
+ }
124
return sil[i].TagDate.Before(*sil[j].TagDate)
125
})
126
return sil
pkg/tag/tag_test.go
@@ -98,6 +98,23 @@ func Test_SortableImageTagList(t *testing.T) {
98
assert.Equal(t, "v2.0.3", sil[3].TagName)
99
assert.Equal(t, "v2.0.2", sil[4].TagName)
100
101
+
102
+ t.Run("Sort by date with same dates", func(t *testing.T) {
103
+ names := []string{"v2.0.2", "v1.0", "v1.0.1", "v2.0.3", "v2.0"}
104
+ date := time.Unix(0, 0)
105
+ il := NewImageTagList()
106
+ for _, name := range names {
107
+ tag := NewImageTag(name, date)
108
+ il.Add(tag)
109
110
+ sil := il.SortByDate()
111
+ require.Len(t, sil, len(names))
112
+ assert.Equal(t, "v1.0", sil[0].TagName)
113
+ assert.Equal(t, "v1.0.1", sil[1].TagName)
114
+ assert.Equal(t, "v2.0", sil[2].TagName)
115
+ assert.Equal(t, "v2.0.2", sil[3].TagName)
116
+ assert.Equal(t, "v2.0.3", sil[4].TagName)
+ })
func Test_TagsFromTagList(t *testing.T) {
0 commit comments