2015-01-27 23:28:33 +01:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
2015-01-28 07:00:56 +01:00
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/dag"
|
2015-01-27 23:28:33 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestTaintedTransformer(t *testing.T) {
|
|
|
|
mod := testModule(t, "transform-tainted-basic")
|
|
|
|
state := &State{
|
|
|
|
Modules: []*ModuleState{
|
|
|
|
&ModuleState{
|
|
|
|
Path: RootModulePath,
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"aws_instance.web": &ResourceState{
|
|
|
|
Type: "aws_instance",
|
|
|
|
Tainted: []*InstanceState{
|
|
|
|
&InstanceState{ID: "foo"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
g := Graph{Path: RootModulePath}
|
|
|
|
{
|
|
|
|
tf := &ConfigTransformer{Module: mod}
|
|
|
|
if err := tf.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
transform := &TaintedTransformer{State: state}
|
|
|
|
if err := transform.Transform(&g); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
|
|
expected := strings.TrimSpace(testTransformTaintedBasicStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad:\n\n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 07:00:56 +01:00
|
|
|
func TestGraphNodeTaintedResource_impl(t *testing.T) {
|
|
|
|
var _ dag.Vertex = new(graphNodeTaintedResource)
|
|
|
|
var _ dag.NamedVertex = new(graphNodeTaintedResource)
|
|
|
|
var _ GraphNodeProviderConsumer = new(graphNodeTaintedResource)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGraphNodeTaintedResource_ProvidedBy(t *testing.T) {
|
|
|
|
n := &graphNodeTaintedResource{ResourceName: "aws_instance.foo"}
|
2015-02-10 08:32:28 +01:00
|
|
|
if v := n.ProvidedBy(); v[0] != "aws" {
|
2015-01-28 07:00:56 +01:00
|
|
|
t.Fatalf("bad: %#v", v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-27 23:28:33 +01:00
|
|
|
const testTransformTaintedBasicStr = `
|
|
|
|
aws_instance.web
|
|
|
|
aws_instance.web (tainted #1)
|
|
|
|
`
|