-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathgetters_test.go
66 lines (56 loc) · 2.21 KB
/
getters_test.go
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
package config
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestGetOutput tests the GetOutput function.
func TestGetOutput(t *testing.T) {
logger := Logger{}
assert.Equal(t, []LogOutput{Console}, logger.GetOutput())
}
// TestGetOutputWithMultipleLoggers tests the GetOutput function with multiple loggers.
func TestGetOutputWithMultipleLoggers(t *testing.T) {
logger := Logger{Output: []string{"console", "file"}}
assert.Equal(t, []LogOutput{Console, File}, logger.GetOutput())
}
// TestGetPlugins tests the GetPlugins function.
func TestGetPlugins(t *testing.T) {
plugin := Plugin{Name: "plugin1"}
pluginConfig := PluginConfig{Plugins: []Plugin{plugin}}
assert.Equal(t, []Plugin{plugin}, pluginConfig.GetPlugins("plugin1"))
}
// TestGetDefaultConfigFilePath tests the GetDefaultConfigFilePath function.
func TestGetDefaultConfigFilePath(t *testing.T) {
assert.Equal(t, GlobalConfigFilename, GetDefaultConfigFilePath(GlobalConfigFilename))
}
// TestFilter tests the Filter function.
func TestFilter(t *testing.T) {
// Load config from the default config file.
conf := NewConfig(t.Context(),
Config{GlobalConfigFile: "../gatewayd.yaml", PluginConfigFile: "../gatewayd_plugins.yaml"})
err := conf.InitConfig(t.Context())
require.Nil(t, err)
assert.NotEmpty(t, conf.Global)
// Filter the config.
defaultGroup := conf.Global.Filter(Default)
assert.NotEmpty(t, defaultGroup)
assert.Contains(t, defaultGroup.Clients, Default)
assert.Contains(t, defaultGroup.Servers, Default)
assert.Contains(t, defaultGroup.Pools, Default)
assert.Contains(t, defaultGroup.Proxies, Default)
assert.Contains(t, defaultGroup.Metrics, Default)
assert.Contains(t, defaultGroup.Loggers, Default)
}
// TestFilterWithMissingGroupName tests the Filter function with a missing group name.
func TestFilterWithMissingGroupName(t *testing.T) {
// Load config from the default config file.
conf := NewConfig(t.Context(),
Config{GlobalConfigFile: "../gatewayd.yaml", PluginConfigFile: "../gatewayd_plugins.yaml"})
err := conf.InitConfig(t.Context())
require.Nil(t, err)
assert.NotEmpty(t, conf.Global)
// Filter the config.
defaultGroup := conf.Global.Filter("missing")
assert.Empty(t, defaultGroup)
}