OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / spf13 / viper / util_test.go
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
6 // Viper is a application configuration system.
7 // It believes that applications can be configured a variety of ways
8 // via flags, ENVIRONMENT variables, configuration files retrieved
9 // from the file system, or a remote key/value store.
10
11 package viper
12
13 import (
14         "reflect"
15         "testing"
16 )
17
18 func TestCopyAndInsensitiviseMap(t *testing.T) {
19         var (
20                 given = map[string]interface{}{
21                         "Foo": 32,
22                         "Bar": map[interface{}]interface {
23                         }{
24                                 "ABc": "A",
25                                 "cDE": "B"},
26                 }
27                 expected = map[string]interface{}{
28                         "foo": 32,
29                         "bar": map[string]interface {
30                         }{
31                                 "abc": "A",
32                                 "cde": "B"},
33                 }
34         )
35
36         got := copyAndInsensitiviseMap(given)
37
38         if !reflect.DeepEqual(got, expected) {
39                 t.Fatalf("Got %q\nexpected\n%q", got, expected)
40         }
41
42         if _, ok := given["foo"]; ok {
43                 t.Fatal("Input map changed")
44         }
45
46         if _, ok := given["bar"]; ok {
47                 t.Fatal("Input map changed")
48         }
49
50         m := given["Bar"].(map[interface{}]interface{})
51         if _, ok := m["ABc"]; !ok {
52                 t.Fatal("Input map changed")
53         }
54 }