Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion loader/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func TestValidateContainerName(t *testing.T) {
},
}
err := project.CheckContainerNameUnicity()
assert.Assert(t, strings.Contains(err.Error(), `container name "mycontainer" is already in use by`))
assert.Assert(t, strings.Contains(err.Error(), `container name "mycontainer" is already in use by service "myservice`))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert.Assert(t, strings.Contains(err.Error(), `container name "mycontainer" is already in use by service "myservice`))
assert.Error(t, err, `services.myservice2: container name "mycontainer" is already in use by service "myservice"`)

}

func TestValidateWatch(t *testing.T) {
Expand Down
9 changes: 5 additions & 4 deletions types/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -1026,13 +1026,14 @@ func (p *Project) WithServicesTransform(fn func(name string, s ServiceConfig) (S

// CheckContainerNameUnicity validate project doesn't have services declaring the same container_name
func (p *Project) CheckContainerNameUnicity() error {
names := utils.Set[string]{}
for name, s := range p.Services {
names := map[string]string{}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clearly distinguish these from service names. Please apply the rename at usage sites too.

Suggested change
names := map[string]string{}
containerNames := map[string]string{}

for _, name := range p.ServiceNames() {
s := p.Services[name]
if s.ContainerName != "" {
if existing, ok := names[s.ContainerName]; ok {
return fmt.Errorf(`services.%s: container name %q is already in use by service %s"`, name, s.ContainerName, existing)
return fmt.Errorf(`services.%s: container name %q is already in use by service %q`, name, s.ContainerName, existing)
}
names.Add(s.ContainerName)
names[s.ContainerName] = name
}
}
return nil
Expand Down