scaffold_test.go 808 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. }