diff options
author | Nick Thomas <nick@gitlab.com> | 2017-04-24 19:31:28 +0300 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2017-04-24 19:36:52 +0300 |
commit | 829176ac76c1dc25373800824602261940fca121 (patch) | |
tree | abb862b0ab1466be47c28d51d65e43bc5a53dd69 | |
parent | 9851a84c2af522d982ce4a1f1b6521503b11c512 (diff) |
Fix reading configuration for multiple custom domains
Without this patch, the different domains end up with pointers to the same
domainsConfig struct, as go re-uses the same region of memory on each iteration
of a for loop.
-rw-r--r-- | domains.go | 3 | ||||
-rw-r--r-- | domains_test.go | 7 | ||||
-rw-r--r-- | shared/pages/group/group.test.io/config.json | 2 |
3 files changed, 10 insertions, 2 deletions
@@ -44,8 +44,9 @@ func (d domains) readProjectConfig(rootDomain, group, project string) (err error } for _, domainConfig := range config.Domains { + config := domainConfig // domainConfig is reused for each loop iteration if domainConfig.Valid(rootDomain) { - d.addDomain(rootDomain, group, project, &domainConfig) + d.addDomain(rootDomain, group, project, &config) } } return diff --git a/domains_test.go b/domains_test.go index 5a2882d6..6ce11f5f 100644 --- a/domains_test.go +++ b/domains_test.go @@ -40,6 +40,13 @@ func TestReadProjects(t *testing.T) { for _, actual := range domains { assert.Contains(t, expectedDomains, actual) } + + // Check that multiple domains in the same project are recorded faithfully + exp1 := &domainConfig{Domain: "test.domain.com"} + assert.Equal(t, exp1, d["test.domain.com"].Config) + + exp2 := &domainConfig{Domain: "other.domain.com", Certificate: "test", Key: "key"} + assert.Equal(t, exp2, d["other.domain.com"].Config) } func writeRandomTimestamp() { diff --git a/shared/pages/group/group.test.io/config.json b/shared/pages/group/group.test.io/config.json index 1643525d..5b9be1fd 100644 --- a/shared/pages/group/group.test.io/config.json +++ b/shared/pages/group/group.test.io/config.json @@ -9,7 +9,7 @@ { "Domain": "other.domain.com", "Certificate": "test", - "Certificate": "key" + "Key": "key" } ] } |