util_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright © 2016 Steve Francia <spf@spf13.com>.
  2. //
  3. // Use of this source code is governed by an MIT-style
  4. // license that can be found in the LICENSE file.
  5. // Viper is a application configuration system.
  6. // It believes that applications can be configured a variety of ways
  7. // via flags, ENVIRONMENT variables, configuration files retrieved
  8. // from the file system, or a remote key/value store.
  9. package viper
  10. import (
  11. "reflect"
  12. "testing"
  13. )
  14. func TestCopyAndInsensitiviseMap(t *testing.T) {
  15. var (
  16. given = map[string]interface{}{
  17. "Foo": 32,
  18. "Bar": map[interface{}]interface {
  19. }{
  20. "ABc": "A",
  21. "cDE": "B"},
  22. }
  23. expected = map[string]interface{}{
  24. "foo": 32,
  25. "bar": map[string]interface {
  26. }{
  27. "abc": "A",
  28. "cde": "B"},
  29. }
  30. )
  31. got := copyAndInsensitiviseMap(given)
  32. if !reflect.DeepEqual(got, expected) {
  33. t.Fatalf("Got %q\nexpected\n%q", got, expected)
  34. }
  35. if _, ok := given["foo"]; ok {
  36. t.Fatal("Input map changed")
  37. }
  38. if _, ok := given["bar"]; ok {
  39. t.Fatal("Input map changed")
  40. }
  41. m := given["Bar"].(map[interface{}]interface{})
  42. if _, ok := m["ABc"]; !ok {
  43. t.Fatal("Input map changed")
  44. }
  45. }