terraform: Context.Graph

This commit is contained in:
Mitchell Hashimoto 2014-07-12 19:23:56 -07:00
parent b4b116a018
commit 4dea4c325b
2 changed files with 39 additions and 0 deletions

View File

@ -127,6 +127,11 @@ func (c *Context) Apply() (*State, error) {
return c.state, err return c.state, err
} }
// Graph returns the graph for this context.
func (c *Context) Graph() (*depgraph.Graph, error) {
return c.graph()
}
// Plan generates an execution plan for the given context. // Plan generates an execution plan for the given context.
// //
// The execution plan encapsulates the context and can be stored // The execution plan encapsulates the context and can be stored

View File

@ -7,6 +7,28 @@ import (
"testing" "testing"
) )
func TestContextGraph(t *testing.T) {
p := testProvider("aws")
config := testConfig(t, "validate-good")
c := testContext(t, &ContextOpts{
Config: config,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
g, err := c.Graph()
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(g.String())
expected := strings.TrimSpace(testContextGraph)
if actual != expected {
t.Fatalf("bad: %s", actual)
}
}
func TestContextValidate(t *testing.T) { func TestContextValidate(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
config := testConfig(t, "validate-good") config := testConfig(t, "validate-good")
@ -1605,3 +1627,15 @@ func testProvisioner() *MockResourceProvisioner {
p := new(MockResourceProvisioner) p := new(MockResourceProvisioner)
return p return p
} }
const testContextGraph = `
root: root
aws_instance.bar
aws_instance.bar -> provider.aws
aws_instance.foo
aws_instance.foo -> provider.aws
provider.aws
root
root -> aws_instance.bar
root -> aws_instance.foo
`