util_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package xstream
  2. import (
  3. "testing"
  4. )
  5. func TestConf(t *testing.T) {
  6. var file = "test/testconf.json"
  7. if v, e := GetConfAsString(file, "conf_string"); (e != nil || (v != "test")) {
  8. t.Errorf("Expect %s, actual %s; error is %s. \n", "test", v, e)
  9. }
  10. if v, e := GetConfAsInt(file, "conf_int"); (e != nil || (v != 10)) {
  11. t.Errorf("Expect %s, actual %d. error is %s. \n ", "10", v, e)
  12. }
  13. if v, e := GetConfAsFloat(file, "conf_float"); (e != nil || (v != 32.3)) {
  14. t.Errorf("Expect %s, actual %f. error is %s. \n ", "32.3", v, e)
  15. }
  16. if v, e := GetConfAsBool(file, "conf_bool"); (e != nil || (v != true)) {
  17. t.Errorf("Expect %s, actual %v. error is %s. \n", "true", v, e)
  18. }
  19. if v, e := GetConfAsString(file, "servers.srv1.addr"); (e != nil || (v != "127.0.0.1")) {
  20. t.Errorf("Expect %s, actual %s. error is %s. \n", "127.0.0.1", v, e)
  21. }
  22. if v, e := GetConfAsString(file, "servers.srv1.clientid"); (e != nil || (v != "")) {
  23. t.Errorf("Expect %s, actual %s. error is %s. \n", "", v, e)
  24. }
  25. if v, e := GetConfAsInt(file, "servers.srv2.port"); (e != nil || (v != 1883)) {
  26. t.Errorf("Expect %s, actual %d. error is %s. \n", "1883", v, e)
  27. }
  28. }