-
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
Provider function to replace validation.NoZeroValues #2467
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a46c822
Fix for name with only spaces
WodansSon e983d70
Removed regex and replaced with TrimSpace
WodansSon 05bd771
Updated test for new behavior
WodansSon ea89ddf
Saved as LF only
WodansSon a61728a
Fix lint error
WodansSon 1b2ebcb
Update azurerm/data_source_route_table.go
katbyte 4238406
Update azurerm/resource_arm_route_table.go
katbyte a87333a
Update azurerm/resource_arm_route_table.go
katbyte b0ffcfb
Update azurerm/resource_arm_route_table.go
katbyte 811418a
Update azurerm/resource_arm_route_table.go
katbyte 9094deb
Update signature
WodansSon f6bca95
Added test case
WodansSon 6fda6af
Added special character test cases
WodansSon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,20 @@ | ||
package validate | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// NoEmptyStrings validates that the string is not just whitespace characters (equal to [\r\n\t\f\v ]) | ||
func NoEmptyStrings(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)} | ||
} | ||
|
||
if strings.TrimSpace(v) == "" { | ||
return nil, []error{fmt.Errorf("%q must not be empty", k)} | ||
} | ||
|
||
return nil, nil | ||
} |
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,99 @@ | ||
package validate | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestNoEmptyStrings(t *testing.T) { | ||
cases := []struct { | ||
Value string | ||
TestName string | ||
ErrCount int | ||
}{ | ||
{ | ||
Value: "!", | ||
TestName: "Exclamation", | ||
ErrCount: 0, | ||
}, | ||
{ | ||
Value: ".", | ||
TestName: "Period", | ||
ErrCount: 0, | ||
}, | ||
{ | ||
Value: "-", | ||
TestName: "Hyphen", | ||
ErrCount: 0, | ||
}, | ||
{ | ||
Value: "_", | ||
TestName: "Underscore", | ||
ErrCount: 0, | ||
}, | ||
{ | ||
Value: "10.1.0.0/16", | ||
TestName: "IP", | ||
ErrCount: 0, | ||
}, | ||
{ | ||
Value: "", | ||
TestName: "Empty", | ||
ErrCount: 1, | ||
}, | ||
{ | ||
Value: " ", | ||
TestName: "Space", | ||
ErrCount: 1, | ||
}, | ||
{ | ||
Value: " ", | ||
TestName: "FiveSpaces", | ||
ErrCount: 1, | ||
}, | ||
{ | ||
Value: " 1", | ||
TestName: "DoubleSpaceOne", | ||
ErrCount: 0, | ||
}, | ||
{ | ||
Value: "1 ", | ||
TestName: "OneSpace", | ||
ErrCount: 0, | ||
}, | ||
{ | ||
Value: "\r", | ||
TestName: "CarriageReturn", | ||
ErrCount: 1, | ||
}, | ||
{ | ||
Value: "\n", | ||
TestName: "NewLine", | ||
ErrCount: 1, | ||
}, | ||
{ | ||
Value: "\t", | ||
TestName: "HorizontalTab", | ||
ErrCount: 1, | ||
}, | ||
{ | ||
Value: "\f", | ||
TestName: "FormFeed", | ||
ErrCount: 1, | ||
}, | ||
{ | ||
Value: "\v", | ||
TestName: "VerticalTab", | ||
ErrCount: 1, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.TestName, func(t *testing.T) { | ||
_, errors := NoEmptyStrings(tc.Value, tc.TestName) | ||
|
||
if len(errors) != tc.ErrCount { | ||
t.Fatalf("Expected NoEmptyStrings to have %d not %d errors for %q", tc.ErrCount, len(errors), tc.TestName) | ||
} | ||
}) | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
it'd be good to add a test case for 5 empty spaces in here too
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.
Done.