File: util_test.go

package info (click to toggle)
golang-github-spf13-viper 0.0~git20161213.0.5ed0fc3-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch, stretch-backports
  • size: 272 kB
  • sloc: makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,148 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright © 2016 Steve Francia <spf@spf13.com>.
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.

// Viper is a application configuration system.
// It believes that applications can be configured a variety of ways
// via flags, ENVIRONMENT variables, configuration files retrieved
// from the file system, or a remote key/value store.

package viper

import (
	"reflect"
	"testing"
)

func TestCopyAndInsensitiviseMap(t *testing.T) {

	var (
		given = map[string]interface{}{
			"Foo": 32,
			"Bar": map[interface{}]interface {
			}{
				"ABc": "A",
				"cDE": "B"},
		}
		expected = map[string]interface{}{
			"foo": 32,
			"bar": map[string]interface {
			}{
				"abc": "A",
				"cde": "B"},
		}
	)

	got := copyAndInsensitiviseMap(given)

	if !reflect.DeepEqual(got, expected) {
		t.Fatalf("Got %q\nexpected\n%q", got, expected)
	}

	if _, ok := given["foo"]; ok {
		t.Fatal("Input map changed")
	}

	if _, ok := given["bar"]; ok {
		t.Fatal("Input map changed")
	}

	m := given["Bar"].(map[interface{}]interface{})
	if _, ok := m["ABc"]; !ok {
		t.Fatal("Input map changed")
	}
}