Created
November 21, 2019 13:49
-
-
Save jim-minter/efb19e8842cd69a26e49c437d65bbeaf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package arm | |
import ( | |
"bytes" | |
"encoding/json" | |
"testing" | |
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-07-01/network" | |
"github.com/Azure/go-autorest/autorest/to" | |
) | |
func TestMarshalJSON(t *testing.T) { | |
r := &Resource{ | |
Resource: &network.SecurityGroup{ | |
SecurityGroupPropertiesFormat: &network.SecurityGroupPropertiesFormat{ | |
SecurityRules: &[]network.SecurityRule{ | |
{ | |
SecurityRulePropertiesFormat: &network.SecurityRulePropertiesFormat{ | |
Protocol: network.SecurityRuleProtocolTCP, | |
SourcePortRange: to.StringPtr("*"), | |
DestinationPortRange: to.StringPtr("6443"), | |
SourceAddressPrefix: to.StringPtr("*"), | |
DestinationAddressPrefix: to.StringPtr("*"), | |
Access: network.SecurityRuleAccessAllow, | |
Priority: to.Int32Ptr(101), | |
Direction: network.SecurityRuleDirectionInbound, | |
}, | |
Name: to.StringPtr("apiserver_in"), | |
}, | |
{ | |
SecurityRulePropertiesFormat: &network.SecurityRulePropertiesFormat{ | |
Protocol: network.SecurityRuleProtocolTCP, | |
SourcePortRange: to.StringPtr("*"), | |
DestinationPortRange: to.StringPtr("22"), | |
SourceAddressPrefix: to.StringPtr("*"), | |
DestinationAddressPrefix: to.StringPtr("*"), | |
Access: network.SecurityRuleAccessAllow, | |
Priority: to.Int32Ptr(103), | |
Direction: network.SecurityRuleDirectionInbound, | |
}, | |
Name: to.StringPtr("bootstrap_ssh_in"), | |
}, | |
}, | |
}, | |
Name: to.StringPtr("cluster-controlplane-nsg"), | |
Type: to.StringPtr("Microsoft.Network/networkSecurityGroups"), | |
Location: to.StringPtr("eastus"), | |
}, | |
APIVersion: "2019-07-01", | |
} | |
want := []byte(`{ | |
"apiVersion": "2019-07-01", | |
"location": "eastus", | |
"name": "cluster-controlplane-nsg", | |
"properties": { | |
"securityRules": [ | |
{ | |
"name": "apiserver_in", | |
"properties": { | |
"access": "Allow", | |
"destinationAddressPrefix": "*", | |
"destinationPortRange": "6443", | |
"direction": "Inbound", | |
"priority": 101, | |
"protocol": "Tcp", | |
"sourceAddressPrefix": "*", | |
"sourcePortRange": "*" | |
} | |
}, | |
{ | |
"name": "bootstrap_ssh_in", | |
"properties": { | |
"access": "Allow", | |
"destinationAddressPrefix": "*", | |
"destinationPortRange": "22", | |
"direction": "Inbound", | |
"priority": 103, | |
"protocol": "Tcp", | |
"sourceAddressPrefix": "*", | |
"sourcePortRange": "*" | |
} | |
} | |
] | |
}, | |
"type": "Microsoft.Network/networkSecurityGroups" | |
}`) | |
b, err := json.MarshalIndent(r, "", " ") | |
if err != nil { | |
t.Fatal(err) | |
} | |
if !bytes.Equal(b, want) { | |
t.Error(string(b)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment