From 5eaafe42370d6143025cf9563856f3142659fbb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjam=C3=ADn=20Guzm=C3=A1n?= Date: Sat, 8 Apr 2023 12:59:01 -0600 Subject: [PATCH] Fixed issue when project name contains dashes (`-`) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Benjamín Guzmán --- pkg/compose/viz.go | 11 ++++++++++- pkg/compose/viz_test.go | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/pkg/compose/viz.go b/pkg/compose/viz.go index 4d932ee44..f87056856 100644 --- a/pkg/compose/viz.go +++ b/pkg/compose/viz.go @@ -42,10 +42,19 @@ func (s *composeService) Viz(_ context.Context, project *types.Project, opts api // build graphviz graph var graphBuilder strings.Builder - graphBuilder.WriteString("digraph " + project.Name + " {\n") + + // graph name + graphBuilder.WriteString("digraph ") + writeQuoted(&graphBuilder, project.Name) + graphBuilder.WriteString(" {\n") + + // graph layout + // dot is the perfect layout for this use case since graph is directed and hierarchical graphBuilder.WriteString(opts.Indentation + "layout=dot;\n") + addNodes(&graphBuilder, graph, &opts) graphBuilder.WriteByte('\n') + addEdges(&graphBuilder, graph, &opts) graphBuilder.WriteString("}\n") diff --git a/pkg/compose/viz_test.go b/pkg/compose/viz_test.go index 15425b904..cf9452c58 100644 --- a/pkg/compose/viz_test.go +++ b/pkg/compose/viz_test.go @@ -82,6 +82,20 @@ func TestViz(t *testing.T) { "external": nil, }, }, + { + Name: "With host IP", + Image: "user/image-name", + DependsOn: map[string]types.ServiceDependency{ + "service1": {}, + }, + Ports: []types.ServicePortConfig{ + { + Published: "8888", + Target: 8080, + HostIP: "127.0.0.1", + }, + }, + }, }, Networks: types.Networks{ "internal": types.NetworkConfig{}, @@ -121,7 +135,7 @@ func TestViz(t *testing.T) { assert.NotContains(t, graphStr, "\n ", graphStr) // check digraph name - assert.Contains(t, graphStr, "digraph "+project.Name, graphStr) + assert.Contains(t, graphStr, "digraph \""+project.Name+"\"", graphStr) // check nodes for _, service := range project.Services { @@ -179,7 +193,7 @@ func TestViz(t *testing.T) { assert.NotContains(t, graphStr, "\n\t\t", graphStr) // check digraph name - assert.Contains(t, graphStr, "digraph "+project.Name, graphStr) + assert.Contains(t, graphStr, "digraph \""+project.Name+"\"", graphStr) // check nodes for _, service := range project.Services {