config_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package config
  2. import (
  3. "log"
  4. "regexp"
  5. "testing"
  6. )
  7. func TestReg(t *testing.T) {
  8. content := `
  9. [common]
  10. server=127.0.0.1:8284
  11. tp=tcp
  12. vkey=123
  13. [web2]
  14. host=www.baidu.com
  15. host_change=www.sina.com
  16. target=127.0.0.1:8080,127.0.0.1:8082
  17. header_cookkile=122123
  18. header_user-Agent=122123
  19. [web2]
  20. host=www.baidu.com
  21. host_change=www.sina.com
  22. target=127.0.0.1:8080,127.0.0.1:8082
  23. header_cookkile="122123"
  24. header_user-Agent=122123
  25. [tunnel1]
  26. type=udp
  27. target=127.0.0.1:8080
  28. port=9001
  29. compress=snappy
  30. crypt=true
  31. u=1
  32. p=2
  33. [tunnel2]
  34. type=tcp
  35. target=127.0.0.1:8080
  36. port=9001
  37. compress=snappy
  38. crypt=true
  39. u=1
  40. p=2
  41. `
  42. re, err := regexp.Compile(`\[.+?\]`)
  43. if err != nil {
  44. t.Fail()
  45. }
  46. log.Println(re.FindAllString(content, -1))
  47. }
  48. func TestDealCommon(t *testing.T) {
  49. s := `server=127.0.0.1:8284
  50. tp=tcp
  51. vkey=123`
  52. f := new(CommonConfig)
  53. f.Server = "127.0.0.1:8284"
  54. f.Tp = "tcp"
  55. f.VKey = "123"
  56. if c := dealCommon(s); *c != *f {
  57. t.Fail()
  58. }
  59. }
  60. func TestGetTitleContent(t *testing.T) {
  61. s := "[common]"
  62. if getTitleContent(s) != "common" {
  63. t.Fail()
  64. }
  65. }