forked from TrueCloudLab/distribution
Fix the code and update tests that verify the new code works
Signed-off-by: Milos Gajdos <milosthegajdos@gmail.com>
This commit is contained in:
parent
916b94eb3a
commit
0cf87b1fd1
2 changed files with 47 additions and 6 deletions
|
@ -8,21 +8,39 @@ import (
|
|||
)
|
||||
|
||||
type localConfiguration struct {
|
||||
Version Version `yaml:"version"`
|
||||
Log *Log `yaml:"log"`
|
||||
Version Version `yaml:"version"`
|
||||
Log *Log `yaml:"log"`
|
||||
Notifications []Notif `yaml:"notifications,omitempty"`
|
||||
}
|
||||
|
||||
type Log struct {
|
||||
Formatter string `yaml:"formatter,omitempty"`
|
||||
}
|
||||
|
||||
type Notif struct {
|
||||
Name string `yaml:"name"`
|
||||
}
|
||||
|
||||
var expectedConfig = localConfiguration{
|
||||
Version: "0.1",
|
||||
Log: &Log{
|
||||
Formatter: "json",
|
||||
},
|
||||
Notifications: []Notif{
|
||||
{Name: "foo"},
|
||||
{Name: "bar"},
|
||||
{Name: "car"},
|
||||
},
|
||||
}
|
||||
|
||||
const testConfig = `version: "0.1"
|
||||
log:
|
||||
formatter: "text"
|
||||
notifications:
|
||||
- name: "foo"
|
||||
- name: "bar"
|
||||
- name: "car"`
|
||||
|
||||
type ParserSuite struct{}
|
||||
|
||||
var _ = check.Suite(new(ParserSuite))
|
||||
|
@ -43,17 +61,32 @@ func (suite *ParserSuite) TestParserOverwriteIninitializedPoiner(c *check.C) {
|
|||
},
|
||||
})
|
||||
|
||||
err := p.Parse([]byte(`{version: "0.1", log: {formatter: "text"}}`), &config)
|
||||
err := p.Parse([]byte(testConfig), &config)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(config, check.DeepEquals, expectedConfig)
|
||||
}
|
||||
|
||||
const testConfig2 = `version: "0.1"
|
||||
log:
|
||||
formatter: "text"
|
||||
notifications:
|
||||
- name: "val1"
|
||||
- name: "val2"
|
||||
- name: "car"`
|
||||
|
||||
func (suite *ParserSuite) TestParseOverwriteUnininitializedPoiner(c *check.C) {
|
||||
config := localConfiguration{}
|
||||
|
||||
os.Setenv("REGISTRY_LOG_FORMATTER", "json")
|
||||
defer os.Unsetenv("REGISTRY_LOG_FORMATTER")
|
||||
|
||||
// override only first two notificationsvalues
|
||||
// in the tetConfig: leave the last value unchanged.
|
||||
os.Setenv("REGISTRY_NOTIFICATIONS_0_NAME", "foo")
|
||||
defer os.Unsetenv("REGISTRY_NOTIFICATIONS_0_NAME")
|
||||
os.Setenv("REGISTRY_NOTIFICATIONS_1_NAME", "bar")
|
||||
defer os.Unsetenv("REGISTRY_NOTIFICATIONS_1_NAME")
|
||||
|
||||
p := NewParser("registry", []VersionedParseInfo{
|
||||
{
|
||||
Version: "0.1",
|
||||
|
@ -64,7 +97,7 @@ func (suite *ParserSuite) TestParseOverwriteUnininitializedPoiner(c *check.C) {
|
|||
},
|
||||
})
|
||||
|
||||
err := p.Parse([]byte(`{version: "0.1"}`), &config)
|
||||
err := p.Parse([]byte(testConfig2), &config)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(config, check.DeepEquals, expectedConfig)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue