File tree 2 files changed +27
-1
lines changed
Filter options
2 files changed +27
-1
lines changed
Original file line number Diff line number Diff line change 8
8
"context"
9
9
"database/sql"
10
10
"fmt"
11
+ "sort"
11
12
"strconv"
12
13
"strings"
13
14
"sync"
@@ -336,7 +337,7 @@ func (c *baseCloning) GetSnapshots() ([]models.Snapshot, error) {
336
337
return snapshots , nil
337
338
}
338
339
339
- // GetClones returns all clones.
340
+ // GetClones returns the list of clones descend ordered by creation time .
340
341
func (c * baseCloning ) GetClones () []* models.Clone {
341
342
clones := make ([]* models.Clone , 0 , c .lenClones ())
342
343
@@ -346,6 +347,10 @@ func (c *baseCloning) GetClones() []*models.Clone {
346
347
}
347
348
c .cloneMutex .RUnlock ()
348
349
350
+ sort .Slice (clones , func (i , j int ) bool {
351
+ return clones [i ].CreatedAt > clones [j ].CreatedAt
352
+ })
353
+
349
354
return clones
350
355
}
351
356
Original file line number Diff line number Diff line change @@ -47,6 +47,27 @@ func (s *BaseCloningSuite) TestFindWrapper() {
47
47
assert .Equal (s .T (), CloneWrapper {clone : & models.Clone {ID : "testCloneID" }}, * wrapper )
48
48
}
49
49
50
+ func (s * BaseCloningSuite ) TestCloneList () {
51
+ clone1 := & models.Clone {CreatedAt : "2020-02-20 01:23:45 UTC" }
52
+ clone2 := & models.Clone {CreatedAt : "2020-06-23 10:31:27 UTC" }
53
+ clone3 := & models.Clone {CreatedAt : "2020-05-20 00:43:21 UTC" }
54
+
55
+ s .cloning .setWrapper ("testCloneID1" , & CloneWrapper {clone : clone1 })
56
+ s .cloning .setWrapper ("testCloneID2" , & CloneWrapper {clone : clone2 })
57
+ s .cloning .setWrapper ("testCloneID3" , & CloneWrapper {clone : clone3 })
58
+
59
+ list := s .cloning .GetClones ()
60
+
61
+ assert .Equal (s .T (), 3 , len (list ))
62
+
63
+ // Check clone order.
64
+ assert .Equal (s .T (), []* models.Clone {
65
+ {CreatedAt : "2020-06-23 10:31:27 UTC" },
66
+ {CreatedAt : "2020-05-20 00:43:21 UTC" },
67
+ {CreatedAt : "2020-02-20 01:23:45 UTC" },
68
+ }, list )
69
+ }
70
+
50
71
func (s * BaseCloningSuite ) TestUpdateStatus () {
51
72
s .cloning .setWrapper ("testCloneID" , & CloneWrapper {clone : & models.Clone {Status : models.Status {
52
73
Code : models .StatusCreating ,
You can’t perform that action at this time.
0 commit comments