Skip to content

Commit

Permalink
Fix conflicting hostname problem by making list unique, fixes #789 (#825
Browse files Browse the repository at this point in the history
)
  • Loading branch information
rfay committed May 21, 2018
1 parent 0626755 commit addffd6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
18 changes: 14 additions & 4 deletions pkg/ddevapp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,23 @@ func (app *DdevApp) GetHostname() string {
// GetHostnames returns an array of all the configured hostnames.
func (app *DdevApp) GetHostnames() []string {

var nameList []string
nameList = append(nameList, app.GetHostname())
// Use a map to make sure that we have unique hostnames
// The value is useless, so just use the int 1 for assignment.
nameListMap := make(map[string]int)

nameListMap[app.GetHostname()] = 1

for _, name := range app.AdditionalHostnames {
nameList = append(nameList, name+"."+version.DDevTLD)
nameListMap[name+"."+version.DDevTLD] = 1
}

// Now walk the map and extract the keys into an array.
nameListArray := make([]string, 0, len(nameListMap))
for k := range nameListMap {
nameListArray = append(nameListArray, k)
}
return nameList

return nameListArray
}

// WriteDockerComposeConfig writes a docker-compose.yaml to the app configuration directory.
Expand Down
5 changes: 4 additions & 1 deletion pkg/ddevapp/ddevapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ func TestDdevStartMultipleHostnames(t *testing.T) {
err := app.Init(site.Dir)
assert.NoError(err)

app.AdditionalHostnames = []string{"sub1." + site.Name, "sub2." + site.Name, "subname.sub3." + site.Name}
// site.Name is explicitly added because if not removed in GetHostNames() it will cause ddev-router failure
// "a" is repeated for the same reason; a user error of this type should not cause a failure; GetHostNames()
// should uniqueify them.
app.AdditionalHostnames = []string{"sub1." + site.Name, "sub2." + site.Name, "subname.sub3." + site.Name, site.Name, site.Name, site.Name}

err = app.WriteConfig()
assert.NoError(err)
Expand Down

0 comments on commit addffd6

Please sign in to comment.