mirror of
https://github.com/distribution/distribution
synced 2024-11-12 05:45:51 +01:00
3fa6d5a33b
Dot-imports were only used in a couple of places, and replacing them makes it more explicit what's imported. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
71 lines
1.5 KiB
Go
71 lines
1.5 KiB
Go
package configuration
|
|
|
|
import (
|
|
"os"
|
|
"reflect"
|
|
|
|
"gopkg.in/check.v1"
|
|
)
|
|
|
|
type localConfiguration struct {
|
|
Version Version `yaml:"version"`
|
|
Log *Log `yaml:"log"`
|
|
}
|
|
|
|
type Log struct {
|
|
Formatter string `yaml:"formatter,omitempty"`
|
|
}
|
|
|
|
var expectedConfig = localConfiguration{
|
|
Version: "0.1",
|
|
Log: &Log{
|
|
Formatter: "json",
|
|
},
|
|
}
|
|
|
|
type ParserSuite struct{}
|
|
|
|
var _ = check.Suite(new(ParserSuite))
|
|
|
|
func (suite *ParserSuite) TestParserOverwriteIninitializedPoiner(c *check.C) {
|
|
config := localConfiguration{}
|
|
|
|
os.Setenv("REGISTRY_LOG_FORMATTER", "json")
|
|
defer os.Unsetenv("REGISTRY_LOG_FORMATTER")
|
|
|
|
p := NewParser("registry", []VersionedParseInfo{
|
|
{
|
|
Version: "0.1",
|
|
ParseAs: reflect.TypeOf(config),
|
|
ConversionFunc: func(c interface{}) (interface{}, error) {
|
|
return c, nil
|
|
},
|
|
},
|
|
})
|
|
|
|
err := p.Parse([]byte(`{version: "0.1", log: {formatter: "text"}}`), &config)
|
|
c.Assert(err, check.IsNil)
|
|
c.Assert(config, check.DeepEquals, expectedConfig)
|
|
}
|
|
|
|
func (suite *ParserSuite) TestParseOverwriteUnininitializedPoiner(c *check.C) {
|
|
config := localConfiguration{}
|
|
|
|
os.Setenv("REGISTRY_LOG_FORMATTER", "json")
|
|
defer os.Unsetenv("REGISTRY_LOG_FORMATTER")
|
|
|
|
p := NewParser("registry", []VersionedParseInfo{
|
|
{
|
|
Version: "0.1",
|
|
ParseAs: reflect.TypeOf(config),
|
|
ConversionFunc: func(c interface{}) (interface{}, error) {
|
|
return c, nil
|
|
},
|
|
},
|
|
})
|
|
|
|
err := p.Parse([]byte(`{version: "0.1"}`), &config)
|
|
c.Assert(err, check.IsNil)
|
|
c.Assert(config, check.DeepEquals, expectedConfig)
|
|
}
|