You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
808 B

5 years ago
  1. package command
  2. import (
  3. "bytes"
  4. "fmt"
  5. "testing"
  6. "github.com/spf13/viper"
  7. )
  8. func TestReadingTomlConfiguration(t *testing.T) {
  9. viper.SetConfigType("toml")
  10. // any approach to require this configuration into your program.
  11. var tomlExample = []byte(`
  12. [database]
  13. server = "192.168.1.1"
  14. ports = [ 8001, 8001, 8002 ]
  15. connection_max = 5000
  16. enabled = true
  17. [servers]
  18. # You can indent as you please. Tabs or spaces. TOML don't care.
  19. [servers.alpha]
  20. ip = "10.0.0.1"
  21. dc = "eqdc10"
  22. [servers.beta]
  23. ip = "10.0.0.2"
  24. dc = "eqdc10"
  25. `)
  26. viper.ReadConfig(bytes.NewBuffer(tomlExample))
  27. fmt.Printf("database is %v\n", viper.Get("database"))
  28. fmt.Printf("servers is %v\n", viper.GetStringMap("servers"))
  29. alpha := viper.Sub("servers.alpha")
  30. fmt.Printf("alpha ip is %v\n", alpha.GetString("ip"))
  31. }