Skip to content

Commit

Permalink
added TestCfgSimpleLoad()
Browse files Browse the repository at this point in the history
  • Loading branch information
steveyen committed Oct 20, 2014
1 parent d90fed5 commit 5f3ac40
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion cfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ func TestCfgSimple(t *testing.T) {
emptyDir, _ := ioutil.TempDir("./tmp", "test")
defer os.RemoveAll(emptyDir)

testCfg(t, NewCfgSimple(emptyDir+string(os.PathSeparator)+"test.cfg"))
cfg := NewCfgSimple(emptyDir + string(os.PathSeparator) + "test.cfg")
testCfg(t, cfg)
}

func testCfg(t *testing.T, c Cfg) {
Expand Down Expand Up @@ -127,3 +128,28 @@ func testCfg(t *testing.T, c Cfg) {
" %v, %v, %v", err, v, cas)
}
}

func TestCfgSimpleLoad(t *testing.T) {
emptyDir, _ := ioutil.TempDir("./tmp", "test")
defer os.RemoveAll(emptyDir)

path := emptyDir + string(os.PathSeparator) + "test.cfg"

c := NewCfgSimple(path)
cas1, err := c.Set("a", []byte("A"), 0)
if err != nil || cas1 != 1 {
t.Errorf("expected Set() on initial cfg simple")
}

c2 := NewCfgSimple(path)
if err := c2.(*CfgSimple).Load(); err != nil {
t.Errorf("expected Load() to work")
}
v, cas, err := c2.Get("a", 0)
if err != nil || v == nil || cas != cas1 {
t.Errorf("expected Get() to succeed")
}
if string(v) != "A" {
t.Errorf("exepcted to read what we wrote")
}
}

0 comments on commit 5f3ac40

Please sign in to comment.