Merge pull request #61 from carlosdp/fix-maps-race

Fix maps iteration order error in append_test, merge_test, and graphviz_test
This commit is contained in:
Mitchell Hashimoto 2014-08-05 10:34:09 -07:00
commit 8c7b80d172
3 changed files with 41 additions and 11 deletions

View File

@ -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 {

View File

@ -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

View File

@ -24,7 +24,27 @@ b -> e
actual := strings.TrimSpace(string(buf.Bytes()))
expected := strings.TrimSpace(writeDotStr)
if actual != expected {
actualLines := strings.Split(actual, "\n")
expectedLines := strings.Split(expected, "\n")
if actualLines[0] != expectedLines[0] ||
actualLines[len(actualLines)-1] != expectedLines[len(expectedLines)-1] ||
len(actualLines) != len(expectedLines) {
t.Fatalf("bad: %s", actual)
}
count := 0
for _, el := range expectedLines[1 : len(expectedLines)-1] {
for _, al := range actualLines[1 : len(actualLines)-1] {
if el == al {
count++
break
}
}
}
if count != len(expectedLines)-2 {
t.Fatalf("bad: %s", actual)
}
}