Skip to content

Commit

Permalink
fix: config not read properly (#673)
Browse files Browse the repository at this point in the history
The config file was not read properly because `rawConfig` fields were
made unexported in a previous PR (#672)

BEGIN_COMMIT_OVERRIDE
test: make state config mockable
END_COMMIT_OVERRIDE
  • Loading branch information
phm07 authored Jan 11, 2024
1 parent a25017e commit d062965
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions internal/state/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ func RemoveContext(cfg Config, context *Context) {
}

type rawConfig struct {
activeContext string
contexts []rawConfigContext
ActiveContext string `toml:"active_context,omitempty"`
Contexts []rawConfigContext `toml:"contexts"`
}

type rawConfigContext struct {
Expand All @@ -135,10 +135,10 @@ type rawConfigContext struct {
func (cfg *config) marshal() ([]byte, error) {
var raw rawConfig
if cfg.activeContext != nil {
raw.activeContext = cfg.activeContext.Name
raw.ActiveContext = cfg.activeContext.Name
}
for _, context := range cfg.contexts {
raw.contexts = append(raw.contexts, rawConfigContext{
raw.Contexts = append(raw.Contexts, rawConfigContext{
Name: context.Name,
Token: context.Token,
})
Expand All @@ -151,21 +151,21 @@ func (cfg *config) unmarshal(data []byte) error {
if err := toml.Unmarshal(data, &raw); err != nil {
return err
}
for _, rawContext := range raw.contexts {
for _, rawContext := range raw.Contexts {
cfg.contexts = append(cfg.contexts, &Context{
Name: rawContext.Name,
Token: rawContext.Token,
})
}
if raw.activeContext != "" {
if raw.ActiveContext != "" {
for _, c := range cfg.contexts {
if c.Name == raw.activeContext {
if c.Name == raw.ActiveContext {
cfg.activeContext = c
break
}
}
if cfg.activeContext == nil {
return fmt.Errorf("active context %s not found", raw.activeContext)
return fmt.Errorf("active context %s not found", raw.ActiveContext)
}
}
return nil
Expand Down

0 comments on commit d062965

Please sign in to comment.