mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
terraform: more passing tests
This commit is contained in:
parent
5b0004ffc7
commit
d0786d20dd
@ -4,6 +4,8 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/errwrap"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/hashicorp/terraform/config/module"
|
||||
"github.com/hashicorp/terraform/dag"
|
||||
)
|
||||
@ -67,11 +69,20 @@ func (c *Context2) GraphBuilder() GraphBuilder {
|
||||
// Validate validates the configuration and returns any warnings or errors.
|
||||
func (c *Context2) Validate() ([]string, []error) {
|
||||
var warns []string
|
||||
var errs []error
|
||||
var errs error
|
||||
|
||||
// Validate the configuration itself
|
||||
if err := c.module.Validate(); err != nil {
|
||||
errs = append(errs, err)
|
||||
errs = multierror.Append(errs, err)
|
||||
}
|
||||
|
||||
// This only needs to be done for the root module, since inter-module
|
||||
// variables are validated in the module tree.
|
||||
if config := c.module.Config(); config != nil {
|
||||
// Validate the user variables
|
||||
if err := smcUserVariables(config, c.variables); len(err) > 0 {
|
||||
errs = multierror.Append(errs, err...)
|
||||
}
|
||||
}
|
||||
|
||||
evalCtx := c.evalContext(walkValidate)
|
||||
@ -105,15 +116,23 @@ func (c *Context2) Validate() ([]string, []error) {
|
||||
|
||||
verr, ok := err.(*EvalValidateError)
|
||||
if !ok {
|
||||
errs = append(errs, err)
|
||||
errs = multierror.Append(errs, err)
|
||||
return
|
||||
}
|
||||
|
||||
warns = append(warns, verr.Warnings...)
|
||||
errs = append(errs, verr.Errors...)
|
||||
errs = multierror.Append(errs, verr.Errors...)
|
||||
})
|
||||
|
||||
return warns, errs
|
||||
// Get the actual list of errors out. We do this by checking if the
|
||||
// error is a error wrapper (multierror is one) and grabbing all the
|
||||
// wrapped errors.
|
||||
var rerrs []error
|
||||
if w, ok := errs.(errwrap.Wrapper); ok {
|
||||
rerrs = w.WrappedErrors()
|
||||
}
|
||||
|
||||
return warns, rerrs
|
||||
}
|
||||
|
||||
func (c *Context2) evalContext(op walkOperation) *BuiltinEvalContext {
|
||||
|
@ -167,6 +167,63 @@ func TestContext2Validate_requiredVar(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Validate_selfRef(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "validate-self-ref")
|
||||
c := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
w, e := c.Validate()
|
||||
if len(w) > 0 {
|
||||
t.Fatalf("bad: %#v", w)
|
||||
}
|
||||
if len(e) == 0 {
|
||||
t.Fatalf("bad: %s", e)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Validate_selfRefMulti(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "validate-self-ref-multi")
|
||||
c := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
w, e := c.Validate()
|
||||
if len(w) > 0 {
|
||||
t.Fatalf("bad: %#v", w)
|
||||
}
|
||||
if len(e) == 0 {
|
||||
t.Fatalf("bad: %#v", e)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Validate_selfRefMultiAll(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "validate-self-ref-multi-all")
|
||||
c := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
w, e := c.Validate()
|
||||
if len(w) > 0 {
|
||||
t.Fatalf("bad: %#v", w)
|
||||
}
|
||||
if len(e) == 0 {
|
||||
t.Fatalf("bad: %#v", e)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func TestContextValidate_goodModule(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
@ -468,63 +525,6 @@ func TestContextValidate_provisionerConfig_good(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextValidate_selfRef(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "validate-self-ref")
|
||||
c := testContext(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
w, e := c.Validate()
|
||||
if len(w) > 0 {
|
||||
t.Fatalf("bad: %#v", w)
|
||||
}
|
||||
if len(e) == 0 {
|
||||
t.Fatalf("bad: %#v", e)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextValidate_selfRefMulti(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "validate-self-ref-multi")
|
||||
c := testContext(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
w, e := c.Validate()
|
||||
if len(w) > 0 {
|
||||
t.Fatalf("bad: %#v", w)
|
||||
}
|
||||
if len(e) == 0 {
|
||||
t.Fatalf("bad: %#v", e)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextValidate_selfRefMultiAll(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "validate-self-ref-multi-all")
|
||||
c := testContext(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
w, e := c.Validate()
|
||||
if len(w) > 0 {
|
||||
t.Fatalf("bad: %#v", w)
|
||||
}
|
||||
if len(e) == 0 {
|
||||
t.Fatalf("bad: %#v", e)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextValidate_varRef(t *testing.T) {
|
||||
m := testModule(t, "validate-variable-ref")
|
||||
p := testProvider("aws")
|
||||
|
Loading…
Reference in New Issue
Block a user