mock_test.go 761 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package paladin_test
  2. import (
  3. "testing"
  4. "go-common/library/conf/paladin"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestMock(t *testing.T) {
  8. cs := map[string]string{
  9. "key_toml": `
  10. key_bool = true
  11. key_int = 100
  12. key_float = 100.1
  13. key_string = "text"
  14. `,
  15. }
  16. cli := paladin.NewMock(cs)
  17. // test vlaue
  18. var m paladin.TOML
  19. err := cli.Get("key_toml").Unmarshal(&m)
  20. assert.Nil(t, err)
  21. b, err := m.Get("key_bool").Bool()
  22. assert.Nil(t, err)
  23. assert.Equal(t, b, true)
  24. i, err := m.Get("key_int").Int64()
  25. assert.Nil(t, err)
  26. assert.Equal(t, i, int64(100))
  27. f, err := m.Get("key_float").Float64()
  28. assert.Nil(t, err)
  29. assert.Equal(t, f, float64(100.1))
  30. s, err := m.Get("key_string").String()
  31. assert.Nil(t, err)
  32. assert.Equal(t, s, "text")
  33. }