Skip to content

Commit

Permalink
Fix all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
silphid committed May 19, 2021
1 parent cd47b5d commit 3c0c504
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/internal/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ func loadContext(file string) Context {
if !helpers.PathExists(path) {
panic(fmt.Errorf("context file not found: %q", path))
}
context, err := Load(path)
contexts, err := readAndParseContextFile(path)
if err != nil {
panic(fmt.Errorf("loading context from %q: %w", path, err))
}
return context.Context
return contexts.Context
}

func assertNotSameMapStringString(t *testing.T, map1, map2 map[string]string, msgAndArgs ...interface{}) {
Expand Down
26 changes: 11 additions & 15 deletions src/internal/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,24 @@ type Contexts struct {
contexts map[string]Context
}

// Clone returns a deep-copy of this object
func (c Contexts) Clone() Contexts {
clone := c
for key, value := range c.contexts {
clone.contexts[key] = value.Clone()
}
return clone
}

// Merge creates a deep-copy of this object and copies values from given source object on top of it
func (c Contexts) Merge(source Contexts) Contexts {
clone := c.Clone()
clone.Context.Merge(source.Context)
merged := Contexts{
Context: c.Context.Merge(source.Context),
contexts: make(map[string]Context),
}
for key, value := range c.contexts {
merged.contexts[key] = value.Clone()
}
for key, value := range source.contexts {
existing, ok := clone.contexts[key]
existing, ok := merged.contexts[key]
if ok {
c.contexts[key] = existing.Merge(value)
merged.contexts[key] = existing.Merge(value)
} else {
c.contexts[key] = value
merged.contexts[key] = value
}
}
return clone
return merged
}

// GetContextNames returns the list of all context names user can choose from,
Expand Down

0 comments on commit 3c0c504

Please sign in to comment.