-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Various improvements to automation account & schedule (interval property for recurring) #1384
Changes from 5 commits
beeaed5
feafd1c
bf6c579
b4a6ebd
3ef04d6
f287c40
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,10 @@ | ||
package suppress | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"strings" | ||
) | ||
|
||
func CaseDifference(_, old, new string, _ *schema.ResourceData) bool { | ||
return strings.ToLower(old) == strings.ToLower(new) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package suppress | ||
|
||
import "testing" | ||
|
||
func TestHelper_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 '%q' == '%q'", tc.Suppress, tc.StringA, tc.StringB) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package suppress | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func Rfc3339Time(_, old, new string, _ *schema.ResourceData) bool { | ||
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. Ohhh this too! 👍 |
||
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,48 @@ | ||
package suppress | ||
|
||
import "testing" | ||
|
||
func TestHelper_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 '%q' == '%q'", tc.Suppress, tc.TimeA, tc.TimeB) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package validate | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/Azure/go-autorest/autorest/date" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
//todo, now in terraform helper, switch over once vended, | ||
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. Might be worth noting exactly what the helper is: https://godoc.org/github.com/hashicorp/terraform/helper/validation#ValidateRFC3339TimeString |
||
func Rfc3339Time(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 _, 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 Rfc3339DateInFutureBy(d time.Duration) schema.SchemaValidateFunc { | ||
return func(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 | ||
} | ||
|
||
t, err := date.ParseTime(time.RFC3339, v) | ||
if err != nil { | ||
errors = append(errors, fmt.Errorf("%q has the invalid RFC3339 date format %q: %+v", k, i, err)) | ||
return | ||
} | ||
|
||
if time.Until(t) < d { | ||
errors = append(errors, fmt.Errorf("%q is %q and should be at least %q in the future", k, i, d)) | ||
} | ||
|
||
return | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package validate | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestHelper_Validate_RFC3339Time(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 '%q'", tc.Time) | ||
} | ||
} | ||
} | ||
|
||
func TestHelper_Validate_Rfc3339DateInFutureBy(t *testing.T) { | ||
cases := []struct { | ||
Time string | ||
Duration time.Duration | ||
Errors int | ||
}{ | ||
{ | ||
Time: "", | ||
Duration: time.Hour, | ||
Errors: 1, | ||
}, | ||
{ | ||
Time: "not a time", | ||
Duration: time.Hour, | ||
Errors: 1, | ||
}, | ||
{ | ||
Time: time.Now().String(), | ||
Duration: time.Hour, | ||
Errors: 1, | ||
}, | ||
{ | ||
Time: time.Now().Add(time.Hour * 7).String(), | ||
Duration: time.Hour, | ||
Errors: 1, | ||
}, | ||
{ | ||
Time: time.Now().Add(time.Minute).String(), | ||
Duration: time.Minute * 7, | ||
Errors: 0, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
_, errors := Rfc3339DateInFutureBy(tc.Duration)(tc.Time, "test") | ||
|
||
if len(errors) < tc.Errors { | ||
t.Fatalf("Expected Rfc3339DateInFutureBy to have an error for '%q' in future by `%q`", tc.Time, tc.Duration.String()) | ||
} | ||
} | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
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.
We should get this added into helper/schema 😄