osel/viper_test.go
Nate Johnston ca0e1ca769 Initial import of osel code
This is an initial import of the osel codebase.  The osel tool is a tool that
initiates external security scans (initially through Qualys) upon reciept of
AMQP events that indicate certain sensitive events have occurred, like a
security group rule change.

The commit history had to be thrown away because it contained some non-public
data, so I would like to call out the following contributors:

This uses go 1.10 and vgo for dependency management.

Co-Authored-By: Charles Bitter <Charles_Bitter@cable.comcast.com>
Co-Authored-By: Olivier Gagnon <Olivier_Gagnon@cable.comcast.com>
Co-Authored-By: Joseph Sleiman <Joseph_Sleiman@comcast.com>

Change-Id: Ib6abe2024fd91978b783ceee4cff8bb4678d7b15
2018-03-24 15:30:57 +00:00

43 lines
1.6 KiB
Go

package main
import (
"github.com/nate-johnston/viper"
"github.com/stretchr/testify/assert"
"testing"
)
func TestInitViperWillReturnErrorOnReadError(t *testing.T) {
err := InitViper("fixtures/viper/not_there.yml", nil)
assert.NotNil(t, err)
assert.Equal(t, "open fixtures/viper/not_there.yml: no such file or directory", err.Error())
}
func TestInitViperEnsureItCallsValidateConfigWithConfigErrors(t *testing.T) {
// By calling InitViper and expecting an error case we prove that IniViper is
// calling ValidateConfig() and its working as expected.
viperConfigs := []ViperConfig{
ViperConfig{Key: "missing_required_string", Description: "Required String"},
}
err := InitViper("fixtures/viper/test.yml", viperConfigs)
assert.NotNil(t, err)
assert.Equal(t, "Required Configuration Missing: [Key: missing_required_string, Description: Required String]",
err.Error())
}
func TestValidateConfig(t *testing.T) {
viperConfigs := []ViperConfig{
ViperConfig{Key: "required_string", Description: "Required String"},
ViperConfig{Key: "nested.one", Description: "Required Nested One"},
ViperConfig{Key: "test_default", Default: "Optional Value", Description: "Optional Value"},
ViperConfig{Key: "test_alias", Alias: []string{"bubba", "forest"}, Description: "Optional Value"},
}
InitViper("fixtures/viper/test.yml", viperConfigs)
err := ValidateConfig(viperConfigs)
assert.Nil(t, err)
assert.Equal(t, "Optional Value", viper.GetString("test_default"))
assert.Equal(t, "test_alias value", viper.GetString("test_alias"))
assert.Equal(t, "test_alias value", viper.GetString("bubba"))
assert.Equal(t, "test_alias value", viper.GetString("forest"))
}