kuma

Форк
0
/
config_test.go 
105 строк · 3.0 Кб
1
package bootstrap_test
2

3
import (
4
	"os"
5
	"path/filepath"
6
	"strings"
7
	"time"
8

9
	. "github.com/onsi/ginkgo/v2"
10
	. "github.com/onsi/gomega"
11

12
	"github.com/kumahq/kuma/pkg/config"
13
	. "github.com/kumahq/kuma/pkg/config/xds/bootstrap"
14
)
15

16
var _ = Describe("BootstrappServerConfig", func() {
17
	It("should be loadable from configuration file", func() {
18
		// given
19
		cfg := BootstrapServerConfig{}
20
		//nolint:gosec
21
		fileError := os.WriteFile("/tmp/corefile", []byte("abc"), 0o600)
22
		Expect(fileError).ToNot(HaveOccurred())
23

24
		// when
25
		err := config.Load(filepath.Join("testdata", "valid-config.input.yaml"), &cfg)
26

27
		// then
28
		Expect(err).ToNot(HaveOccurred())
29

30
		// and
31
		Expect(cfg.Params.AdminAddress).To(Equal("192.168.0.1"))
32
		Expect(cfg.Params.AdminPort).To(Equal(uint32(4321)))
33
		Expect(cfg.Params.AdminAccessLogPath).To(Equal("/var/log"))
34
		Expect(cfg.Params.XdsHost).To(Equal("kuma-control-plane.internal"))
35
		Expect(cfg.Params.XdsPort).To(Equal(uint32(10101)))
36
		Expect(cfg.Params.XdsConnectTimeout.Duration).To(Equal(2 * time.Second))
37
		Expect(cfg.Params.CorefileTemplatePath).To(Equal("/tmp/corefile"))
38
	})
39

40
	Context("with modified environment variables", func() {
41
		var backupEnvVars []string
42

43
		BeforeEach(func() {
44
			backupEnvVars = os.Environ()
45
		})
46

47
		AfterEach(func() {
48
			os.Clearenv()
49
			for _, envVar := range backupEnvVars {
50
				parts := strings.SplitN(envVar, "=", 2)
51
				os.Setenv(parts[0], parts[1])
52
			}
53
		})
54

55
		It("should be loadable from environment variables", func() {
56
			// setup
57
			env := map[string]string{
58
				"KUMA_BOOTSTRAP_SERVER_API_VERSION":                  "v3",
59
				"KUMA_BOOTSTRAP_SERVER_PARAMS_ADMIN_ADDRESS":         "192.168.0.1",
60
				"KUMA_BOOTSTRAP_SERVER_PARAMS_ADMIN_PORT":            "4321",
61
				"KUMA_BOOTSTRAP_SERVER_PARAMS_ADMIN_ACCESS_LOG_PATH": "/var/log",
62
				"KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_HOST":              "kuma-control-plane.internal",
63
				"KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_PORT":              "10101",
64
				"KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_CONNECT_TIMEOUT":   "2s",
65
			}
66
			for key, value := range env {
67
				os.Setenv(key, value)
68
			}
69

70
			// given
71
			cfg := BootstrapServerConfig{}
72

73
			// when
74
			err := config.Load("", &cfg)
75

76
			// then
77
			Expect(err).ToNot(HaveOccurred())
78

79
			// and
80
			Expect(cfg.Params.AdminAddress).To(Equal("192.168.0.1"))
81
			Expect(cfg.Params.AdminPort).To(Equal(uint32(4321)))
82
			Expect(cfg.Params.AdminAccessLogPath).To(Equal("/var/log"))
83
			Expect(cfg.Params.XdsHost).To(Equal("kuma-control-plane.internal"))
84
			Expect(cfg.Params.XdsPort).To(Equal(uint32(10101)))
85
			Expect(cfg.Params.XdsConnectTimeout.Duration).To(Equal(2 * time.Second))
86
		})
87
	})
88

89
	It("should have consistent defaults", func() {
90
		// given
91
		cfg := DefaultBootstrapServerConfig()
92

93
		// when
94
		actual, err := config.ToYAML(cfg)
95
		// then
96
		Expect(err).ToNot(HaveOccurred())
97

98
		// when
99
		expected, err := os.ReadFile(filepath.Join("testdata", "default-config.golden.yaml"))
100
		// then
101
		Expect(err).ToNot(HaveOccurred())
102
		// and
103
		Expect(actual).To(MatchYAML(expected))
104
	})
105
})
106

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

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

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

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