lint_test.go 775 B

1234567891011121314151617181920212223242526272829303132333435
  1. package lint_test
  2. import (
  3. "bytes"
  4. "testing"
  5. "go-common/app/admin/main/config/pkg/lint"
  6. _ "go-common/app/admin/main/config/pkg/lint/json"
  7. _ "go-common/app/admin/main/config/pkg/lint/toml"
  8. )
  9. func TestLint(t *testing.T) {
  10. jsonRead := bytes.NewBufferString(`{"hello": "world", "a1":"ab"}`)
  11. err := lint.Lint("json", jsonRead)
  12. if err != nil {
  13. t.Errorf("%v", err)
  14. }
  15. tomlRead := bytes.NewBufferString(`[owner]
  16. name = "Tom Preston-Werner"
  17. dob = 1979-05-27T07:32:00-08:00 # First class dates
  18. [database]
  19. server = "192.168.1.1"
  20. ports = [ 8001, 8001, 8002 ]
  21. connection_max = 5000
  22. enabled = true`)
  23. err = lint.Lint("toml", tomlRead)
  24. if err != nil {
  25. t.Errorf("%v", err)
  26. }
  27. err = lint.Lint("test", tomlRead)
  28. if err != lint.ErrLintNotExists {
  29. t.Errorf("%v", err)
  30. }
  31. }