소스 검색

Add additional NodePricing tests for AWS and Alibaba providers

Extend test coverage for the enhanced diagnostic logging:
- Alibaba: Add test for fallback key success case
- AWS: Add tests for success and invalid key cases

Signed-off-by: Warwick Peatey <warwick.peatey@ibm.com>
Claude 3 달 전
부모
커밋
9e711ff2c1
2개의 변경된 파일96개의 추가작업 그리고 0개의 파일을 삭제
  1. 34 0
      pkg/cloud/alibaba/provider_test.go
  2. 62 0
      pkg/cloud/aws/provider_test.go

+ 34 - 0
pkg/cloud/alibaba/provider_test.go

@@ -1140,6 +1140,40 @@ func TestNodePricing_Error(t *testing.T) {
 	}
 }
 
+func TestNodePricing_FallbackSuccess(t *testing.T) {
+	// Test the case where the primary key (with disk info) is not found,
+	// but the fallback key (without disk info) is found
+	fallbackKey := "r::i::os"
+	a := &Alibaba{
+		Pricing: map[string]*AlibabaPricing{
+			fallbackKey: {
+				Node: &models.Node{
+					Cost: "0.05",
+					VCPU: "2",
+				},
+			},
+		},
+	}
+	// Key with disk info that won't match, but fallback without disk will match
+	dummyKey := &AlibabaNodeKey{
+		ProviderID:         "foo",
+		RegionID:           "r",
+		InstanceType:       "i",
+		OSType:             "os",
+		SystemDiskCategory: "cloud_ssd", // This makes the primary key different
+	}
+	node, _, err := a.NodePricing(dummyKey)
+	if err != nil {
+		t.Fatalf("NodePricing should succeed with fallback key, got error: %v", err)
+	}
+	if node == nil {
+		t.Fatalf("NodePricing should return node")
+	}
+	if node.Cost != "0.05" {
+		t.Fatalf("Expected cost 0.05, got %s", node.Cost)
+	}
+}
+
 func TestGpuPricing(t *testing.T) {
 	a := &Alibaba{}
 	v, err := a.GpuPricing(nil)

+ 62 - 0
pkg/cloud/aws/provider_test.go

@@ -797,3 +797,65 @@ func TestAWS_getFargatePod(t *testing.T) {
 		})
 	}
 }
+
+func TestNodePricing_Success(t *testing.T) {
+	aws := &AWS{
+		Pricing: map[string]*AWSProductTerms{
+			"us-east-1,m5.large,linux": {
+				OnDemand: &AWSOfferTerm{
+					PriceDimensions: map[string]*AWSRateCode{
+						"test": {
+							PricePerUnit: AWSCurrencyCode{USD: "0.096"},
+						},
+					},
+				},
+			},
+		},
+		ValidPricingKeys: map[string]bool{"us-east-1,m5.large,linux": true},
+		BaseCPUPrice:     "0.01",
+		BaseRAMPrice:     "0.001",
+		BaseGPUPrice:     "0.1",
+	}
+
+	key := &awsKey{
+		Labels: map[string]string{
+			v1.LabelTopologyRegion:     "us-east-1",
+			v1.LabelInstanceTypeStable: "m5.large",
+			v1.LabelOSStable:           "linux",
+		},
+	}
+
+	node, _, err := aws.NodePricing(key)
+	if err != nil {
+		t.Fatalf("NodePricing should succeed, got error: %v", err)
+	}
+	if node == nil {
+		t.Fatalf("NodePricing should return node")
+	}
+}
+
+func TestNodePricing_InvalidKey(t *testing.T) {
+	aws := &AWS{
+		Pricing:          map[string]*AWSProductTerms{},
+		ValidPricingKeys: map[string]bool{},
+		BaseCPUPrice:     "0.01",
+		BaseRAMPrice:     "0.001",
+		BaseGPUPrice:     "0.1",
+	}
+
+	key := &awsKey{
+		Labels: map[string]string{
+			v1.LabelTopologyRegion:     "unknown-region",
+			v1.LabelInstanceTypeStable: "unknown.type",
+			v1.LabelOSStable:           "linux",
+		},
+	}
+
+	node, _, err := aws.NodePricing(key)
+	if err == nil {
+		t.Fatalf("NodePricing should return error for invalid key")
+	}
+	if node != nil {
+		t.Fatalf("NodePricing should return nil node for invalid key")
+	}
+}