Merge pull request #25251 from hashicorp/jbardin/dot
quote dot node names
This commit is contained in:
commit
3506f159aa
|
@ -33,7 +33,7 @@ func TestGraph(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
output := ui.OutputWriter.String()
|
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)
|
t.Fatalf("doesn't look like digraph: %s", output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ func TestGraph_noArgs(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
output := ui.OutputWriter.String()
|
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)
|
t.Fatalf("doesn't look like digraph: %s", output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ func TestGraph_plan(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
output := ui.OutputWriter.String()
|
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)
|
t.Fatalf("doesn't look like digraph: %s", output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,9 +108,14 @@ func newMarshalVertex(v Vertex) *marshalVertex {
|
||||||
dn = nil
|
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{
|
return &marshalVertex{
|
||||||
ID: marshalVertexID(v),
|
ID: marshalVertexID(v),
|
||||||
Name: VertexName(v),
|
Name: name,
|
||||||
Attrs: make(map[string]string),
|
Attrs: make(map[string]string),
|
||||||
graphNodeDotter: dn,
|
graphNodeDotter: dn,
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
func TestGraphDot_attrs(t *testing.T) {
|
||||||
var g Graph
|
var g Graph
|
||||||
g.Add(&testGraphNodeDotter{
|
g.Add(&testGraphNodeDotter{
|
||||||
|
@ -53,6 +68,14 @@ type testGraphNodeDotter struct{ Result *DotNode }
|
||||||
func (n *testGraphNodeDotter) Name() string { return n.Result.Name }
|
func (n *testGraphNodeDotter) Name() string { return n.Result.Name }
|
||||||
func (n *testGraphNodeDotter) DotNode(string, *DotOpts) *DotNode { return n.Result }
|
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 {
|
const testGraphDotBasicStr = `digraph {
|
||||||
compound = "true"
|
compound = "true"
|
||||||
newrank = "true"
|
newrank = "true"
|
||||||
|
|
Loading…
Reference in New Issue