Skip to content

Commit

Permalink
Fixed tests related to storage changes
Browse files Browse the repository at this point in the history
  • Loading branch information
xperiandri committed Oct 25, 2024
1 parent 85829df commit de707a0
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 45 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ insert_final_newline = false

[*.{fs,fsx}]
fsharp_multiline_bracket_style = stroustrup
fsharp_newline_before_multiline_computation_expression = false
fsharp_newline_before_multiline_computation_expression = false

[*.json]
indent_size = 2
22 changes: 12 additions & 10 deletions src/Farmer/Arm/Storage.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 -> {|
Expand All @@ -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()
|}
|}

Expand Down
19 changes: 14 additions & 5 deletions src/Farmer/Types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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"

[<AbstractClass; Sealed; Extension>]
type FeatureFlagExtensions =

Expand All @@ -435,13 +440,17 @@ type FeatureFlagExtensions =
featureFlag |> Option.map (fun f -> f.AsBoolean) |> Option.toNullable

[<Extension>]
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

[<Extension>]
static member ArmValue(featureFlag: FeatureFlag option) =
featureFlag |> Option.map (fun f -> f.ArmValue) |> Option.toObj

[<Extension>]
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
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/JsonRegression.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
34 changes: 17 additions & 17 deletions src/Tests/Storage.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -736,8 +736,8 @@ 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<bool>())
false
"https traffic only should be disabled"
}

Expand All @@ -754,8 +754,8 @@ 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<bool>())
true
"https traffic only should be enabled"
}

Expand Down Expand Up @@ -863,8 +863,8 @@ 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<bool>())
false
"blob public access should be disabled"
}

Expand All @@ -882,8 +882,8 @@ 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<bool>())
true
"blob public access should be enabled"
}

Expand All @@ -900,8 +900,8 @@ 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<bool>())
false
"shared key access should be disabled"
}

Expand All @@ -919,8 +919,8 @@ 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<bool>())
true
"shared key access should be enabled"
}

Expand All @@ -939,8 +939,8 @@ let tests =
Expect.equal
(jobj
.SelectToken("resources[0].properties.defaultToOAuthAuthentication")
.ToString())
"true"
.ToObject<bool>())
true
"default to OAuth should be enabled"
}

Expand All @@ -960,8 +960,8 @@ let tests =
Expect.equal
(jobj
.SelectToken("resources[0].properties.defaultToOAuthAuthentication")
.ToString())
"false"
.ToObject<bool>())
false
"default to OAuth should be disabled"
}
]
2 changes: 1 addition & 1 deletion src/Tests/VirtualMachine.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
2 changes: 1 addition & 1 deletion src/Tests/test-data/diagnostics.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"parameters": {},
"resources": [
{
"apiVersion": "2022-05-01",
"apiVersion": "2023-05-01",
"dependsOn": [],
"kind": "StorageV2",
"location": "northeurope",
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/test-data/event-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"parameters": {},
"resources": [
{
"apiVersion": "2022-05-01",
"apiVersion": "2023-05-01",
"dependsOn": [],
"kind": "StorageV2",
"location": "northeurope",
Expand All @@ -18,7 +18,7 @@
"type": "Microsoft.Storage/storageAccounts"
},
{
"apiVersion": "2018-03-01-preview",
"apiVersion": "2023-05-01",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', 'isaacgriddevprac')]"
],
Expand Down
10 changes: 5 additions & 5 deletions src/Tests/test-data/lots-of-resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"type": "Microsoft.Sql/servers/elasticPools"
},
{
"apiVersion": "2022-05-01",
"apiVersion": "2023-05-01",
"dependsOn": [],
"kind": "StorageV2",
"location": "northeurope",
Expand Down Expand Up @@ -223,7 +223,7 @@
"type": "Microsoft.Web/serverfarms"
},
{
"apiVersion": "2022-05-01",
"apiVersion": "2023-05-01",
"dependsOn": [],
"kind": "StorageV2",
"location": "northeurope",
Expand Down Expand Up @@ -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://', ''), '/', '')]"
}
}
],
Expand Down Expand Up @@ -781,7 +781,7 @@
"type": "Microsoft.Web/serverfarms"
},
{
"apiVersion": "2022-05-01",
"apiVersion": "2023-05-01",
"dependsOn": [],
"kind": "StorageV2",
"location": "northeurope",
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/test-data/vm.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -143,7 +143,7 @@
"type": "Microsoft.Network/publicIPAddresses"
},
{
"apiVersion": "2022-05-01",
"apiVersion": "2023-05-01",
"dependsOn": [],
"kind": "StorageV2",
"location": "northeurope",
Expand Down

0 comments on commit de707a0

Please sign in to comment.