Merge pull request #25251 from hashicorp/jbardin/dot

quote dot node names
This commit is contained in:
James Bardin 2020-06-15 14:46:34 -04:00 committed by GitHub
commit 3506f159aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 4 deletions

View File

@ -33,7 +33,7 @@ func TestGraph(t *testing.T) {
}
output := ui.OutputWriter.String()
if !strings.Contains(output, `provider["registry.terraform.io/hashicorp/test"]`) {
if !strings.Contains(output, `provider[\"registry.terraform.io/hashicorp/test\"]`) {
t.Fatalf("doesn't look like digraph: %s", output)
}
}
@ -80,7 +80,7 @@ func TestGraph_noArgs(t *testing.T) {
}
output := ui.OutputWriter.String()
if !strings.Contains(output, `provider["registry.terraform.io/hashicorp/test"]`) {
if !strings.Contains(output, `provider[\"registry.terraform.io/hashicorp/test\"]`) {
t.Fatalf("doesn't look like digraph: %s", output)
}
}
@ -161,7 +161,7 @@ func TestGraph_plan(t *testing.T) {
}
output := ui.OutputWriter.String()
if !strings.Contains(output, `provider["registry.terraform.io/hashicorp/test"]`) {
if !strings.Contains(output, `provider[\"registry.terraform.io/hashicorp/test\"]`) {
t.Fatalf("doesn't look like digraph: %s", output)
}
}

View File

@ -108,9 +108,14 @@ func newMarshalVertex(v Vertex) *marshalVertex {
dn = nil
}
// the name will be quoted again later, so we need to ensure it's properly
// escaped without quotes.
name := strconv.Quote(VertexName(v))
name = name[1 : len(name)-1]
return &marshalVertex{
ID: marshalVertexID(v),
Name: VertexName(v),
Name: name,
Attrs: make(map[string]string),
graphNodeDotter: dn,
}

View File

@ -32,6 +32,21 @@ func TestGraphDot_basic(t *testing.T) {
}
}
func TestGraphDot_quoted(t *testing.T) {
var g Graph
quoted := `name["with-quotes"]`
other := `other`
g.Add(quoted)
g.Add(other)
g.Connect(BasicEdge(quoted, other))
actual := strings.TrimSpace(string(g.Dot(nil)))
expected := strings.TrimSpace(testGraphDotQuotedStr)
if actual != expected {
t.Fatalf("\ngot: %q\nwanted %q\n", actual, expected)
}
}
func TestGraphDot_attrs(t *testing.T) {
var g Graph
g.Add(&testGraphNodeDotter{
@ -53,6 +68,14 @@ type testGraphNodeDotter struct{ Result *DotNode }
func (n *testGraphNodeDotter) Name() string { return n.Result.Name }
func (n *testGraphNodeDotter) DotNode(string, *DotOpts) *DotNode { return n.Result }
const testGraphDotQuotedStr = `digraph {
compound = "true"
newrank = "true"
subgraph "root" {
"[root] name[\"with-quotes\"]" -> "[root] other"
}
}`
const testGraphDotBasicStr = `digraph {
compound = "true"
newrank = "true"