Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sinbai committed Feb 5, 2025
1 parent cd74e7e commit 0a84785
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
12 changes: 10 additions & 2 deletions internal/services/mssql/mssql_database_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -1190,8 +1190,16 @@ func resourceMsSqlDatabaseRead(d *pluginsdk.ResourceData, meta interface{}) erro
d.Set("license_type", d.Get("license_type").(string))
}

// Get it from config as the API returns not the specified value but the maximum value.
d.Set("max_size_gb", d.Get("max_size_gb").(float64))
// when `max_size_gb` is below 1GB, the API only accepts 100MB and 500MB. 100MB is 104857600, and 500MB is 524288000.
// directly set `max_size_gb` when API returns `104857600` or `524288000`.
size := float64((pointer.From(props.MaxSizeBytes)) / int64(1073741824))
switch pointer.From(props.MaxSizeBytes) {
case 104857600:
size = 0.1
case 524288000:
size = 0.5
}
d.Set("max_size_gb", size)

if props.CurrentServiceObjectiveName != nil {
skuName = *props.CurrentServiceObjectiveName
Expand Down
38 changes: 19 additions & 19 deletions internal/services/mssql/mssql_database_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ func TestAccMsSqlDatabase_maxSizeGB(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("max_size_gb"),
data.ImportStep(),
{
Config: r.maxSizeGB(data, 0.5),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("max_size_gb"),
data.ImportStep(),
{
Config: r.maxSizeGB(data, 1),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("max_size_gb"),
data.ImportStep(),
})
}

Expand Down Expand Up @@ -125,7 +125,7 @@ func TestAccMsSqlDatabase_complete(t *testing.T) {
check.That(data.ResourceName).Key("tags.ENV").HasValue("Test"),
),
},
data.ImportStep("sample_name", "max_size_gb"),
data.ImportStep("sample_name"),
{
Config: r.update(data),
Check: acceptance.ComposeTestCheckFunc(
Expand All @@ -137,7 +137,7 @@ func TestAccMsSqlDatabase_complete(t *testing.T) {
check.That(data.ResourceName).Key("tags.ENV").HasValue("Staging"),
),
},
data.ImportStep("sample_name", "max_size_gb"),
data.ImportStep("sample_name"),
})
}

Expand Down Expand Up @@ -477,56 +477,56 @@ func TestAccMsSqlDatabase_scaleReplicaSet(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("sample_name", "license_type", "max_size_gb"),
data.ImportStep("sample_name", "license_type"),
{
Config: r.scaleReplicaSet(data, "P2"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("sample_name", "license_type", "max_size_gb"),
data.ImportStep("sample_name", "license_type"),
{
Config: r.scaleReplicaSet(data, "GP_Gen5_2"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("sample_name", "license_type", "max_size_gb"),
data.ImportStep("sample_name", "license_type"),
{
Config: r.scaleReplicaSet(data, "BC_Gen5_2"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("sample_name", "license_type", "max_size_gb"),
data.ImportStep("sample_name", "license_type"),
{
Config: r.scaleReplicaSet(data, "GP_Gen5_2"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("sample_name", "license_type", "max_size_gb"),
data.ImportStep("sample_name", "license_type"),
{
Config: r.scaleReplicaSet(data, "S2"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("sample_name", "license_type", "max_size_gb"),
data.ImportStep("sample_name", "license_type"),
{
Config: r.scaleReplicaSet(data, "Basic"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("sample_name", "license_type", "max_size_gb"),
data.ImportStep("sample_name", "license_type"),
{
Config: r.scaleReplicaSet(data, "S1"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("sample_name", "license_type", "max_size_gb"),
data.ImportStep("sample_name", "license_type"),
})
}

Expand All @@ -544,7 +544,7 @@ func TestAccMsSqlDatabase_scaleReplicaSetWithFailovergroup(t *testing.T) {
check.That(data.ResourceName).Key("sku_name").HasValue("GP_Gen5_2"),
),
},
data.ImportStep("max_size_gb"),
data.ImportStep(),
{
Config: r.scaleReplicaSetWithFailovergroup(data, "GP_Gen5_8", 25),
Check: acceptance.ComposeTestCheckFunc(
Expand All @@ -554,7 +554,7 @@ func TestAccMsSqlDatabase_scaleReplicaSetWithFailovergroup(t *testing.T) {
check.That(data.ResourceName).Key("sku_name").HasValue("GP_Gen5_8"),
),
},
data.ImportStep("max_size_gb"),
data.ImportStep(),
{
Config: r.scaleReplicaSetWithFailovergroup(data, "GP_Gen5_2", 5),
Check: acceptance.ComposeTestCheckFunc(
Expand All @@ -564,7 +564,7 @@ func TestAccMsSqlDatabase_scaleReplicaSetWithFailovergroup(t *testing.T) {
check.That(data.ResourceName).Key("sku_name").HasValue("GP_Gen5_2"),
),
},
data.ImportStep("max_size_gb"),
data.ImportStep(),
})
}

Expand Down Expand Up @@ -636,7 +636,7 @@ func TestAccMsSqlDatabase_threatDetectionPolicy(t *testing.T) {
check.That(data.ResourceName).Key("threat_detection_policy.0.email_account_admins").HasValue("Enabled"),
),
},
data.ImportStep("sample_name", "threat_detection_policy.0.storage_account_access_key", "max_size_gb"),
data.ImportStep("sample_name", "threat_detection_policy.0.storage_account_access_key"),
{
Config: r.threatDetectionPolicy(data, "Disabled"),
Check: acceptance.ComposeTestCheckFunc(
Expand All @@ -645,7 +645,7 @@ func TestAccMsSqlDatabase_threatDetectionPolicy(t *testing.T) {
check.That(data.ResourceName).Key("threat_detection_policy.0.state").HasValue("Disabled"),
),
},
data.ImportStep("sample_name", "threat_detection_policy.0.storage_account_access_key", "max_size_gb"),
data.ImportStep("sample_name", "threat_detection_policy.0.storage_account_access_key"),
})
}

Expand All @@ -663,7 +663,7 @@ func TestAccMsSqlDatabase_threatDetectionPolicyNoStorage(t *testing.T) {
check.That(data.ResourceName).Key("threat_detection_policy.0.storage_endpoint").IsEmpty(),
),
},
data.ImportStep("sample_name", "threat_detection_policy.0.storage_account_access_key", "max_size_gb"),
data.ImportStep("sample_name", "threat_detection_policy.0.storage_account_access_key"),
{
Config: r.threatDetectionPolicy(data, "Enabled"),
Check: acceptance.ComposeTestCheckFunc(
Expand Down

0 comments on commit 0a84785

Please sign in to comment.