2014-08-07 12:49:48 +04:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2014-10-08 12:02:00 +04:00
|
|
|
"os"
|
|
|
|
"reflect"
|
2014-08-07 12:49:48 +04:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestConfig(t *testing.T) {
|
2014-10-08 12:02:00 +04:00
|
|
|
cfg, err := NewConfigWithFile("./config.toml")
|
2014-08-07 12:49:48 +04:00
|
|
|
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
|
|
|
}
|
2014-08-07 12:49:48 +04:00
|
|
|
}
|