Ver código fonte

ASR.Minutes() does not return an error

Michael Dresser 4 anos atrás
pai
commit
ada46a75c9
2 arquivos alterados com 8 adições e 15 exclusões
  1. 4 4
      pkg/kubecost/allocation.go
  2. 4 11
      pkg/kubecost/allocation_test.go

+ 4 - 4
pkg/kubecost/allocation.go

@@ -2456,16 +2456,16 @@ func (asr *AllocationSetRange) End() (time.Time, error) {
 
 // Minutes returns the duration, in minutes, between the earliest start
 // and the latest end of all allocations in the AllocationSetRange.
-func (asr *AllocationSetRange) Minutes() (float64, error) {
+func (asr *AllocationSetRange) Minutes() float64 {
 	start, err := asr.Start()
 	if err != nil {
-		return 0, fmt.Errorf("failed to calculate start: %s", err)
+		return 0
 	}
 	end, err := asr.End()
 	if err != nil {
-		return 0, fmt.Errorf("failed to calculate end: %s", err)
+		return 0
 	}
 	duration := end.Sub(start)
 
-	return duration.Minutes(), nil
+	return duration.Minutes()
 }

+ 4 - 11
pkg/kubecost/allocation_test.go

@@ -2343,14 +2343,13 @@ func TestAllocationSetRange_Minutes(t *testing.T) {
 		name string
 		arg  *AllocationSetRange
 
-		expectError bool
-		expected    float64
+		expected float64
 	}{
 		{
 			name: "Empty ASR",
 			arg:  nil,
 
-			expectError: true,
+			expected: 0,
 		},
 		{
 			name: "Single allocation",
@@ -2418,14 +2417,8 @@ func TestAllocationSetRange_Minutes(t *testing.T) {
 	}
 
 	for _, test := range tests {
-		result, err := test.arg.Minutes()
-		if test.expectError && err != nil {
-			continue
-		}
-
-		if test.expectError && err == nil {
-			t.Errorf("%s: expected error and got none", test.name)
-		} else if result != test.expected {
+		result := test.arg.Minutes()
+		if result != test.expected {
 			t.Errorf("%s: expected %f but got %f", test.name, test.expected, result)
 		}
 	}