Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_image - change os_disk property to a list #1443

Merged
merged 4 commits into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion azurerm/helpers/azure/resourceid.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type ResourceID struct {
func ParseAzureResourceID(id string) (*ResourceID, error) {
idURL, err := url.ParseRequestURI(id)
if err != nil {
return nil, fmt.Errorf("Cannot parse Azure Id: %s", err)
return nil, fmt.Errorf("Cannot parse Azure ID: %s", err)
}

path := idURL.Path
Expand Down
4 changes: 2 additions & 2 deletions azurerm/helpers/azure/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
)

func ValidateResourceId(i interface{}, k string) (_ []string, errors []error) {
func ValidateResourceID(i interface{}, k string) (_ []string, errors []error) {
v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %q to be string", k))
Expand All @@ -30,5 +30,5 @@ func ValidateResourceIDOrEmpty(i interface{}, k string) (_ []string, errors []er
return
}

return ValidateResourceId(i, k)
return ValidateResourceID(i, k)
}
34 changes: 18 additions & 16 deletions azurerm/helpers/azure/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,61 @@ package azure

import "testing"

func TestHelper_Validate_AzureResourceId(t *testing.T) {
func TestHelper_AzureResourceID(t *testing.T) {
cases := []struct {
Id string
ID string
Errors int
}{
{
Id: "",
ID: "",
Errors: 1,
},
{
Id: "nonsense",
ID: "nonsense",
Errors: 1,
},
{
Id: "/slash",
ID: "/slash",
Errors: 1,
},
{
Id: "/path/to/nothing",
ID: "/path/to/nothing",
Errors: 1,
},
{
Id: "/subscriptions",
ID: "/subscriptions",
Errors: 1,
},
{
Id: "/providers",
ID: "/providers",
Errors: 1,
},
{
Id: "/subscriptions/not-a-guid",
ID: "/subscriptions/not-a-guid",
Errors: 0,
},
{
Id: "/providers/test",
ID: "/providers/test",
Errors: 0,
},
{
Id: "/subscriptions/00000000-0000-0000-0000-00000000000/",
ID: "/subscriptions/00000000-0000-0000-0000-00000000000/",
Errors: 0,
},
{
Id: "/providers/provider.name/",
ID: "/providers/provider.name/",
Errors: 0,
},
}

for _, tc := range cases {
_, errors := ValidateResourceId(tc.Id, "test")
t.Run(tc.ID, func(t *testing.T) {
_, errors := ValidateResourceID(tc.ID, "test")

if len(errors) < tc.Errors {
t.Fatalf("Expected AzureResourceId to have an error for %q", tc.Id)
}
if len(errors) < tc.Errors {
t.Fatalf("Expected ValidateResourceID to have %d not %d errors for %q", tc.Errors, len(errors), tc.ID)
}
})
}
}

Expand Down
16 changes: 12 additions & 4 deletions azurerm/helpers/suppress/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,50 @@ package suppress

import "testing"

func TestHelper_Suppress_CaseDifference(t *testing.T) {
func TestCaseDifference(t *testing.T) {
cases := []struct {
Name string
StringA string
StringB string
Suppress bool
}{
{
Name: "empty",
StringA: "",
StringB: "",
Suppress: true,
},
{
Name: "empty vs text",
StringA: "ye old text",
StringB: "",
Suppress: false,
},
{
Name: "different text",
StringA: "ye old text?",
StringB: "ye different text",
Suppress: false,
},
{
Name: "same text",
StringA: "ye same text!",
StringB: "ye same text!",
Suppress: true,
},
{
Name: "same text different case",
StringA: "ye old text?",
StringB: "Ye OLD texT?",
Suppress: true,
},
}

for _, tc := range cases {
if CaseDifference("test", tc.StringA, tc.StringB, nil) != tc.Suppress {
t.Fatalf("Expected CaseDifference to return %t for '%q' == '%q'", tc.Suppress, tc.StringA, tc.StringB)
}
t.Run(tc.Name, func(t *testing.T) {
if CaseDifference("test", tc.StringA, tc.StringB, nil) != tc.Suppress {
t.Fatalf("Expected CaseDifference to return %t for '%q' == '%q'", tc.Suppress, tc.StringA, tc.StringB)
}
})
}
}
2 changes: 1 addition & 1 deletion azurerm/helpers/suppress/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/hashicorp/terraform/helper/schema"
)

func Rfc3339Time(_, old, new string, _ *schema.ResourceData) bool {
func RFC3339Time(_, old, new string, _ *schema.ResourceData) bool {
ot, oerr := time.Parse(time.RFC3339, old)
nt, nerr := time.Parse(time.RFC3339, new)

Expand Down
17 changes: 13 additions & 4 deletions azurerm/helpers/suppress/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,56 @@ package suppress

import "testing"

func TestHelper_Supress_Rfc3339Time(t *testing.T) {
func TestRFC3339Time(t *testing.T) {
cases := []struct {
Name string
TimeA string
TimeB string
Suppress bool
}{
{
Name: "empty",
TimeA: "",
TimeB: "",
Suppress: false,
},
{
Name: "neither are time",
TimeA: "this is not a time",
TimeB: "neither is this",
Suppress: false,
},
{
Name: "time vs text",
TimeA: "2000-01-01T01:23:45+00:00",
TimeB: "that is a valid time",
Suppress: false,
},
{
Name: "two different times",
TimeA: "2000-01-01T01:23:45+00:00",
TimeB: "1984-07-07T01:23:45+00:00",
Suppress: false,
},
{
Name: "same time, different zone 1",
TimeA: "2000-01-01T01:23:45+00:00",
TimeB: "2000-01-01T01:23:45Z",
Suppress: true,
},
{
Name: "same time, different zone 2",
TimeA: "2000-01-01T01:23:45-08:00",
TimeB: "2000-01-01T09:23:45Z",
Suppress: true,
},
}

for _, tc := range cases {
if Rfc3339Time("test", tc.TimeA, tc.TimeB, nil) != tc.Suppress {
t.Fatalf("Expected Rfc3339Time to return %t for '%q' == '%q'", tc.Suppress, tc.TimeA, tc.TimeB)
}
t.Run(tc.Name, func(t *testing.T) {
if RFC3339Time("test", tc.TimeA, tc.TimeB, nil) != tc.Suppress {
t.Fatalf("Expected RFC3339Time to return %t for '%q' == '%q'", tc.Suppress, tc.TimeA, tc.TimeB)
}
})
}
}
9 changes: 4 additions & 5 deletions azurerm/helpers/validate/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package validate
import (
"fmt"
"net"
"regexp"
)

func Ip4Address(i interface{}, k string) (_ []string, errors []error) {
func IP4Address(i interface{}, k string) (_ []string, errors []error) {
v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %q to be string", k))
Expand All @@ -21,15 +20,15 @@ func Ip4Address(i interface{}, k string) (_ []string, errors []error) {
return
}

func MacAddress(i interface{}, k string) (_ []string, errors []error) {
func MACAddress(i interface{}, k string) (_ []string, errors []error) {
v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %q to be string", k))
return
}

if matched := regexp.MustCompile(`^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$`).Match([]byte(v)); !matched {
errors = append(errors, fmt.Errorf("%q is not a valid MAC address: %q", k, i))
if _, err := net.ParseMAC(v); err != nil {
errors = append(errors, fmt.Errorf("%q is not a valid MAC address: %q (%v)", k, i, err))
}

return
Expand Down
58 changes: 31 additions & 27 deletions azurerm/helpers/validate/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,94 +2,98 @@ package validate

import "testing"

func TestHelper_Validate_Ip4Address(t *testing.T) {
func TestIP4Address(t *testing.T) {
cases := []struct {
Ip string
IP string
Errors int
}{
{
Ip: "",
IP: "",
Errors: 1,
},
{
Ip: "0.0.0.0",
IP: "0.0.0.0",
Errors: 0,
},
{
Ip: "1.2.3.no",
IP: "1.2.3.no",
Errors: 1,
},
{
Ip: "text",
IP: "text",
Errors: 1,
},
{
Ip: "1.2.3.4",
IP: "1.2.3.4",
Errors: 0,
},
{
Ip: "12.34.43.21",
IP: "12.34.43.21",
Errors: 0,
},
{
Ip: "100.123.199.0",
IP: "100.123.199.0",
Errors: 0,
},
{
Ip: "255.255.255.255",
IP: "255.255.255.255",
Errors: 0,
},
}

for _, tc := range cases {
_, errors := Ip4Address(tc.Ip, "test")
t.Run(tc.IP, func(t *testing.T) {
_, errors := IP4Address(tc.IP, "test")

if len(errors) < tc.Errors {
t.Fatalf("Expected Ip4Address to have an error for %q", tc.Ip)
}
if len(errors) != tc.Errors {
t.Fatalf("Expected IP4Address to return %d error(s) not %d", len(errors), tc.Errors)
}
})
}
}

func TestHelper_Validate_MacAddress(t *testing.T) {
func TestMACAddress(t *testing.T) {
cases := []struct {
Ip string
MAC string
Errors int
}{
{
Ip: "",
MAC: "",
Errors: 1,
},
{
Ip: "text",
MAC: "text d",
Errors: 1,
},
{
Ip: "12:34:no",
MAC: "12:34:no",
Errors: 1,
},
{
Ip: "123:34:56:78:90:ab",
MAC: "123:34:56:78:90:ab",
Errors: 1,
},
{
Ip: "12:34:56:78:90:NO",
MAC: "12:34:56:78:90:NO",
Errors: 1,
},
{
Ip: "12:34:56:78:90:ab",
MAC: "12:34:56:78:90:ab",
Errors: 0,
},
{
Ip: "ab:cd:ef:AB:CD:EF",
MAC: "ab:cd:ef:AB:CD:EF",
Errors: 0,
},
}

for _, tc := range cases {
_, errors := MacAddress(tc.Ip, "test")
t.Run(tc.MAC, func(t *testing.T) {
_, errors := MACAddress(tc.MAC, "test")

if len(errors) < tc.Errors {
t.Fatalf("Expected MacAddress to have an error for %q", tc.Ip)
}
if len(errors) != tc.Errors {
t.Fatalf("Expected MACAddress to return %d error(s) not %d", len(errors), tc.Errors)
}
})
}
}
Loading