-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Resource:
azurerm_scheduler_job
(#1172)
* Intial commit of scheduler_job * azurerm_scheduler_job todo & misc cleanup * travis CI fixes travis CI fixes * azurerm_scheduler_job: removed populate function & other small changes * aszurerm_schduler_job: update tests & validation * Updated example URLs * schduler jobs & collection: formatted examples * azurerm_scheduler_job: schema adjustments * azurerm_scheduler_job: resolving PR comments * azurerm_scheduler_job: First round of PR fixes * azurerm_scheduler_job: Futher PR fixes * scheduler job: address PR comments * scheduler job - minor fix to tests * Adding tests for the validation functions * inline-ing the check methods * Fixing the highlight in the sidebar * Fixing merge issues * Fixing a crash when loading the environment
- Loading branch information
1 parent
7897d07
commit 3cc5cdb
Showing
13 changed files
with
2,256 additions
and
20 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package set | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform/helper/hashcode" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func HashInt(v interface{}) int { | ||
return hashcode.String(strconv.Itoa(v.(int))) | ||
} | ||
|
||
func HashStringIgnoreCase(v interface{}) int { | ||
return hashcode.String(strings.ToLower(v.(string))) | ||
} | ||
|
||
func FromInt32Slice(slice []int32) *schema.Set { | ||
set := &schema.Set{F: HashInt} | ||
for _, v := range slice { | ||
set.Add(int(v)) | ||
} | ||
|
||
return set | ||
} | ||
|
||
func ToSliceInt32P(set *schema.Set) *[]int32 { | ||
var slice []int32 | ||
for _, m := range set.List() { | ||
slice = append(slice, int32(m.(int))) | ||
} | ||
|
||
return &slice | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package validate | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
|
||
"strings" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func IntBetweenAndNot(min, max, not int) schema.SchemaValidateFunc { | ||
return func(i interface{}, k string) (_ []string, errors []error) { | ||
v, ok := i.(int) | ||
if !ok { | ||
errors = append(errors, fmt.Errorf("expected type of %q to be int", k)) | ||
return | ||
} | ||
|
||
if v < min || v > max { | ||
errors = append(errors, fmt.Errorf("expected %s to be in the range (%d - %d), got %d", k, min, max, v)) | ||
return | ||
} | ||
|
||
if v == not { | ||
errors = append(errors, fmt.Errorf("expected %s to not be %d, got %d", k, not, v)) | ||
return | ||
} | ||
|
||
return | ||
} | ||
} | ||
|
||
func UrlIsHttpOrHttps() schema.SchemaValidateFunc { | ||
return UrlWithScheme([]string{"http", "https"}) | ||
} | ||
|
||
func UrlWithScheme(validSchemes []string) 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 | ||
} | ||
|
||
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)) | ||
return | ||
} | ||
|
||
if url.Host == "" { | ||
errors = append(errors, fmt.Errorf("%q url has no host: %q", k, url)) | ||
} | ||
|
||
found := false | ||
for _, s := range validSchemes { | ||
if strings.EqualFold(url.Scheme, s) { | ||
found = true | ||
break | ||
} | ||
} | ||
|
||
if !found { | ||
schemes := strings.Join(validSchemes, ",") | ||
errors = append(errors, fmt.Errorf("URL scheme %q isn't valid - supported scheme's are %q", url.Scheme, schemes)) | ||
} | ||
|
||
return | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package validate | ||
|
||
import "testing" | ||
|
||
func TestUrlWithScheme(t *testing.T) { | ||
validSchemes := []string{"example"} | ||
testCases := []struct { | ||
Url string | ||
ShouldHaveError bool | ||
}{ | ||
{ | ||
Url: "example://mysite.com", | ||
ShouldHaveError: false, | ||
}, | ||
{ | ||
Url: "http://mysite.com", | ||
ShouldHaveError: true, | ||
}, | ||
{ | ||
Url: "example://", | ||
ShouldHaveError: true, | ||
}, | ||
{ | ||
Url: "example://validhost", | ||
ShouldHaveError: false, | ||
}, | ||
} | ||
|
||
t.Run("TestUrlWithScheme", func(t *testing.T) { | ||
for _, v := range testCases { | ||
_, errors := UrlWithScheme(validSchemes)(v.Url, "field_name") | ||
|
||
hasErrors := len(errors) > 0 | ||
if v.ShouldHaveError && !hasErrors { | ||
t.Fatalf("Expected an error but didn't get one for %q", v.Url) | ||
return | ||
} | ||
|
||
if !v.ShouldHaveError && hasErrors { | ||
t.Fatalf("Expected %q to return no errors, but got some %+v", v.Url, errors) | ||
return | ||
} | ||
} | ||
}) | ||
} |
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
Oops, something went wrong.