فهرست منبع

fix float issues

Signed-off-by: Cliff Colvin <ccolvin@kubecost.com>
Ajay Tripathy 2 سال پیش
والد
کامیت
c765841355
1فایلهای تغییر یافته به همراه49 افزوده شده و 24 حذف شده
  1. 49 24
      test/cloud_test.go

+ 49 - 24
test/cloud_test.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"math"
 	"os"
+	"strconv"
 	"strings"
 	"testing"
 	"time"
@@ -118,8 +119,10 @@ func TestPVPriceFromCSV(t *testing.T) {
 		t.Errorf("Error in NodePricing: %s", err.Error())
 	} else {
 		gotPrice := resPV.Cost
-		if gotPrice != wantPrice {
-			t.Errorf("Wanted price '%s' got price '%s'", wantPrice, gotPrice)
+		wantPriceFloat, _ := strconv.ParseFloat(wantPrice, 64)
+		gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
+		if gotPriceFloat != wantPriceFloat {
+			t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
 		}
 	}
 
@@ -150,8 +153,10 @@ func TestPVPriceFromCSVStorageClass(t *testing.T) {
 		t.Errorf("Error in NodePricing: %s", err.Error())
 	} else {
 		gotPrice := resPV.Cost
-		if gotPrice != wantPrice {
-			t.Errorf("Wanted price '%s' got price '%s'", wantPrice, gotPrice)
+		wantPriceFloat, _ := strconv.ParseFloat(wantPrice, 64)
+		gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
+		if gotPriceFloat != wantPriceFloat {
+			t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
 		}
 	}
 
@@ -203,8 +208,10 @@ func TestNodePriceFromCSVWithGPU(t *testing.T) {
 		if gotGPU != wantGPU {
 			t.Errorf("Wanted gpu count '%s' got gpu count '%s'", wantGPU, gotGPU)
 		}
-		if gotPrice != wantPrice {
-			t.Errorf("Wanted price '%s' got price '%s'", wantPrice, gotPrice)
+		wantPriceFloat, _ := strconv.ParseFloat(wantPrice, 64)
+		gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
+		if gotPriceFloat != wantPriceFloat {
+			t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
 		}
 
 	}
@@ -219,8 +226,10 @@ func TestNodePriceFromCSVWithGPU(t *testing.T) {
 		if gotGPU != wantGPU {
 			t.Errorf("Wanted gpu count '%s' got gpu count '%s'", wantGPU, gotGPU)
 		}
-		if gotPrice != wantPrice2 {
-			t.Errorf("Wanted price '%s' got price '%s'", wantPrice2, gotPrice)
+		wantPriceFloat, _ := strconv.ParseFloat(wantPrice2, 64)
+		gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
+		if gotPriceFloat != wantPriceFloat {
+			t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
 		}
 
 	}
@@ -254,8 +263,10 @@ func TestNodePriceFromCSVSpecialChar(t *testing.T) {
 		t.Errorf("Error in NodePricing: %s", err.Error())
 	} else {
 		gotPrice := resN.Cost
-		if gotPrice != wantPrice {
-			t.Errorf("Wanted price '%s' got price '%s'", wantPrice, gotPrice)
+		wantPriceFloat, _ := strconv.ParseFloat(wantPrice, 64)
+		gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
+		if gotPriceFloat != wantPriceFloat {
+			t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
 		}
 	}
 }
@@ -290,8 +301,10 @@ func TestNodePriceFromCSV(t *testing.T) {
 		t.Errorf("Error in NodePricing: %s", err.Error())
 	} else {
 		gotPrice := resN.Cost
-		if gotPrice != wantPrice {
-			t.Errorf("Wanted price '%s' got price '%s'", wantPrice, gotPrice)
+		wantPriceFloat, _ := strconv.ParseFloat(wantPrice, 64)
+		gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
+		if gotPriceFloat != wantPriceFloat {
+			t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
 		}
 	}
 
@@ -366,8 +379,10 @@ func TestNodePriceFromCSVWithRegion(t *testing.T) {
 		t.Errorf("Error in NodePricing: %s", err.Error())
 	} else {
 		gotPrice := resN.Cost
-		if gotPrice != wantPrice {
-			t.Errorf("Wanted price '%s' got price '%s'", wantPrice, gotPrice)
+		wantPriceFloat, _ := strconv.ParseFloat(wantPrice, 64)
+		gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
+		if gotPriceFloat != wantPriceFloat {
+			t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
 		}
 	}
 	k2 := c.GetKey(n2.Labels, n2)
@@ -376,8 +391,10 @@ func TestNodePriceFromCSVWithRegion(t *testing.T) {
 		t.Errorf("Error in NodePricing: %s", err.Error())
 	} else {
 		gotPrice := resN2.Cost
-		if gotPrice != wantPrice2 {
-			t.Errorf("Wanted price '%s' got price '%s'", wantPrice2, gotPrice)
+		wantPriceFloat, _ := strconv.ParseFloat(wantPrice2, 64)
+		gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
+		if gotPriceFloat != wantPriceFloat {
+			t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
 		}
 	}
 	k3 := c.GetKey(n3.Labels, n3)
@@ -386,8 +403,10 @@ func TestNodePriceFromCSVWithRegion(t *testing.T) {
 		t.Errorf("Error in NodePricing: %s", err.Error())
 	} else {
 		gotPrice := resN3.Cost
-		if gotPrice != wantPrice3 {
-			t.Errorf("Wanted price '%s' got price '%s'", wantPrice3, gotPrice)
+		wantPriceFloat, _ := strconv.ParseFloat(wantPrice3, 64)
+		gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
+		if gotPriceFloat != wantPriceFloat {
+			t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
 		}
 	}
 
@@ -572,8 +591,10 @@ func TestNodePriceFromCSVWithCase(t *testing.T) {
 		t.Errorf("Error in NodePricing: %s", err.Error())
 	} else {
 		gotPrice := resN.Cost
-		if gotPrice != wantPrice {
-			t.Errorf("Wanted price '%s' got price '%s'", wantPrice, gotPrice)
+		wantPriceFloat, _ := strconv.ParseFloat(wantPrice, 64)
+		gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
+		if gotPriceFloat != wantPriceFloat {
+			t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
 		}
 	}
 
@@ -615,8 +636,10 @@ func TestNodePriceFromCSVMixed(t *testing.T) {
 		t.Errorf("Error in NodePricing: %s", err.Error())
 	} else {
 		gotPrice := resN.Cost
-		if gotPrice != wantPrice {
-			t.Errorf("Wanted price '%s' got price '%s'", wantPrice, gotPrice)
+		wantPriceFloat, _ := strconv.ParseFloat(wantPrice, 64)
+		gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
+		if gotPriceFloat != wantPriceFloat {
+			t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
 		}
 	}
 	k2 := c.GetKey(n2.Labels, n2)
@@ -625,8 +648,10 @@ func TestNodePriceFromCSVMixed(t *testing.T) {
 		t.Errorf("Error in NodePricing: %s", err.Error())
 	} else {
 		gotPrice := resN2.Cost
-		if gotPrice != wantPrice2 {
-			t.Errorf("Wanted price '%s' got price '%s'", wantPrice2, gotPrice)
+		wantPriceFloat, _ := strconv.ParseFloat(wantPrice2, 64)
+		gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
+		if gotPriceFloat != wantPriceFloat {
+			t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
 		}
 	}