/
validate.go
35 lines (29 loc) · 1.16 KB
/
validate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package terraform
import (
"github.com/gruntwork-io/terratest/modules/testing"
"github.com/stretchr/testify/require"
)
// Validate calls terraform validate and returns stdout/stderr.
func Validate(t testing.TestingT, options *Options) string {
out, err := ValidateE(t, options)
require.NoError(t, err)
return out
}
// ValidateE calls terraform validate and returns stdout/stderr.
func ValidateE(t testing.TestingT, options *Options) (string, error) {
return RunTerraformCommandE(t, options, FormatArgs(options, "validate")...)
}
// InitAndValidate runs terraform init and validate with the given options and returns stdout/stderr from the validate command.
// This will fail the test if there is an error in the command.
func InitAndValidate(t testing.TestingT, options *Options) string {
out, err := InitAndValidateE(t, options)
require.NoError(t, err)
return out
}
// InitAndValidateE runs terraform init and validate with the given options and returns stdout/stderr from the validate command.
func InitAndValidateE(t testing.TestingT, options *Options) (string, error) {
if _, err := InitE(t, options); err != nil {
return "", err
}
return ValidateE(t, options)
}