-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
New Resource: azurerm_scheduler_job
#1172
Changes from 10 commits
f1c9ef6
020df2c
beb79b8
2c9a46a
720eabc
6b7b924
61ea612
9a76a4b
ee60252
218376a
5a50522
878707c
e404a92
93e318b
c18fbfe
9836428
770beb3
f32ecc0
184a879
00cfa00
c1ae37e
f0a0315
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package set | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform/helper/hashcode" | ||
) | ||
|
||
func HashInt(v interface{}) int { | ||
return hashcode.String(strconv.Itoa(v.(int))) | ||
} | ||
|
||
func HashStringIgnoreCase(v interface{}) int { | ||
return hashcode.String(strings.ToLower(v.(string))) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package supress | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"strings" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor can we sort these? |
||
) | ||
|
||
func CaseDifference(_, old, new string, _ *schema.ResourceData) bool { | ||
return strings.ToLower(old) == strings.ToLower(new) | ||
} | ||
|
||
func Rfc3339Time(_, old, new string, _ *schema.ResourceData) bool { | ||
ot, oerr := time.Parse(time.RFC3339, old) | ||
nt, nerr := time.Parse(time.RFC3339, new) | ||
|
||
if oerr != nil || nerr != nil { | ||
return false | ||
} | ||
|
||
return nt.Equal(ot) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package supress | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestInternal_Suppress_CaseDifference(t *testing.T) { | ||
cases := []struct { | ||
StringA string | ||
StringB string | ||
Suppress bool | ||
}{ | ||
{ | ||
StringA: "", | ||
StringB: "", | ||
Suppress: true, | ||
}, | ||
{ | ||
StringA: "ye old text", | ||
StringB: "", | ||
Suppress: false, | ||
}, | ||
{ | ||
StringA: "ye old text?", | ||
StringB: "ye different text", | ||
Suppress: false, | ||
}, | ||
{ | ||
StringA: "ye same text!", | ||
StringB: "ye same text!", | ||
Suppress: true, | ||
}, | ||
{ | ||
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 '%s' == '%s'", tc.Suppress, tc.StringA, tc.StringB) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor you can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be using %q everywhere instead of %s? |
||
} | ||
} | ||
} | ||
|
||
func TestInternal_Supress_Rfc3339Time(t *testing.T) { | ||
cases := []struct { | ||
TimeA string | ||
TimeB string | ||
Suppress bool | ||
}{ | ||
{ | ||
TimeA: "", | ||
TimeB: "", | ||
Suppress: false, | ||
}, | ||
{ | ||
TimeA: "this is not a time", | ||
TimeB: "neither is this", | ||
Suppress: false, | ||
}, | ||
{ | ||
TimeA: "2000-01-01T01:23:45+00:00", | ||
TimeB: "that is a valid time", | ||
Suppress: false, | ||
}, | ||
{ | ||
TimeA: "2000-01-01T01:23:45+00:00", | ||
TimeB: "1984-07-07T01:23:45+00:00", | ||
Suppress: false, | ||
}, | ||
{ | ||
TimeA: "2000-01-01T01:23:45+00:00", | ||
TimeB: "2000-01-01T01:23:45Z", | ||
Suppress: true, | ||
}, | ||
{ | ||
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 '%s' == '%s'", tc.Suppress, tc.TimeA, tc.TimeB) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package validate | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"time" | ||
|
||
"github.com/Azure/go-autorest/autorest/date" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
//todo, now in terraform helper, switch over once vended, | ||
func Rfc3339Time(i interface{}, k string) (ws []string, errors []error) { | ||
v, ok := i.(string) | ||
if !ok { | ||
errors = append(errors, fmt.Errorf("expected type of %s to be string", k)) | ||
return | ||
} | ||
|
||
if _, err := date.ParseTime(time.RFC3339, v); err != nil { | ||
errors = append(errors, fmt.Errorf("%q has the invalid RFC3339 date format %q: %+v", k, i, err)) | ||
} | ||
|
||
return | ||
} | ||
|
||
func IntBetweenAndNot(min, max, not int) schema.SchemaValidateFunc { | ||
return func(i interface{}, k string) (s []string, es []error) { | ||
v, ok := i.(int) | ||
if !ok { | ||
es = append(es, fmt.Errorf("expected type of %s to be int", k)) | ||
return | ||
} | ||
|
||
if v < min || v > max { | ||
es = append(es, fmt.Errorf("expected %s to be in the range (%d - %d), got %d", k, min, max, v)) | ||
return | ||
} | ||
|
||
if v == not { | ||
es = append(es, fmt.Errorf("expected %s to not be %d, got %d", k, not, v)) | ||
return | ||
} | ||
|
||
return | ||
} | ||
} | ||
|
||
func Url(i interface{}, k string) (ws []string, errors []error) { | ||
v, ok := i.(string) | ||
if !ok { | ||
errors = append(errors, fmt.Errorf("expected type of %s to be string", k)) | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we be adding a |
||
} | ||
|
||
url, err := url.Parse(v) | ||
if err != nil { | ||
errors = append(errors, fmt.Errorf("%q url is in an invalid format: %q (%+v)", k, i, err)) | ||
} else if url.Scheme != "http" && url.Scheme != "https" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's a bit of an assumption given the name of the function - perhaps it's worth renaming this to |
||
errors = append(errors, fmt.Errorf("%q url is neither an http or https uri: %q", k, url.Scheme)) | ||
} else if url.Host == "" { | ||
errors = append(errors, fmt.Errorf("%q url has no host: %q", k, url)) | ||
} | ||
|
||
return | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package validate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add some basic tests covering the methods in the other file? |
||
|
||
import "testing" | ||
|
||
func TestInternal_ValidateRFC3339Time(t *testing.T) { | ||
cases := []struct { | ||
Time string | ||
Errors int | ||
}{ | ||
{ | ||
Time: "", | ||
Errors: 1, | ||
}, | ||
{ | ||
Time: "this is not a date", | ||
Errors: 1, | ||
}, | ||
{ | ||
Time: "2000-01-01", | ||
Errors: 1, | ||
}, | ||
{ | ||
Time: "2000-01-01T01:23:45", | ||
Errors: 1, | ||
}, | ||
{ | ||
Time: "2000-01-01T01:23:45Z", | ||
Errors: 0, | ||
}, | ||
{ | ||
Time: "2000-01-01T01:23:45+00:00", | ||
Errors: 0, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
_, errors := Rfc3339Time(tc.Time, "test") | ||
|
||
if len(errors) != tc.Errors { | ||
t.Fatalf("Expected Rfc3339Time to have an error for '%s'", tc.Time) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
supress
->suppress