ledisdb/config/config_test.go

43 lines
746 B
Go
Raw Permalink Normal View History

package config
import (
2014-10-08 12:02:00 +04:00
"os"
"reflect"
"testing"
)
func TestConfig(t *testing.T) {
2014-10-08 12:02:00 +04:00
cfg, err := NewConfigWithFile("./config.toml")
if err != nil {
t.Fatal(err)
}
2014-10-08 12:20:09 +04:00
bakFile := "./config.toml.bak"
defer os.Remove(bakFile)
if err := cfg.DumpFile(bakFile); err != nil {
2014-10-08 12:02:00 +04:00
t.Fatal(err)
}
2014-10-08 12:20:09 +04:00
if c, err := NewConfigWithFile(bakFile); err != nil {
2014-10-08 12:02:00 +04:00
t.Fatal(err)
2014-10-08 12:20:09 +04:00
} else {
c.FileName = cfg.FileName
if !reflect.DeepEqual(cfg, c) {
t.Fatal("must equal")
}
c.FileName = bakFile
c.SlaveOf = "127.0.0.1:6381"
if err := c.Rewrite(); err != nil {
t.Fatal(err)
}
if c1, err := NewConfigWithFile(bakFile); err != nil {
t.Fatal(err)
} else if !reflect.DeepEqual(c, c1) {
t.Fatalf("must equal %v != %v", c, c1)
}
2014-10-08 12:02:00 +04:00
}
}