|
6 | 6 |
|
7 | 7 | "github.com/google/go-cmp/cmp" |
8 | 8 | "github.com/spectrocloud/palette-sdk-go/api/models" |
| 9 | + "github.com/spectrocloud/palette-sdk-go/client" |
9 | 10 | "github.com/stretchr/testify/assert" |
10 | 11 |
|
11 | 12 | "github.com/spectrocloud/terraform-provider-spectrocloud/types" |
@@ -94,18 +95,73 @@ func TestToEksCluster(t *testing.T) { |
94 | 95 | }, |
95 | 96 | }) |
96 | 97 |
|
97 | | - //client := &client.V1Client{} |
98 | | - // |
99 | | - //cluster, err := toEksCluster(client, d) |
100 | | - // |
101 | | - //assert.NoError(t, err, "Expected no error from toEksCluster") |
102 | | - //assert.Equal(t, "test-cluster", cluster.Metadata.Name, "Unexpected cluster name") |
103 | | - // |
104 | | - //assert.NotNil(t, cluster.Spec.Machinepoolconfig, "Expected MachinePools to be non-nil") |
105 | | - //assert.Equal(t, 2, len(cluster.Spec.Machinepoolconfig), "Expected one machine pool in the cluster") |
106 | | - // |
107 | | - //assert.Equal(t, "test-pool", *cluster.Spec.Machinepoolconfig[1].PoolConfig.Name, "Unexpected machine pool name") |
108 | | - //assert.Equal(t, int64(10), cluster.Spec.Machinepoolconfig[1].CloudConfig.RootDeviceSize, "Unexpected disk size") |
| 98 | + client := &client.V1Client{} |
| 99 | + |
| 100 | + cluster, err := toEksCluster(client, d) |
| 101 | + |
| 102 | + assert.NoError(t, err, "Expected no error from toEksCluster") |
| 103 | + assert.Equal(t, "test-cluster", cluster.Metadata.Name, "Unexpected cluster name") |
| 104 | + |
| 105 | + assert.NotNil(t, cluster.Spec.Machinepoolconfig, "Expected MachinePools to be non-nil") |
| 106 | + // Without az_subnets, no cp-pool should be added |
| 107 | + assert.Equal(t, 1, len(cluster.Spec.Machinepoolconfig), "Expected one machine pool in the cluster (no cp-pool)") |
| 108 | + |
| 109 | + assert.Equal(t, "test-pool", *cluster.Spec.Machinepoolconfig[0].PoolConfig.Name, "Unexpected machine pool name") |
| 110 | + assert.Equal(t, int64(10), cluster.Spec.Machinepoolconfig[0].CloudConfig.RootDeviceSize, "Unexpected disk size") |
| 111 | +} |
| 112 | + |
| 113 | +func TestToEksClusterWithAzSubnets(t *testing.T) { |
| 114 | + // Setup a dummy ResourceData for testing with az_subnets |
| 115 | + d := resourceClusterEks().TestResourceData() |
| 116 | + |
| 117 | + /* set the values of the ResourceData */ |
| 118 | + d.Set("name", "test-cluster-az") |
| 119 | + d.Set("context", "project") |
| 120 | + d.Set("tags", []interface{}{"tag1:value1", "tag2:value2"}) |
| 121 | + d.Set("cloud_account_id", "test-cloud-id") |
| 122 | + d.Set("cloud_config", []interface{}{ |
| 123 | + map[string]interface{}{ |
| 124 | + "ssh_key_name": "test-ssh-key", |
| 125 | + "region": "us-west-1", |
| 126 | + "vpc_id": "test-vpc-id", |
| 127 | + "endpoint_access": "public", |
| 128 | + "public_access_cidrs": []interface{}{"0.0.0.0/0"}, |
| 129 | + "encryption_config_arn": "arn:test:encryption", |
| 130 | + "az_subnets": map[string]interface{}{ |
| 131 | + "us-west-1a": "subnet-12345", |
| 132 | + "us-west-1b": "subnet-67890", |
| 133 | + }, |
| 134 | + }, |
| 135 | + }) |
| 136 | + d.Set("machine_pool", []interface{}{ |
| 137 | + map[string]interface{}{ |
| 138 | + "name": "test-pool", |
| 139 | + "disk_size_gb": 10, |
| 140 | + "count": 2, |
| 141 | + "instance_type": "t2.micro", |
| 142 | + "capacity_type": "on-demand", |
| 143 | + "update_strategy": "RollingUpdateScaleOut", |
| 144 | + }, |
| 145 | + }) |
| 146 | + |
| 147 | + client := &client.V1Client{} |
| 148 | + |
| 149 | + cluster, err := toEksCluster(client, d) |
| 150 | + |
| 151 | + assert.NoError(t, err, "Expected no error from toEksCluster") |
| 152 | + assert.Equal(t, "test-cluster-az", cluster.Metadata.Name, "Unexpected cluster name") |
| 153 | + |
| 154 | + assert.NotNil(t, cluster.Spec.Machinepoolconfig, "Expected MachinePools to be non-nil") |
| 155 | + // With az_subnets having more than one element, cp-pool should be added |
| 156 | + assert.Equal(t, 2, len(cluster.Spec.Machinepoolconfig), "Expected two machine pools in the cluster (cp-pool + test-pool)") |
| 157 | + |
| 158 | + // Check that cp-pool is the first one |
| 159 | + assert.Equal(t, "cp-pool", *cluster.Spec.Machinepoolconfig[0].PoolConfig.Name, "Expected first machine pool to be cp-pool") |
| 160 | + assert.True(t, cluster.Spec.Machinepoolconfig[0].PoolConfig.IsControlPlane, "Expected first machine pool to be control plane") |
| 161 | + |
| 162 | + // Check that test-pool is the second one |
| 163 | + assert.Equal(t, "test-pool", *cluster.Spec.Machinepoolconfig[1].PoolConfig.Name, "Expected second machine pool to be test-pool") |
| 164 | + assert.Equal(t, int64(10), cluster.Spec.Machinepoolconfig[1].CloudConfig.RootDeviceSize, "Unexpected disk size") |
109 | 165 | } |
110 | 166 |
|
111 | 167 | func TestToMachinePoolEks(t *testing.T) { |
|
0 commit comments