github.com/grafana/pyroscope@v1.18.0/pkg/querier/timeline/calculator_test.go (about) 1 package timeline_test 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/stretchr/testify/assert" 8 9 "github.com/grafana/pyroscope/pkg/querier/timeline" 10 ) 11 12 func Test_CalcPointInterval(t *testing.T) { 13 TestDate := time.Date(2023, time.April, 18, 1, 2, 3, 4, time.UTC) 14 15 testCases := []struct { 16 name string 17 start time.Time 18 end time.Time 19 want int64 20 }{ 21 {name: "1 second", start: TestDate, end: TestDate.Add(1 * time.Second), want: 15}, 22 {name: "1 hour", start: TestDate, end: TestDate.Add(1 * time.Hour), want: 15}, 23 {name: "7 days", start: TestDate, end: TestDate.Add(7 * 24 * time.Hour), want: 300}, 24 {name: "30 days", start: TestDate, end: TestDate.Add(30 * 24 * time.Hour), want: 1800}, 25 {name: "90 days", start: TestDate, end: TestDate.Add(30 * 24 * time.Hour), want: 1800}, 26 {name: "~6 months", start: TestDate, end: TestDate.Add(6 * 30 * 24 * time.Hour), want: 10800}, 27 {name: "~1 year", start: TestDate, end: TestDate.Add(12 * 30 * 24 * time.Hour), want: 21600}, 28 {name: "~2 years", start: TestDate, end: TestDate.Add(2 * 12 * 30 * 24 * time.Hour), want: 43200}, 29 {name: "~5 years", start: TestDate, end: TestDate.Add(5 * 12 * 30 * 24 * time.Hour), want: 86400}, 30 } 31 32 for _, tc := range testCases { 33 t.Run(tc.name, func(t *testing.T) { 34 got := timeline.CalcPointInterval(tc.start.UnixMilli(), tc.end.UnixMilli()) 35 36 assert.Equal(t, float64(tc.want), got) 37 }) 38 } 39 40 }