z_test.go 902 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package ini
  2. import (
  3. "os"
  4. "testing"
  5. "git.ali33.ru/fcg-xvii/go-tools/text/config"
  6. )
  7. func TestINI(t *testing.T) {
  8. // read config
  9. conf, err := config.FromFile("ini", "test.ini")
  10. if err != nil {
  11. t.Fatal(err)
  12. }
  13. // get value from config main section
  14. mainVal, check := conf.Value("one")
  15. t.Log(mainVal, check)
  16. // int
  17. var i int = 0
  18. t.Log(mainVal.Setup(&i), i)
  19. i = 0
  20. t.Log(conf.ValueSetup("one", &i), i)
  21. t.Log("value default", conf.ValueDefault("db_connection", "").(string))
  22. // get section
  23. main, check := conf.Section("main")
  24. t.Log(main, check)
  25. cool, check := conf.Section("cool")
  26. t.Log(cool, check)
  27. var str string = ""
  28. t.Log(cool.ValueSetup("key1", &str), str)
  29. cools, check := conf.Sections("cool")
  30. t.Log(cools, check)
  31. var f *os.File
  32. f, err = os.OpenFile("tmp.ini", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)
  33. if err != nil {
  34. t.Fatal(err)
  35. }
  36. conf.Save(f)
  37. f.Close()
  38. }