Skip to content

Commit 5eaafe4

Browse files
BenjaminGuzmanndeloof
authored andcommitted
Fixed issue when project name contains dashes (-)
Signed-off-by: Benjamín Guzmán <[email protected]>
1 parent 7840a92 commit 5eaafe4

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

pkg/compose/viz.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,19 @@ func (s *composeService) Viz(_ context.Context, project *types.Project, opts api
4242

4343
// build graphviz graph
4444
var graphBuilder strings.Builder
45-
graphBuilder.WriteString("digraph " + project.Name + " {\n")
45+
46+
// graph name
47+
graphBuilder.WriteString("digraph ")
48+
writeQuoted(&graphBuilder, project.Name)
49+
graphBuilder.WriteString(" {\n")
50+
51+
// graph layout
52+
// dot is the perfect layout for this use case since graph is directed and hierarchical
4653
graphBuilder.WriteString(opts.Indentation + "layout=dot;\n")
54+
4755
addNodes(&graphBuilder, graph, &opts)
4856
graphBuilder.WriteByte('\n')
57+
4958
addEdges(&graphBuilder, graph, &opts)
5059
graphBuilder.WriteString("}\n")
5160

pkg/compose/viz_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ func TestViz(t *testing.T) {
8282
"external": nil,
8383
},
8484
},
85+
{
86+
Name: "With host IP",
87+
Image: "user/image-name",
88+
DependsOn: map[string]types.ServiceDependency{
89+
"service1": {},
90+
},
91+
Ports: []types.ServicePortConfig{
92+
{
93+
Published: "8888",
94+
Target: 8080,
95+
HostIP: "127.0.0.1",
96+
},
97+
},
98+
},
8599
},
86100
Networks: types.Networks{
87101
"internal": types.NetworkConfig{},
@@ -121,7 +135,7 @@ func TestViz(t *testing.T) {
121135
assert.NotContains(t, graphStr, "\n ", graphStr)
122136

123137
// check digraph name
124-
assert.Contains(t, graphStr, "digraph "+project.Name, graphStr)
138+
assert.Contains(t, graphStr, "digraph \""+project.Name+"\"", graphStr)
125139

126140
// check nodes
127141
for _, service := range project.Services {
@@ -179,7 +193,7 @@ func TestViz(t *testing.T) {
179193
assert.NotContains(t, graphStr, "\n\t\t", graphStr)
180194

181195
// check digraph name
182-
assert.Contains(t, graphStr, "digraph "+project.Name, graphStr)
196+
assert.Contains(t, graphStr, "digraph \""+project.Name+"\"", graphStr)
183197

184198
// check nodes
185199
for _, service := range project.Services {

0 commit comments

Comments
 (0)