mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-23 09:08:26 +01:00
Sort the chart list before returning
- updatet the chart getting API - update the corresponding UT case Signed-off-by: Steven Zou <szou@vmware.com>
This commit is contained in:
parent
925f70a1ac
commit
4bf729caaf
@ -5,6 +5,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Masterminds/semver"
|
"github.com/Masterminds/semver"
|
||||||
@ -45,6 +47,7 @@ type ChartInfo struct {
|
|||||||
Name string
|
Name string
|
||||||
TotalVersions uint32 `json:"total_versions"`
|
TotalVersions uint32 `json:"total_versions"`
|
||||||
Created time.Time
|
Created time.Time
|
||||||
|
Updated time.Time
|
||||||
Icon string
|
Icon string
|
||||||
Home string
|
Home string
|
||||||
Deprecated bool
|
Deprecated bool
|
||||||
@ -135,6 +138,16 @@ func (cho *ChartOperator) GetChartList(content []byte) ([]*ChartInfo, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Sort the chart list by the updated time which is the create time
|
||||||
|
//of the latest version of the chart.
|
||||||
|
sort.Slice(chartList, func(i, j int) bool {
|
||||||
|
if chartList[i].Updated.Equal(chartList[j].Updated) {
|
||||||
|
return strings.Compare(chartList[i].Name, chartList[j].Name) < 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return chartList[i].Updated.After(chartList[j].Updated)
|
||||||
|
})
|
||||||
|
|
||||||
return chartList, nil
|
return chartList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,15 +35,8 @@ func TestGetChartList(t *testing.T) {
|
|||||||
t.Fatalf("Length of chart list should be 2, but we got %d now", len(infos))
|
t.Fatalf("Length of chart list should be 2, but we got %d now", len(infos))
|
||||||
}
|
}
|
||||||
|
|
||||||
foundHarbor := false
|
firstInSortedList := infos[0]
|
||||||
for _, chart := range infos {
|
if firstInSortedList.Name != "harbor" {
|
||||||
if chart.Name == "harbor" {
|
t.Fatalf("Expect the fist item of the sorted list to be 'harbor' but got '%s'", firstInSortedList.Name)
|
||||||
foundHarbor = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !foundHarbor {
|
|
||||||
t.Fatal("Expect chart named with 'harbor' but got nothing")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user