Fix maps race in append and merge tests

This commit is contained in:
Carlos Diaz-Padron 2014-07-28 13:51:13 -07:00
parent 9013777279
commit 47529f829e
2 changed files with 20 additions and 10 deletions

View File

@ -15,14 +15,19 @@ func Append(c1, c2 *Config) (*Config, error) {
// Append unknown keys, but keep them unique since it is a set // Append unknown keys, but keep them unique since it is a set
unknowns := make(map[string]struct{}) unknowns := make(map[string]struct{})
for _, k := range c1.unknownKeys { for _, k := range c1.unknownKeys {
_, present := unknowns[k]
if !present {
unknowns[k] = struct{}{} unknowns[k] = struct{}{}
c.unknownKeys = append(c.unknownKeys, k)
}
} }
for _, k := range c2.unknownKeys { for _, k := range c2.unknownKeys {
_, present := unknowns[k]
if !present {
unknowns[k] = struct{}{} unknowns[k] = struct{}{}
}
for k, _ := range unknowns {
c.unknownKeys = append(c.unknownKeys, k) c.unknownKeys = append(c.unknownKeys, k)
} }
}
if len(c1.Outputs) > 0 || len(c2.Outputs) > 0 { if len(c1.Outputs) > 0 || len(c2.Outputs) > 0 {
c.Outputs = make( c.Outputs = make(

View File

@ -11,14 +11,19 @@ func Merge(c1, c2 *Config) (*Config, error) {
// Merge unknown keys // Merge unknown keys
unknowns := make(map[string]struct{}) unknowns := make(map[string]struct{})
for _, k := range c1.unknownKeys { for _, k := range c1.unknownKeys {
_, present := unknowns[k]
if !present {
unknowns[k] = struct{}{} unknowns[k] = struct{}{}
c.unknownKeys = append(c.unknownKeys, k)
}
} }
for _, k := range c2.unknownKeys { for _, k := range c2.unknownKeys {
_, present := unknowns[k]
if !present {
unknowns[k] = struct{}{} unknowns[k] = struct{}{}
}
for k, _ := range unknowns {
c.unknownKeys = append(c.unknownKeys, k) c.unknownKeys = append(c.unknownKeys, k)
} }
}
// NOTE: Everything below is pretty gross. Due to the lack of generics // NOTE: Everything below is pretty gross. Due to the lack of generics
// in Go, there is some hoop-jumping involved to make this merging a // in Go, there is some hoop-jumping involved to make this merging a