mirror of
https://github.com/docker/compose.git
synced 2025-07-21 20:54:32 +02:00
Fixed issue when project name contains dashes (-
)
Signed-off-by: Benjamín Guzmán <bg@benjaminguzman.dev>
This commit is contained in:
parent
7840a92c40
commit
5eaafe4237
@ -42,10 +42,19 @@ func (s *composeService) Viz(_ context.Context, project *types.Project, opts api
|
|||||||
|
|
||||||
// build graphviz graph
|
// build graphviz graph
|
||||||
var graphBuilder strings.Builder
|
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")
|
graphBuilder.WriteString(opts.Indentation + "layout=dot;\n")
|
||||||
|
|
||||||
addNodes(&graphBuilder, graph, &opts)
|
addNodes(&graphBuilder, graph, &opts)
|
||||||
graphBuilder.WriteByte('\n')
|
graphBuilder.WriteByte('\n')
|
||||||
|
|
||||||
addEdges(&graphBuilder, graph, &opts)
|
addEdges(&graphBuilder, graph, &opts)
|
||||||
graphBuilder.WriteString("}\n")
|
graphBuilder.WriteString("}\n")
|
||||||
|
|
||||||
|
@ -82,6 +82,20 @@ func TestViz(t *testing.T) {
|
|||||||
"external": nil,
|
"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{
|
Networks: types.Networks{
|
||||||
"internal": types.NetworkConfig{},
|
"internal": types.NetworkConfig{},
|
||||||
@ -121,7 +135,7 @@ func TestViz(t *testing.T) {
|
|||||||
assert.NotContains(t, graphStr, "\n ", graphStr)
|
assert.NotContains(t, graphStr, "\n ", graphStr)
|
||||||
|
|
||||||
// check digraph name
|
// check digraph name
|
||||||
assert.Contains(t, graphStr, "digraph "+project.Name, graphStr)
|
assert.Contains(t, graphStr, "digraph \""+project.Name+"\"", graphStr)
|
||||||
|
|
||||||
// check nodes
|
// check nodes
|
||||||
for _, service := range project.Services {
|
for _, service := range project.Services {
|
||||||
@ -179,7 +193,7 @@ func TestViz(t *testing.T) {
|
|||||||
assert.NotContains(t, graphStr, "\n\t\t", graphStr)
|
assert.NotContains(t, graphStr, "\n\t\t", graphStr)
|
||||||
|
|
||||||
// check digraph name
|
// check digraph name
|
||||||
assert.Contains(t, graphStr, "digraph "+project.Name, graphStr)
|
assert.Contains(t, graphStr, "digraph \""+project.Name+"\"", graphStr)
|
||||||
|
|
||||||
// check nodes
|
// check nodes
|
||||||
for _, service := range project.Services {
|
for _, service := range project.Services {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user