forked from elastic/elastic-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
76 lines (63 loc) · 1.89 KB
/
config_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
67
68
69
70
71
72
73
74
75
76
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License 2.0;
// you may not use this file except in compliance with the Elastic License 2.0.
package application
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/elastic/elastic-agent/internal/pkg/agent/configuration"
"github.com/elastic/elastic-agent/internal/pkg/config"
)
func TestConfig(t *testing.T) {
testMgmtMode(t)
testLocalConfig(t)
}
func testMgmtMode(t *testing.T) {
t.Run("succeed when local mode is selected", func(t *testing.T) {
c := mustWithConfigMode(true)
m := localConfig{}
err := c.UnpackTo(&m)
require.NoError(t, err)
assert.Equal(t, false, m.Fleet.Enabled)
assert.Equal(t, true, configuration.IsStandalone(m.Fleet))
})
t.Run("succeed when fleet mode is selected", func(t *testing.T) {
c := mustWithConfigMode(false)
m := localConfig{}
err := c.UnpackTo(&m)
require.NoError(t, err)
assert.Equal(t, true, m.Fleet.Enabled)
assert.Equal(t, false, configuration.IsStandalone(m.Fleet))
})
}
func testLocalConfig(t *testing.T) {
t.Run("only accept positive period", func(t *testing.T) {
c := config.MustNewConfigFrom(map[string]interface{}{
"enabled": true,
"period": 0,
})
m := configuration.ReloadConfig{}
err := c.UnpackTo(&m)
assert.Error(t, err)
c = config.MustNewConfigFrom(map[string]interface{}{
"enabled": true,
"period": 1,
})
err = c.UnpackTo(&m)
assert.NoError(t, err)
assert.Equal(t, 1*time.Second, m.Period)
})
}
func mustWithConfigMode(standalone bool) *config.Config {
return config.MustNewConfigFrom(
map[string]interface{}{
"fleet": map[string]interface{}{
"enabled": !standalone,
"kibana": map[string]interface{}{"host": "demo"},
"access_api_key": "123",
},
},
)
}