Skip to content

Commit

Permalink
[TT-1090] support multiple named configuration + only read default on…
Browse files Browse the repository at this point in the history
…e when explicitly requested (#1009)
  • Loading branch information
Tofel authored Jun 27, 2024
1 parent 687eddc commit ca284b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ type SethConfig interface {
GetSethConfig() *seth.Config
}

type NamedConfiguration interface {
GetConfigurationName() string
type NamedConfigurations interface {
GetConfigurationNames() []string
}

type GlobalTestConfig interface {
Expand Down
20 changes: 10 additions & 10 deletions config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ import (
// it also looks for given configuration name and unmarshals it into the target struct overwriting the root.
// Target needs to be a struct with exported fields with `toml:"field_name"` tags.
func BytesToAnyTomlStruct(logger zerolog.Logger, filename, configurationName string, target any, content []byte) error {
err := toml.Unmarshal(content, target)

if err != nil {
return errors.Wrapf(err, "error unmarshalling config")
}

logger.Debug().Msgf("Successfully unmarshalled %s config file", filename)

var someToml map[string]interface{}
err = toml.Unmarshal(content, &someToml)
err := toml.Unmarshal(content, &someToml)
if err != nil {
return err
}

if configurationName == "" {
logger.Debug().Msgf("No configuration name provided, will read only default configuration.")

err := toml.Unmarshal(content, target)

if err != nil {
return errors.Wrapf(err, "error unmarshalling config")
}

logger.Debug().Msgf("Successfully unmarshalled %s config file", filename)

return nil
}

if _, ok := someToml[configurationName]; !ok {
logger.Debug().Msgf("Config file %s does not contain configuration named '%s', will read only default configuration.", filename, configurationName)
logger.Debug().Msgf("Config file %s does not contain configuration named '%s'. Won't read anything", filename, configurationName)
return nil
}

Expand Down

0 comments on commit ca284b7

Please sign in to comment.