Bladeren bron

[HOTFIX] fix compile issue with wrapped error, enhance flaky unit test

Signed-off-by: Alex Meijer <ameijer@kubecost.com>
Alex Meijer 3 jaren geleden
bovenliggende
commit
db3bd2c3db
2 gewijzigde bestanden met toevoegingen van 5 en 2 verwijderingen
  1. 1 1
      pkg/cmd/costmodel/costmodel.go
  2. 4 1
      pkg/kubecost/window_test.go

+ 1 - 1
pkg/cmd/costmodel/costmodel.go

@@ -58,7 +58,7 @@ func StartExportWorker(ctx context.Context, model costmodel.AllocationModel) {
 
 	fm, err := filemanager.NewFileManager(exportPath)
 	if err != nil {
-		log.Errorf("could not start CSV exporter", err)
+		log.Errorf("could not start CSV exporter: %v", err)
 		return
 	}
 	go func() {

+ 4 - 1
pkg/kubecost/window_test.go

@@ -239,7 +239,10 @@ func TestParseWindowUTC(t *testing.T) {
 	if month.Duration().Hours() > hoursThisMonth || month.Duration().Hours() < (hoursThisMonth-24.0) {
 		t.Fatalf(`expect: window "month" to have approximately %f hours; actual: %f hours`, hoursThisMonth, month.Duration().Hours())
 	}
-	if !month.End().Before(time.Now().UTC()) {
+
+	// this test fails periodically if execution is so fast that time.Now() during the condition
+	// check is the same as the end of the current month time computed by ParseWindowUTC
+	if !month.End().Before(time.Now().UTC().Add(time.Nanosecond * 1)) {
 		t.Fatalf(`expect: window "month" to end before now; actual: %s ends after %s`, month, time.Now().UTC())
 	}