z_test.go 960 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. arr := main.ValueDefault("arr", []string{})
  26. t.Log(arr)
  27. cool, check := conf.Section("cool")
  28. t.Log(cool, check)
  29. var str string = ""
  30. t.Log(cool.ValueSetup("key1", &str), str)
  31. cools, check := conf.Sections("cool")
  32. t.Log(cools, check)
  33. var f *os.File
  34. f, err = os.OpenFile("tmp.ini", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)
  35. if err != nil {
  36. t.Fatal(err)
  37. }
  38. conf.Save(f)
  39. f.Close()
  40. }