github.com/zooyer/miskit@v1.0.71/conf/conf_test.go (about) 1 package conf 2 3 import ( 4 "os" 5 "testing" 6 "time" 7 ) 8 9 func TestNew(t *testing.T) { 10 const ( 11 filename = "./test/test.yaml" 12 ) 13 var ( 14 err error 15 name string 16 age int 17 ) 18 19 if err = os.WriteFile(filename, []byte("name: \"tom\"\nage: 18"), 0644); err != nil { 20 t.Fatal(err) 21 } 22 23 conf := New(time.Millisecond*500) 24 if err = conf.Init(filename); err != nil { 25 t.Fatal(err) 26 } 27 if err = conf.Bind("name", &name); err != nil { 28 t.Fatal(err) 29 } 30 if err = conf.Bind("age", &age); err != nil { 31 t.Fatal(err) 32 } 33 t.Log(name, age) 34 35 if err = os.WriteFile(filename, []byte("name: \"jack\"\nage: 15"), 0644); err != nil { 36 t.Fatal(err) 37 } 38 time.Sleep(time.Second) 39 t.Log(name, age) 40 return 41 }