Skip to content
Snippets Groups Projects
Commit 39685807 authored by Florent Aide's avatar Florent Aide
Browse files

runner: add the first config struct to read beaver.yml config

parent b790ba21
No related branches found
No related tags found
No related merge requests found
...@@ -6,5 +6,6 @@ ...@@ -6,5 +6,6 @@
github.com/go-cmd/cmd v1.4.1 // indirect github.com/go-cmd/cmd v1.4.1 // indirect
github.com/orus-io/go-flags v1.4.0 github.com/orus-io/go-flags v1.4.0
github.com/rs/zerolog v1.26.1 github.com/rs/zerolog v1.26.1
github.com/spf13/viper v1.11.0 // indirect
github.com/stretchr/testify v1.7.1 // indirect github.com/stretchr/testify v1.7.1 // indirect
) )
This diff is collapsed.
package runner
import (
"github.com/spf13/viper"
)
type Variable struct {
Name string `mapstructure:"name"`
Value string `mapstructure:"value"`
}
type Spec struct {
Variables []Variable `mapstructure:"variables"`
}
type Config struct {
APIVersion string `mapstructure:"apiVersion"`
Kind string `mapstructure:"kind"`
Spec Spec `mapstructure:"spec"`
}
func NewConfig(configDir string) (*Config, error) {
// we ONLY search for files named beaver.yml
viper.SetConfigName("beaver")
viper.AddConfigPath(configDir)
if err := viper.ReadInConfig(); err != nil {
return nil, err
}
var config Config
if err := viper.Unmarshal(&config); err != nil {
return nil, err
}
return &config, nil
}
package runner
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestConfig(t *testing.T) {
configDir := "fixtures/"
config, err := NewConfig(configDir)
require.NoError(t, err)
// first config.spec.variables entry name should be VAULT_KV in our test file
assert.Equal(t, "VAULT_KV", config.Spec.Variables[0].Name)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment