ref: f79a9d09c451653ff27fb34afb5b0c71dc758a32
server/db/dates_test.go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
package db import ( "fmt" "os" "testing" "time" "yats-server/dates" "yats-server/model" ) func TestTodayString(t *testing.T) { daysRange := CalculateDaysRange() fmt.Printf("from: %s to: %s\n", daysRange.From, daysRange.To) } func TestManyDaysAgo(t *testing.T) { daysRange := DaysAgo(10) fmt.Printf("from: %s to: %s\n", daysRange.From, daysRange.To) } func CalculateDaysRange() dates.DaysRange { currentTime := time.Now() yesterday := currentTime.AddDate(0, 0, -1) fmt.Println("today YYYY-MM-DD : ", currentTime.Format("2006-02-01")) fmt.Println("yesterday YYYY-MM-DD : ", yesterday.Format("2006-02-01")) return dates.DaysRange{yesterday.Format("2006-02-01"), currentTime.Format("2006-02-01")} } func DaysAgo(n int) dates.DaysRange { currentTime := time.Now().AddDate(0, 0, n*(-1)) yesterday := currentTime.AddDate(0, 0, -1) fmt.Println("today YYYY-MM-DD : ", currentTime.Format("2006-02-01")) fmt.Println("yesterday YYYY-MM-DD : ", yesterday.Format("2006-02-01")) return dates.DaysRange{yesterday.Format("2006-02-01"), currentTime.Format("2006-02-01")} } func TestParquet(t *testing.T) { event := model.EventRequest{ ID_client: "abc", Etime: int64(time.Now().UnixMilli()), Name: "SomeTest", } tmpFile, _ := os.CreateTemp("/tmp/", "tempEvent-XXXX.parquet") EventToParquet([]model.EventRequest{event}, tmpFile.Name()) metric := model.MetricRequest{ ID_client: "mabc", Mtime: int64(time.Now().UnixMilli()), Name: "someName", Value: "SomeValue", } tmpMetricFile, _ := os.CreateTemp("/tmp/", "tempMetric-XXXX.parquet") MetricToParquet([]model.MetricRequest{metric}, tmpMetricFile.Name()) } |