From 3c3a3d8446c4ecc1f2a50ab231db56d934356998 Mon Sep 17 00:00:00 2001 From: Andrii Chebukin Date: Fri, 25 Oct 2024 16:30:54 +0400 Subject: [PATCH] Fixed tests related to storage changes --- .editorconfig | 5 ++- src/Farmer/Arm/Storage.fs | 22 ++++++----- src/Farmer/Types.fs | 19 ++++++--- src/Tests/JsonRegression.fs | 2 +- src/Tests/Storage.fs | 46 ++++++++++++++-------- src/Tests/VirtualMachine.fs | 2 +- src/Tests/test-data/diagnostics.json | 2 +- src/Tests/test-data/event-grid.json | 4 +- src/Tests/test-data/lots-of-resources.json | 10 ++--- src/Tests/test-data/vm.json | 4 +- 10 files changed, 71 insertions(+), 45 deletions(-) diff --git a/.editorconfig b/.editorconfig index 6b24cb92d..0defd3d1d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,4 +9,7 @@ insert_final_newline = false [*.{fs,fsx}] fsharp_multiline_bracket_style = stroustrup -fsharp_newline_before_multiline_computation_expression = false \ No newline at end of file +fsharp_newline_before_multiline_computation_expression = false + +[*.json] +indent_size = 2 diff --git a/src/Farmer/Arm/Storage.fs b/src/Farmer/Arm/Storage.fs index 3bbfdb70b..20d968052 100644 --- a/src/Farmer/Arm/Storage.fs +++ b/src/Farmer/Arm/Storage.fs @@ -175,8 +175,8 @@ type StorageAccount = { | Blobs _ -> "BlobStorage" | Files _ -> "FileStorage" | BlockBlobs _ -> "BlockBlobStorage" - extendedLocation = "" // TODO: - identity = "" // TODO: user assigned identityt + extendedLocation = None // TODO: + identity = None // TODO: user assigned identity properties = {| accessTier = match this.Sku with @@ -206,13 +206,15 @@ type StorageAccount = { defaultAction = networkRuleSet.DefaultAction.ArmValue |}) |> Option.defaultValue Unchecked.defaultof<_> - allowBlobPublicAccess = this.DisableBlobPublicAccess.BooleanValue() - allowSharedKeyAccess = this.DisableSharedKeyAccess.BooleanValue() - defaultToOAuthAuthentication = this.DefaultToOAuthAuthentication.BooleanValue() + allowBlobPublicAccess = this.DisableBlobPublicAccess.AsInvertedBoolean() + allowSharedKeyAccess = this.DisableSharedKeyAccess.AsInvertedBoolean() + defaultToOAuthAuthentication = this.DefaultToOAuthAuthentication.AsBoolean() dnsEndpointType = this.DnsZoneType |> Option.toObj - encryption = {| - requireInfrastructureEncryption = this.RequireInfrastructureEncryption |> Option.toNullable - |} + encryption = + this.RequireInfrastructureEncryption + |> Option.map (fun _ -> {| + requireInfrastructureEncryption = this.RequireInfrastructureEncryption + |}) immutableStorageWithVersioning = this.ImmutableStorageWithVersioning |> Option.map (fun immutableStorage -> {| @@ -229,8 +231,8 @@ type StorageAccount = { |}) isHnsEnabled = this.EnableHierarchicalNamespace |> Option.toNullable minimumTlsVersion = this.MinTlsVersion.ArmValue() - publicNetworkAccess = this.DisablePublicNetworkAccess.ArmValue() - supportsHttpsTrafficOnly = this.SupportsHttpsTrafficOnly.BooleanValue() + publicNetworkAccess = this.DisablePublicNetworkAccess.ArmInvertedValue() + supportsHttpsTrafficOnly = this.SupportsHttpsTrafficOnly.AsBoolean() |} |} diff --git a/src/Farmer/Types.fs b/src/Farmer/Types.fs index 1f94f753a..e3c8138b1 100644 --- a/src/Farmer/Types.fs +++ b/src/Farmer/Types.fs @@ -417,16 +417,21 @@ type FeatureFlag = | Enabled -> true | Disabled -> false - member this.BooleanValue = + member this.AsInvertedBoolean = match this with - | Enabled -> "true" - | Disabled -> "false" + | Enabled -> false + | Disabled -> true member this.ArmValue = match this with | Enabled -> "Enabled" | Disabled -> "Disabled" + member this.ArmInvertedValue = + match this with + | Enabled -> "Disabled" + | Disabled -> "Enabled" + [] type FeatureFlagExtensions = @@ -435,13 +440,17 @@ type FeatureFlagExtensions = featureFlag |> Option.map (fun f -> f.AsBoolean) |> Option.toNullable [] - static member BooleanValue(featureFlag: FeatureFlag option) = - featureFlag |> Option.map (fun f -> f.BooleanValue) |> Option.toObj + static member AsInvertedBoolean(featureFlag: FeatureFlag option) = + featureFlag |> Option.map (fun f -> f.AsInvertedBoolean) |> Option.toNullable [] static member ArmValue(featureFlag: FeatureFlag option) = featureFlag |> Option.map (fun f -> f.ArmValue) |> Option.toObj + [] + static member ArmInvertedValue(featureFlag: FeatureFlag option) = + featureFlag |> Option.map (fun f -> f.ArmInvertedValue) |> Option.toObj + module FeatureFlag = let ofBool enabled = if enabled then Enabled else Disabled let toBool (flag: FeatureFlag) = flag.AsBoolean diff --git a/src/Tests/JsonRegression.fs b/src/Tests/JsonRegression.fs index d55fb6e11..e65b538ed 100644 --- a/src/Tests/JsonRegression.fs +++ b/src/Tests/JsonRegression.fs @@ -329,7 +329,7 @@ let tests = test "Can parse JSON into an ARM template" { let json = """ { - "apiVersion": "2019-06-01", + "apiVersion": "2023-05-01", "dependsOn": [], "kind": "StorageV2", "location": "northeurope", diff --git a/src/Tests/Storage.fs b/src/Tests/Storage.fs index 35c7fa4e5..9da8e4c5b 100644 --- a/src/Tests/Storage.fs +++ b/src/Tests/Storage.fs @@ -456,7 +456,7 @@ let tests = Expect.equal builder.WebsitePrimaryEndpoint.Value - "reference(resourceId('Microsoft.Storage/storageAccounts', 'foo'), '2022-05-01').primaryEndpoints.web" + "reference(resourceId('Microsoft.Storage/storageAccounts', 'foo'), '2023-05-01').primaryEndpoints.web" "Zone names are not fixed and should be related to a storage account name" } test "Creates different SKU kinds correctly" { @@ -736,8 +736,10 @@ let tests = let jobj = jsn |> Newtonsoft.Json.Linq.JObject.Parse Expect.equal - (jobj.SelectToken("resources[0].properties.supportsHttpsTrafficOnly").ToString()) - "false" + (jobj + .SelectToken("resources[0].properties.supportsHttpsTrafficOnly") + .ToObject()) + false "https traffic only should be disabled" } @@ -754,8 +756,10 @@ let tests = let jobj = jsn |> Newtonsoft.Json.Linq.JObject.Parse Expect.equal - (jobj.SelectToken("resources[0].properties.supportsHttpsTrafficOnly").ToString()) - "true" + (jobj + .SelectToken("resources[0].properties.supportsHttpsTrafficOnly") + .ToObject()) + true "https traffic only should be enabled" } @@ -863,8 +867,10 @@ let tests = let jobj = jsn |> Newtonsoft.Json.Linq.JObject.Parse Expect.equal - (jobj.SelectToken("resources[0].properties.allowBlobPublicAccess").ToString()) - "false" + (jobj + .SelectToken("resources[0].properties.allowBlobPublicAccess") + .ToObject()) + false "blob public access should be disabled" } @@ -882,8 +888,10 @@ let tests = let jobj = jsn |> Newtonsoft.Json.Linq.JObject.Parse Expect.equal - (jobj.SelectToken("resources[0].properties.allowBlobPublicAccess").ToString()) - "true" + (jobj + .SelectToken("resources[0].properties.allowBlobPublicAccess") + .ToObject()) + true "blob public access should be enabled" } @@ -900,8 +908,10 @@ let tests = let jobj = jsn |> Newtonsoft.Json.Linq.JObject.Parse Expect.equal - (jobj.SelectToken("resources[0].properties.allowSharedKeyAccess").ToString()) - "false" + (jobj + .SelectToken("resources[0].properties.allowSharedKeyAccess") + .ToObject()) + false "shared key access should be disabled" } @@ -919,8 +929,10 @@ let tests = let jobj = jsn |> Newtonsoft.Json.Linq.JObject.Parse Expect.equal - (jobj.SelectToken("resources[0].properties.allowSharedKeyAccess").ToString()) - "true" + (jobj + .SelectToken("resources[0].properties.allowSharedKeyAccess") + .ToObject()) + true "shared key access should be enabled" } @@ -939,8 +951,8 @@ let tests = Expect.equal (jobj .SelectToken("resources[0].properties.defaultToOAuthAuthentication") - .ToString()) - "true" + .ToObject()) + true "default to OAuth should be enabled" } @@ -960,8 +972,8 @@ let tests = Expect.equal (jobj .SelectToken("resources[0].properties.defaultToOAuthAuthentication") - .ToString()) - "false" + .ToObject()) + false "default to OAuth should be disabled" } ] \ No newline at end of file diff --git a/src/Tests/VirtualMachine.fs b/src/Tests/VirtualMachine.fs index f96d24168..74499837b 100644 --- a/src/Tests/VirtualMachine.fs +++ b/src/Tests/VirtualMachine.fs @@ -57,7 +57,7 @@ let tests = Expect.equal resource.DiagnosticsProfile.BootDiagnostics.StorageUri - "[reference(resourceId('Microsoft.Storage/storageAccounts', 'isaacsvmstorage'), '2022-05-01').primaryEndpoints.blob]" + "[reference(resourceId('Microsoft.Storage/storageAccounts', 'isaacsvmstorage'), '2023-05-01').primaryEndpoints.blob]" "Incorrect diagnostics storage Uri" } diff --git a/src/Tests/test-data/diagnostics.json b/src/Tests/test-data/diagnostics.json index 71863da1e..f00d8a694 100644 --- a/src/Tests/test-data/diagnostics.json +++ b/src/Tests/test-data/diagnostics.json @@ -5,7 +5,7 @@ "parameters": {}, "resources": [ { - "apiVersion": "2022-05-01", + "apiVersion": "2023-05-01", "dependsOn": [], "kind": "StorageV2", "location": "northeurope", diff --git a/src/Tests/test-data/event-grid.json b/src/Tests/test-data/event-grid.json index 226e44a4c..4f91f79c4 100644 --- a/src/Tests/test-data/event-grid.json +++ b/src/Tests/test-data/event-grid.json @@ -5,7 +5,7 @@ "parameters": {}, "resources": [ { - "apiVersion": "2022-05-01", + "apiVersion": "2023-05-01", "dependsOn": [], "kind": "StorageV2", "location": "northeurope", @@ -18,7 +18,7 @@ "type": "Microsoft.Storage/storageAccounts" }, { - "apiVersion": "2018-03-01-preview", + "apiVersion": "2023-05-01", "dependsOn": [ "[resourceId('Microsoft.Storage/storageAccounts', 'isaacgriddevprac')]" ], diff --git a/src/Tests/test-data/lots-of-resources.json b/src/Tests/test-data/lots-of-resources.json index 5ea46e34e..d66fc750d 100644 --- a/src/Tests/test-data/lots-of-resources.json +++ b/src/Tests/test-data/lots-of-resources.json @@ -83,7 +83,7 @@ "type": "Microsoft.Sql/servers/elasticPools" }, { - "apiVersion": "2022-05-01", + "apiVersion": "2023-05-01", "dependsOn": [], "kind": "StorageV2", "location": "northeurope", @@ -223,7 +223,7 @@ "type": "Microsoft.Web/serverfarms" }, { - "apiVersion": "2022-05-01", + "apiVersion": "2023-05-01", "dependsOn": [], "kind": "StorageV2", "location": "northeurope", @@ -410,12 +410,12 @@ "isHttpAllowed": true, "isHttpsAllowed": true, "optimizationType": "GeneralWebDelivery", - "originHostHeader": "[replace(replace(reference(resourceId('Microsoft.Storage/storageAccounts', 'farmerstorage1979'), '2022-05-01').primaryEndpoints.web, 'https://', ''), '/', '')]", + "originHostHeader": "[replace(replace(reference(resourceId('Microsoft.Storage/storageAccounts', 'farmerstorage1979'), '2023-05-01').primaryEndpoints.web, 'https://', ''), '/', '')]", "origins": [ { "name": "origin", "properties": { - "hostName": "[replace(replace(reference(resourceId('Microsoft.Storage/storageAccounts', 'farmerstorage1979'), '2022-05-01').primaryEndpoints.web, 'https://', ''), '/', '')]" + "hostName": "[replace(replace(reference(resourceId('Microsoft.Storage/storageAccounts', 'farmerstorage1979'), '2023-05-01').primaryEndpoints.web, 'https://', ''), '/', '')]" } } ], @@ -781,7 +781,7 @@ "type": "Microsoft.Web/serverfarms" }, { - "apiVersion": "2022-05-01", + "apiVersion": "2023-05-01", "dependsOn": [], "kind": "StorageV2", "location": "northeurope", diff --git a/src/Tests/test-data/vm.json b/src/Tests/test-data/vm.json index 0516838a3..bc499ee16 100644 --- a/src/Tests/test-data/vm.json +++ b/src/Tests/test-data/vm.json @@ -20,7 +20,7 @@ "diagnosticsProfile": { "bootDiagnostics": { "enabled": true, - "storageUri": "[reference(resourceId('Microsoft.Storage/storageAccounts', 'isaacsvmstorage'), '2022-05-01').primaryEndpoints.blob]" + "storageUri": "[reference(resourceId('Microsoft.Storage/storageAccounts', 'isaacsvmstorage'), '2023-05-01').primaryEndpoints.blob]" } }, "hardwareProfile": { @@ -143,7 +143,7 @@ "type": "Microsoft.Network/publicIPAddresses" }, { - "apiVersion": "2022-05-01", + "apiVersion": "2023-05-01", "dependsOn": [], "kind": "StorageV2", "location": "northeurope",