|
|
@@ -112,6 +112,20 @@ func TestProcessDescribePriceAndCreateAlibabaPricing(t *testing.T) {
|
|
|
},
|
|
|
expectedError: nil,
|
|
|
},
|
|
|
+ {
|
|
|
+ name: "test General Purpose Type g8a instance family",
|
|
|
+ teststruct: &SlimK8sNode{
|
|
|
+ InstanceType: "ecs.g8a.8xlarge",
|
|
|
+ RegionID: "cn-hangzhou",
|
|
|
+ PriceUnit: "Hour",
|
|
|
+ MemorySizeInKiB: "33554432KiB",
|
|
|
+ IsIoOptimized: true,
|
|
|
+ OSType: "Linux",
|
|
|
+ ProviderID: "cn-hangzhou.i-test-01c",
|
|
|
+ InstanceTypeFamily: "g8a",
|
|
|
+ },
|
|
|
+ expectedError: nil,
|
|
|
+ },
|
|
|
{
|
|
|
name: "test Enhanced General Purpose Type g6e instance family",
|
|
|
teststruct: &SlimK8sNode{
|
|
|
@@ -856,3 +870,108 @@ func TestDeterminePVRegion(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+func TestGetInstanceFamilyGenerationFromType(t *testing.T) {
|
|
|
+ cases := []struct {
|
|
|
+ name string
|
|
|
+ instanceType string
|
|
|
+ expectedInstanceFamilyGeneration int
|
|
|
+ }{
|
|
|
+ {
|
|
|
+ name: "test if ecs.[instance-family].[different-type] work",
|
|
|
+ instanceType: "ecs.sn2ne.2xlarge",
|
|
|
+ expectedInstanceFamilyGeneration: 2,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "test if ecs.[instance-family].[different-type] work",
|
|
|
+ instanceType: "ecs.g7.large",
|
|
|
+ expectedInstanceFamilyGeneration: 7,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "test if random word gives you ALIBABA_UNKNOWN_INSTANCE_FAMILY_TYPE value ",
|
|
|
+ instanceType: "random.value",
|
|
|
+ expectedInstanceFamilyGeneration: -1,
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, c := range cases {
|
|
|
+ t.Run(c.name, func(t *testing.T) {
|
|
|
+ returnValue := getInstanceFamilyGenerationFromType(c.instanceType)
|
|
|
+ if returnValue != c.expectedInstanceFamilyGeneration {
|
|
|
+ t.Fatalf("Case name %s: expected instance family generation of type %d but got %d", c.name, c.expectedInstanceFamilyGeneration, returnValue)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestCreateDescribeNodePriceACSRequest(t *testing.T) {
|
|
|
+
|
|
|
+ cases := []struct {
|
|
|
+ name string
|
|
|
+ testStruct interface{}
|
|
|
+ expectedError error
|
|
|
+ expectedDiskCategory string
|
|
|
+ }{
|
|
|
+ {
|
|
|
+ // Test case for instance type ecs.g6.large
|
|
|
+ name: "test request parma when instance type is ecs.g6.large",
|
|
|
+ testStruct: &SlimK8sNode{
|
|
|
+ InstanceType: "ecs.g6.large",
|
|
|
+ RegionID: "cn-hangzhou",
|
|
|
+ PriceUnit: "Hour",
|
|
|
+ MemorySizeInKiB: "16KiB",
|
|
|
+ IsIoOptimized: true,
|
|
|
+ OSType: "Linux",
|
|
|
+ ProviderID: "Ali-XXX-node-01",
|
|
|
+ InstanceTypeFamily: "g6",
|
|
|
+ },
|
|
|
+ expectedError: nil,
|
|
|
+ expectedDiskCategory: "",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ // Test case for instance type ecs.g7.large
|
|
|
+ name: "test request parma when instance type is ecs.g7.large",
|
|
|
+ testStruct: &SlimK8sNode{
|
|
|
+ InstanceType: "ecs.g7.large",
|
|
|
+ RegionID: "cn-hangzhou",
|
|
|
+ PriceUnit: "Hour",
|
|
|
+ MemorySizeInKiB: "16KiB",
|
|
|
+ IsIoOptimized: true,
|
|
|
+ OSType: "Linux",
|
|
|
+ ProviderID: "Ali-XXX-node-02",
|
|
|
+ InstanceTypeFamily: "g7",
|
|
|
+ },
|
|
|
+ expectedError: nil,
|
|
|
+ expectedDiskCategory: ALIBABA_DISK_CLOUD_ESSD_CATEGORY,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ // Test case for instance type ecs.g7.large, this instance type is in 'alibabaDefaultToCloudEssd'
|
|
|
+ name: "test request parma when instance type is ecs.g6e.large",
|
|
|
+ testStruct: &SlimK8sNode{
|
|
|
+ InstanceType: "ecs.g6e.large",
|
|
|
+ RegionID: "cn-hangzhou",
|
|
|
+ PriceUnit: "Hour",
|
|
|
+ MemorySizeInKiB: "16KiB",
|
|
|
+ IsIoOptimized: true,
|
|
|
+ OSType: "Linux",
|
|
|
+ ProviderID: "Ali-XXX-node-03",
|
|
|
+ InstanceTypeFamily: "g6e",
|
|
|
+ },
|
|
|
+ expectedError: nil,
|
|
|
+ expectedDiskCategory: ALIBABA_DISK_CLOUD_ESSD_CATEGORY,
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, c := range cases {
|
|
|
+ t.Run(c.name, func(t *testing.T) {
|
|
|
+ req, err := createDescribePriceACSRequest(c.testStruct)
|
|
|
+ t.Logf("Request Params SystemDisk.Category: %v", req.QueryParams["SystemDisk.Category"])
|
|
|
+ if err != nil && c.expectedError != nil {
|
|
|
+ t.Fatalf("Case name %s: Error converting to Alibaba cloud request", c.name)
|
|
|
+ }
|
|
|
+ if c.expectedDiskCategory != req.QueryParams["SystemDisk.Category"] {
|
|
|
+ t.Fatalf("Case name %s: Disk Category is not set correctly", c.name)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|