Procházet zdrojové kódy

Fix a test that relies on Prom library (#2432)

We were assuming that the library always returns seconds, but it can
now also return minutes (presumably if the seconds divide well). This is
probably failing due to an update of that library.

Signed-off-by: Michael Dresser <michaelmdresser@gmail.com>
Michael Dresser před 2 roky
rodič
revize
245fbc8b19
1 změnil soubory, kde provedl 8 přidání a 4 odebrání
  1. 8 4
      pkg/kubecost/window_test.go

+ 8 - 4
pkg/kubecost/window_test.go

@@ -667,13 +667,17 @@ func TestWindow_DurationOffsetForPrometheus(t *testing.T) {
 	}
 
 	dur, off, err := w.DurationOffsetForPrometheus()
-	expDur := int(now.Sub(startOfToday).Seconds())
-	expDurStr := fmt.Sprintf("%ds", expDur)
 	if err != nil {
 		t.Fatalf("unexpected error: %s", err)
 	}
-	if dur != expDurStr {
-		t.Fatalf(`expect: window to be "%s"; actual: "%s"`, expDurStr, dur)
+	// We can get a response in seconds OR minutes. Check seconds first as it
+	// is higher resolution.
+	expDurSec := int(now.Sub(startOfToday).Seconds())
+	expDurSecStr := fmt.Sprintf("%ds", expDurSec)
+	expDurMin := int(now.Sub(startOfToday).Minutes())
+	expDurMinStr := fmt.Sprintf("%dm", expDurMin)
+	if dur != expDurSecStr && dur != expDurMinStr {
+		t.Fatalf(`expect: window to be "%s" (or "%s"); actual: "%s"`, expDurSecStr, expDurMinStr, dur)
 	}
 	if off != "" {
 		t.Fatalf(`expect: offset to be ""; actual: "%s"`, off)