Skip to content

Commit

Permalink
chore: update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Jan 7, 2025
1 parent f4a816b commit 30af3d2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/db/branch/switch_/switch__test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestSwitchCommand(t *testing.T) {
// Run test
err := Run(context.Background(), "target", fsys)
// Check error
assert.ErrorContains(t, err, "toml: line 0: unexpected EOF; expected key separator '='")
assert.ErrorContains(t, err, "toml: expected = after a key, but the document ends there")
})

t.Run("throws error on missing database", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/start/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestStartCommand(t *testing.T) {
// Run test
err := Run(context.Background(), fsys, []string{}, false)
// Check error
assert.ErrorContains(t, err, "toml: line 0: unexpected EOF; expected key separator '='")
assert.ErrorContains(t, err, "toml: expected = after a key, but the document ends there")
})

t.Run("throws error on missing docker", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/status/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestStatusCommand(t *testing.T) {
// Run test
err := Run(context.Background(), CustomName{}, utils.OutputPretty, fsys)
// Check error
assert.ErrorContains(t, err, "toml: line 0: unexpected EOF; expected key separator '='")
assert.ErrorContains(t, err, "toml: expected = after a key, but the document ends there")
})

t.Run("throws error on missing docker", func(t *testing.T) {
Expand Down
12 changes: 8 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ func (c *config) loadFromFile(filename string, fsys fs.FS) error {
var buf bytes.Buffer
if err := initConfigTemplate.Option("missingkey=zero").Execute(&buf, c); err != nil {
return errors.Errorf("failed to initialise template config: %w", err)
} else if err := v.MergeConfig(&buf); err != nil {
return errors.Errorf("failed to merge template config: %w", err)
} else if err := c.loadFromReader(v, &buf); err != nil {
return err
}
// Load custom config
if ext := filepath.Ext(filename); len(ext) > 0 {
Expand All @@ -399,8 +399,12 @@ func (c *config) loadFromFile(filename string, fsys fs.FS) error {
return errors.Errorf("failed to read file config: %w", err)
}
defer f.Close()
if err := v.MergeConfig(f); err != nil {
return errors.Errorf("failed to merge file config: %w", err)
return c.loadFromReader(v, f)
}

func (c *config) loadFromReader(v *viper.Viper, r io.Reader) error {
if err := v.MergeConfig(r); err != nil {
return errors.Errorf("failed to merge config: %w", err)
}
// Manually parse [functions.*] to empty struct for backwards compatibility
for key, value := range v.GetStringMap("functions") {
Expand Down

0 comments on commit 30af3d2

Please sign in to comment.