-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
148 additions
and
2 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
20 changes: 20 additions & 0 deletions
20
internal/services/resource/validate/resource_deployment_script_azure_cli_version.go
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,20 @@ | ||
package validate | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
) | ||
|
||
func ResourceDeploymentScriptAzureCliVersion(i interface{}, k string) ([]string, []error) { | ||
v, ok := i.(string) | ||
if !ok { | ||
return nil, []error{fmt.Errorf("expected type of %q to be string", k)} | ||
} | ||
|
||
var errors []error | ||
if matched := regexp.MustCompile(`^\d+\.\d+\.\d+$`).Match([]byte(v)); !matched { | ||
errors = append(errors, fmt.Errorf("%q should be in format x.y.z", k)) | ||
} | ||
|
||
return nil, errors | ||
} |
55 changes: 55 additions & 0 deletions
55
internal/services/resource/validate/resource_deployment_script_azure_cli_version_test.go
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,55 @@ | ||
package validate | ||
|
||
import "testing" | ||
|
||
func TestResourceDeploymentScriptAzureCliVersion(t *testing.T) { | ||
cases := []struct { | ||
Input string | ||
Valid bool | ||
}{ | ||
|
||
{ | ||
Input: "", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
Input: "2", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
Input: "1.1", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
Input: "3..", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
Input: "2.9.0.1", | ||
Valid: true, | ||
}, | ||
|
||
{ | ||
Input: "2.9.0", | ||
Valid: true, | ||
}, | ||
|
||
{ | ||
Input: "2.0.77", | ||
Valid: true, | ||
}, | ||
} | ||
for _, tc := range cases { | ||
t.Logf("[DEBUG] Testing Value %s", tc.Input) | ||
_, errors := ResourceDeploymentScriptAzureCliVersion(tc.Input, "test") | ||
valid := len(errors) == 0 | ||
|
||
if tc.Valid != valid { | ||
t.Fatalf("Expected %t but got %t", tc.Valid, valid) | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
internal/services/resource/validate/resource_deployment_script_azure_power_shell_version.go
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,20 @@ | ||
package validate | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
) | ||
|
||
func ResourceDeploymentScriptAzurePowerShellVersion(i interface{}, k string) ([]string, []error) { | ||
v, ok := i.(string) | ||
if !ok { | ||
return nil, []error{fmt.Errorf("expected type of %q to be string", k)} | ||
} | ||
|
||
var errors []error | ||
if matched := regexp.MustCompile(`^\d+\.\d+$`).Match([]byte(v)); !matched { | ||
errors = append(errors, fmt.Errorf("%q should be in format x.y", k)) | ||
} | ||
|
||
return nil, errors | ||
} |
50 changes: 50 additions & 0 deletions
50
...l/services/resource/validate/resource_deployment_script_azure_power_shell_version_test.go
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,50 @@ | ||
package validate | ||
|
||
import "testing" | ||
|
||
func TestResourceDeploymentScriptAzurePowerShellVersion(t *testing.T) { | ||
cases := []struct { | ||
Input string | ||
Valid bool | ||
}{ | ||
|
||
{ | ||
Input: "", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
Input: "2", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
Input: "1.1.1", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
Input: "3.", | ||
Valid: false, | ||
}, | ||
|
||
{ | ||
Input: "9.7", | ||
Valid: true, | ||
}, | ||
|
||
{ | ||
Input: "10.3", | ||
Valid: true, | ||
}, | ||
} | ||
for _, tc := range cases { | ||
t.Logf("[DEBUG] Testing Value %s", tc.Input) | ||
_, errors := ResourceDeploymentScriptAzurePowerShellVersion(tc.Input, "test") | ||
valid := len(errors) == 0 | ||
|
||
if tc.Valid != valid { | ||
t.Fatalf("Expected %t but got %t", tc.Valid, valid) | ||
} | ||
} | ||
} |