Commit Graph

20 Commits

Author SHA1 Message Date
Brian Flad 00a76d019a
Merge pull request #18614 from craigatgoogle/float-validation
Added FloatBetween validation function.
2019-05-06 17:56:56 -07:00
Brian Flad 46804080aa
helper/validation: Add Any() SchemaValidateFunc
`Any()` allows any single passing validation of multiple `SchemaValidateFunc` to pass validation to cover cases where a standard validation function does not cover the functionality or to make error messaging simpler.

Example provider usage:

```go
ValidateFunc: validation.Any(
  validation.IntAtLeast(42),
  validation.IntAtMost(5),
),
```
2018-10-18 20:58:53 -04:00
Brian Flad 17ac9a5756
helper/validation: Add All() and IntInSlice() SchemaValidateFunc
`All()` combines the outputs of multiple `SchemaValidateFunc`, to reduce the usage of custom validation functions that implement standard validation functions.

Example provider usage:

```go
ValidateFunc: validation.All(
  StringLenBetween(5, 42),
  StringMatch(regexp.MustCompile(`[a-zA-Z0-9]+`), "value must be alphanumeric"),
),
```

`IntInSlice()` is the `int` equivalent of `StringInSlice()`

Example provider usage:

```go
ValidateFunc: validation.IntInSlice([]int{30, 60, 120})
```

Output from unit testing:

```
$ make test TEST=./helper/validation
==> Checking that code complies with gofmt requirements...
go generate ./...
2018/10/17 14:16:03 Generated command/internal_plugin_list.go
go list ./helper/validation | xargs -t -n4 go test  -timeout=2m -parallel=4
go test -timeout=2m -parallel=4 github.com/hashicorp/terraform/helper/validation
ok  	github.com/hashicorp/terraform/helper/validation	1.106s
```
2018-10-17 14:22:29 -04:00
craigatgoogle 7df15ad98a Added FloatBetween validation func
Added lower bound inclusion test for FloatBetween
2018-08-06 16:32:39 -07:00
Adit Sarfaty dfa623250a helper/validation: IP address and IP address range validation helpers 2018-03-29 09:41:59 -07:00
Brian Flad 994a78dbc7 validation: Return "invalid RFC3339 timestamp" in ValidateRFC3339TimeString 2018-03-15 12:31:31 -04:00
Brian Flad ea64b24cd9 validation: Add ValidateRFC3339TimeString 2018-03-01 23:19:07 -05:00
Chris Marchesi 5da62a44f4
helper/validation: Fix comment on StringMatch
To match the current implementation.
2017-12-01 10:52:25 -08:00
Chris Marchesi e33aa9dc2e
helper/validation: Add StringMatch
StringMatch returns a validation function that can be used to match a
string against a regular expression. This can be used for simple
substring validations or more complex validation scenarios. Optionally,
an error message can be returned so that the user is returned a better
error message other than that their field did not match a regular
expression that they might not be able to understand.
2017-11-27 17:16:15 -08:00
Chris Marchesi edb8e8904c
helper/validation: Add NoZeroValues
This adds NoZeroValues, a small SchemaValidateFunc that checks that a
defined value is not a zero value. It's useful for situations where you
want to keep someone from explicitly entering a zero value (ie:
literally "0", or an empty string) on a required field, and want to
catch it in the validation stage, versus during apply using GetOk.
2017-09-25 17:19:23 -07:00
Chris Marchesi 61971f2dde
helper/validation: Fix validation package
That'll teach me to use the GitHub merge conflict resolver :P
2017-08-28 14:41:01 -07:00
Chris Marchesi b0152f6be3 Add newline to end of validation.go 2017-08-28 13:49:11 -07:00
Chris Marchesi f17e14f576 Merge branch 'master' into f-validate-list-no-duplicates 2017-08-28 13:45:16 -07:00
Chris Marchesi aacfc01945
helper/validation: Add ValidateListUniqueStrings
Add the ValidateListUniqueStrings function, which is a ValidateFunc that
ensures a list has no duplicate items in it. It's useful for when a list
is needed over a set because order matters, yet the items still need to
be unique.
2017-08-27 09:50:21 -07:00
Chris Marchesi afeeecd10d
helper/validation: Add ValidateRegexp
This adds a ValidateRegexp validation helper to check to see if a field
has a valid regular expression.

Includes test for good regexp, and test for bad regexp.
2017-08-26 10:07:10 -07:00
Riley Karson 8cf04f8e4e Added IntAtLeast and IntAtMost validation functions. (#15403) 2017-06-27 17:25:51 +03:00
tombuildsstuff 277d1b6b2d Refactoring the schema diff/validation -> core 2017-03-27 15:41:55 +01:00
Joseph Anthony Pasquale Holsten 855adb47ed alicloud: simplify validators (#12982) 2017-03-23 10:57:11 +02:00
Paul Tyng fead481002 Fix typo in test method name (#10370) 2016-11-25 16:20:12 +00:00
Peter McAtominey 8abec085ec helper: create validation package to provide common validation functions 2016-08-10 13:27:49 +01:00