Skip to content

Commit

Permalink
Fix maps race in append and merge tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdp committed Jul 29, 2014
1 parent 9013777 commit 47529f8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
15 changes: 10 additions & 5 deletions config/append.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ func Append(c1, c2 *Config) (*Config, error) {
// Append unknown keys, but keep them unique since it is a set
unknowns := make(map[string]struct{})
for _, k := range c1.unknownKeys {
unknowns[k] = struct{}{}
_, present := unknowns[k]
if !present {
unknowns[k] = struct{}{}
c.unknownKeys = append(c.unknownKeys, k)
}
}
for _, k := range c2.unknownKeys {
unknowns[k] = struct{}{}
}
for k, _ := range unknowns {
c.unknownKeys = append(c.unknownKeys, k)
_, present := unknowns[k]
if !present {
unknowns[k] = struct{}{}
c.unknownKeys = append(c.unknownKeys, k)
}
}

if len(c1.Outputs) > 0 || len(c2.Outputs) > 0 {
Expand Down
15 changes: 10 additions & 5 deletions config/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ func Merge(c1, c2 *Config) (*Config, error) {
// Merge unknown keys
unknowns := make(map[string]struct{})
for _, k := range c1.unknownKeys {
unknowns[k] = struct{}{}
_, present := unknowns[k]
if !present {
unknowns[k] = struct{}{}
c.unknownKeys = append(c.unknownKeys, k)
}
}
for _, k := range c2.unknownKeys {
unknowns[k] = struct{}{}
}
for k, _ := range unknowns {
c.unknownKeys = append(c.unknownKeys, k)
_, present := unknowns[k]
if !present {
unknowns[k] = struct{}{}
c.unknownKeys = append(c.unknownKeys, k)
}
}

// NOTE: Everything below is pretty gross. Due to the lack of generics
Expand Down

0 comments on commit 47529f8

Please sign in to comment.