github.com/DelineaXPM/dsv-cli@v1.40.6/tests/e2e/cmd_usage_test.go (about) 1 //go:build endtoend 2 // +build endtoend 3 4 package e2e 5 6 import ( 7 "fmt" 8 "testing" 9 "time" 10 ) 11 12 func TestUsage(t *testing.T) { 13 now := time.Now() 14 current := now.Format("2006-01-02") 15 pastSevenDays := now.AddDate(0, 0, -7).Format("2006-01-02") 16 futureSevenDays := now.AddDate(0, 0, 7).Format("2006-01-02") 17 18 output := runWithProfile(t, fmt.Sprintf("usage --enddate %s", futureSevenDays)) 19 requireContains(t, output, "error: must specify --startdate") 20 21 // If `--enddate` is not used, today's date should be assumed. 22 output = runWithProfile(t, fmt.Sprintf("usage --startdate %s", pastSevenDays)) 23 requireContains(t, output, fmt.Sprintf(`"startDate": "%s"`, pastSevenDays)) 24 requireContains(t, output, fmt.Sprintf(`"endDate": "%s"`, current)) 25 26 // Test when `--enddate` is used. 27 output = runWithProfile(t, fmt.Sprintf( 28 "usage --startdate %s --enddate %s", pastSevenDays, futureSevenDays, 29 )) 30 requireContains(t, output, fmt.Sprintf(`"startDate": "%s"`, pastSevenDays)) 31 requireContains(t, output, fmt.Sprintf(`"endDate": "%s"`, futureSevenDays)) 32 }