talos

Форк
0
/
config_test.go 
93 строки · 2.0 Кб
1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4

5
package config_test
6

7
import (
8
	"testing"
9

10
	"github.com/stretchr/testify/assert"
11

12
	clientconfig "github.com/siderolabs/talos/pkg/machinery/client/config"
13
)
14

15
func TestConfigMerge(t *testing.T) {
16
	context1 := &clientconfig.Context{}
17
	context2 := &clientconfig.Context{}
18

19
	for _, tt := range []struct {
20
		name          string
21
		config        *clientconfig.Config
22
		configToMerge *clientconfig.Config
23

24
		expectedContext  string
25
		expectedContexts map[string]*clientconfig.Context
26
	}{
27
		{
28
			name:   "IntoEmpty",
29
			config: &clientconfig.Config{},
30
			configToMerge: &clientconfig.Config{
31
				Context: "foo",
32
				Contexts: map[string]*clientconfig.Context{
33
					"foo": context1,
34
				},
35
			},
36

37
			expectedContext: "foo",
38
			expectedContexts: map[string]*clientconfig.Context{
39
				"foo": context1,
40
			},
41
		},
42
		{
43
			name: "NoConflict",
44
			config: &clientconfig.Config{
45
				Context: "bar",
46
				Contexts: map[string]*clientconfig.Context{
47
					"bar": context2,
48
				},
49
			},
50
			configToMerge: &clientconfig.Config{
51
				Context: "",
52
				Contexts: map[string]*clientconfig.Context{
53
					"foo": context1,
54
				},
55
			},
56

57
			expectedContext: "bar",
58
			expectedContexts: map[string]*clientconfig.Context{
59
				"foo": context1,
60
				"bar": context2,
61
			},
62
		},
63
		{
64
			name: "WithRename",
65
			config: &clientconfig.Config{
66
				Context: "bar",
67
				Contexts: map[string]*clientconfig.Context{
68
					"bar": context2,
69
				},
70
			},
71
			configToMerge: &clientconfig.Config{
72
				Context: "bar",
73
				Contexts: map[string]*clientconfig.Context{
74
					"bar": context1,
75
				},
76
			},
77

78
			expectedContext: "bar-1",
79
			expectedContexts: map[string]*clientconfig.Context{
80
				"bar-1": context1,
81
				"bar":   context2,
82
			},
83
		},
84
	} {
85
		t.Run(tt.name, func(t *testing.T) {
86
			c := tt.config
87
			c.Merge(tt.configToMerge)
88

89
			assert.Equal(t, tt.expectedContext, c.Context)
90
			assert.Equal(t, tt.expectedContexts, c.Contexts)
91
		})
92
	}
93
}
94

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.