Преглед изворни кода

Merge pull request #1847 from ameijer/alex/fix-unit-tests

[HOTFIX] fix compile issue with wrapped error, enhance flaky unit test
Sean Holcomb пре 3 година
родитељ
комит
db9d95f126
2 измењених фајлова са 6 додато и 2 уклоњено
  1. 1 1
      pkg/cmd/costmodel/costmodel.go
  2. 5 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() {

+ 5 - 1
pkg/kubecost/window_test.go

@@ -239,7 +239,11 @@ 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
+	// so we add one nanosecond to sure time.Now() is later than when invoked earlier
+	if !month.End().Before(time.Now().UTC().Add(time.Nanosecond)) {
 		t.Fatalf(`expect: window "month" to end before now; actual: %s ends after %s`, month, time.Now().UTC())
 	}