aboutsummaryrefslogtreecommitdiff
path: root/libpod/config/merge_test.go
blob: eb450b273a0eb8635fa86ce6681185d4f5e73ed4 (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package config

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestMergeStrings(t *testing.T) {
	testData := []struct {
		a   string
		b   string
		res string
	}{
		{"", "", ""},
		{"a", "", "a"},
		{"a", "b", "a"},
		{"", "b", "b"},
	}
	for _, data := range testData {
		res := mergeStrings(data.a, data.b)
		assert.Equal(t, data.res, res)
	}
}

func TestMergeStringSlices(t *testing.T) {
	testData := []struct {
		a   []string
		b   []string
		res []string
	}{
		{
			nil, nil, nil,
		},
		{
			nil,
			[]string{},
			[]string{},
		},
		{
			[]string{},
			nil,
			[]string{},
		},
		{
			[]string{},
			[]string{},
			[]string{},
		},
		{
			[]string{"a"},
			[]string{},
			[]string{"a"},
		},
		{
			[]string{"a"},
			[]string{"b"},
			[]string{"a"},
		},
		{
			[]string{},
			[]string{"b"},
			[]string{"b"},
		},
	}
	for _, data := range testData {
		res := mergeStringSlices(data.a, data.b)
		assert.Equal(t, data.res, res)
	}
}

func TestMergeStringMaps(t *testing.T) {
	testData := []struct {
		a   map[string][]string
		b   map[string][]string
		res map[string][]string
	}{
		{
			nil, nil, nil,
		},
		{
			nil,
			map[string][]string{},
			map[string][]string{}},
		{
			map[string][]string{"a": {"a"}},
			nil,
			map[string][]string{"a": {"a"}},
		},
		{
			nil,
			map[string][]string{"b": {"b"}},
			map[string][]string{"b": {"b"}},
		},
		{
			map[string][]string{"a": {"a"}},
			map[string][]string{"b": {"b"}},
			map[string][]string{"a": {"a"}},
		},
	}
	for _, data := range testData {
		res := mergeStringMaps(data.a, data.b)
		assert.Equal(t, data.res, res)
	}
}

func TestMergeInts64(t *testing.T) {
	testData := []struct {
		a   int64
		b   int64
		res int64
	}{
		{int64(0), int64(0), int64(0)},
		{int64(1), int64(0), int64(1)},
		{int64(0), int64(1), int64(1)},
		{int64(2), int64(1), int64(2)},
		{int64(-1), int64(1), int64(-1)},
		{int64(0), int64(-1), int64(-1)},
	}
	for _, data := range testData {
		res := mergeInt64s(data.a, data.b)
		assert.Equal(t, data.res, res)
	}
}
func TestMergeUint32(t *testing.T) {
	testData := []struct {
		a   uint32
		b   uint32
		res uint32
	}{
		{uint32(0), uint32(0), uint32(0)},
		{uint32(1), uint32(0), uint32(1)},
		{uint32(0), uint32(1), uint32(1)},
		{uint32(2), uint32(1), uint32(2)},
	}
	for _, data := range testData {
		res := mergeUint32s(data.a, data.b)
		assert.Equal(t, data.res, res)
	}
}

func TestMergeBools(t *testing.T) {
	testData := []struct {
		a   bool
		b   bool
		res bool
	}{
		{false, false, false},
		{true, false, true},
		{false, true, true},
		{true, true, true},
	}
	for _, data := range testData {
		res := mergeBools(data.a, data.b)
		assert.Equal(t, data.res, res)
	}
}