1package models_test
2
3import (
4	"reflect"
5	"testing"
6
7	"github.com/influxdata/influxdb/models"
8)
9
10func TestTags_Merge(t *testing.T) {
11	examples := []struct {
12		Base   map[string]string
13		Arg    map[string]string
14		Result map[string]string
15	}{
16		{
17			Base:   nil,
18			Arg:    nil,
19			Result: map[string]string{},
20		},
21		{
22			Base:   nil,
23			Arg:    map[string]string{"foo": "foo"},
24			Result: map[string]string{"foo": "foo"},
25		},
26		{
27			Base:   map[string]string{"foo": "foo"},
28			Arg:    nil,
29			Result: map[string]string{"foo": "foo"},
30		},
31		{
32			Base:   map[string]string{"foo": "foo"},
33			Arg:    map[string]string{"bar": "bar"},
34			Result: map[string]string{"foo": "foo", "bar": "bar"},
35		},
36		{
37			Base:   map[string]string{"foo": "foo", "bar": "bar"},
38			Arg:    map[string]string{"zoo": "zoo"},
39			Result: map[string]string{"foo": "foo", "bar": "bar", "zoo": "zoo"},
40		},
41		{
42			Base:   map[string]string{"foo": "foo", "bar": "bar"},
43			Arg:    map[string]string{"bar": "newbar"},
44			Result: map[string]string{"foo": "foo", "bar": "newbar"},
45		},
46	}
47
48	for i, example := range examples {
49		i++
50		result := models.StatisticTags(example.Base).Merge(example.Arg)
51		if got, exp := result, example.Result; !reflect.DeepEqual(got, exp) {
52			t.Errorf("[Example %d] got %#v, expected %#v", i, got, exp)
53		}
54	}
55}
56