Keep Version struct as input
This commit is contained in:
@@ -106,17 +106,12 @@ func (v Version) String() string {
|
||||
type Config map[string]interface{}
|
||||
|
||||
// NewConfig - instantiate a new config
|
||||
func NewConfig(major, minor, patch int) Configure {
|
||||
func NewConfig(version Version) Configure {
|
||||
// error condition
|
||||
if major < 0 || minor < 0 || patch < 0 {
|
||||
if version.Major == 0 {
|
||||
return nil
|
||||
}
|
||||
config := make(Config)
|
||||
version := Version{
|
||||
Major: major,
|
||||
Minor: minor,
|
||||
Patch: patch,
|
||||
}
|
||||
config["Version"] = version.String()
|
||||
return &config
|
||||
}
|
||||
|
||||
@@ -31,15 +31,16 @@ type MySuite struct{}
|
||||
|
||||
var _ = Suite(&MySuite{})
|
||||
|
||||
var version = Version{1, 0, 0}
|
||||
|
||||
func (s *MySuite) TestVersion(c *C) {
|
||||
version := Version{1, 0, 0}
|
||||
cfg := NewConfig(1, 0, 0)
|
||||
cfg := NewConfig(version)
|
||||
c.Assert(cfg.GetVersion(), DeepEquals, version)
|
||||
}
|
||||
|
||||
func (s *MySuite) TestGetSet(c *C) {
|
||||
defer os.RemoveAll("test.json")
|
||||
cfg := NewConfig(1, 0, 0)
|
||||
cfg := NewConfig(version)
|
||||
/*
|
||||
GetVersion() Version
|
||||
SetInt(string, int)
|
||||
@@ -66,7 +67,7 @@ func (s *MySuite) TestGetSet(c *C) {
|
||||
c.Assert(pi, Equals, 3.1415)
|
||||
cfg.SaveConfig("test.json")
|
||||
|
||||
newCfg := NewConfig(1, 0, 0)
|
||||
newCfg := NewConfig(version)
|
||||
newCfg.SetInt("NewInt", 99)
|
||||
newCfg.LoadConfig("test.json")
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user