Keep Version struct as input

This commit is contained in:
Anand Babu (AB) Periasamy
2015-04-10 18:33:37 -07:00
parent 05953cda89
commit bdea263f3a
2 changed files with 7 additions and 11 deletions
+2 -7
View File
@@ -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
}
+5 -4
View File
@@ -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")
/*