github.com/GuanceCloud/cliutils@v1.1.21/point/sort_test.go (about) 1 // Unless explicitly stated otherwise all files in this repository are licensed 2 // under the MIT License. 3 // This product includes software developed at Guance Cloud (https://www.guance.com/). 4 // Copyright 2021-present Guance, Inc. 5 6 package point 7 8 import ( 9 T "testing" 10 "time" 11 12 "github.com/stretchr/testify/assert" 13 ) 14 15 func TestSortByTime(t *T.T) { 16 t.Run(`basic`, func(t *T.T) { 17 pts := []*Point{ 18 NewPointV2("p1", nil, WithTime(time.Now())), 19 NewPointV2("p2", nil, WithTime(time.Now().Add(-time.Hour))), 20 } 21 22 t.Logf("before sort pt[0]: %s", pts[0].Pretty()) 23 t.Logf("before sort pt[1]: %s", pts[1].Pretty()) 24 25 SortByTime(pts) 26 27 t.Logf("pt[0]: %s", pts[0].Pretty()) 28 t.Logf("pt[1]: %s", pts[1].Pretty()) 29 30 assert.Equal(t, "p2", pts[0].Name()) 31 assert.Equal(t, "p1", pts[1].Name()) 32 }) 33 }