-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig_provider_processing_test.go
More file actions
127 lines (110 loc) · 3.01 KB
/
config_provider_processing_test.go
File metadata and controls
127 lines (110 loc) · 3.01 KB
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
package modular
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
func TestProcessMainConfig(t *testing.T) {
t.Parallel()
tests := []struct {
name string
hasProvider bool
enableVerbose bool
expectConfig bool
}{
{
name: "with provider and verbose enabled",
hasProvider: true,
enableVerbose: true,
expectConfig: true,
},
{
name: "with provider and verbose disabled",
hasProvider: true,
enableVerbose: false,
expectConfig: true,
},
{
name: "without provider",
hasProvider: false,
enableVerbose: true,
expectConfig: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mockLogger := new(MockLogger)
// Allow any debug calls - we don't care about specific messages
mockLogger.On("Debug", mock.Anything, mock.Anything).Return().Maybe()
app := &StdApplication{
logger: mockLogger,
cfgSections: make(map[string]ConfigProvider),
}
if tt.hasProvider {
app.cfgProvider = NewStdConfigProvider(&testCfg{Str: "test", Num: 42})
}
// Set up verbose config state
app.verboseConfig = tt.enableVerbose
cfgBuilder := NewConfig()
tempConfigs := make(map[string]configInfo)
result := processMainConfig(app, cfgBuilder, tempConfigs)
assert.Equal(t, tt.expectConfig, result)
if tt.expectConfig {
assert.Contains(t, tempConfigs, "_main")
} else {
assert.NotContains(t, tempConfigs, "_main")
}
})
}
}
func TestProcessSectionConfigs(t *testing.T) {
t.Parallel()
tests := []struct {
name string
sections map[string]ConfigProvider
enableVerbose bool
expectConfigs int
}{
{
name: "with sections and verbose enabled",
sections: map[string]ConfigProvider{
"section1": NewStdConfigProvider(&testSectionCfg{Enabled: true, Name: "test"}),
"section2": NewStdConfigProvider(&testSectionCfg{Enabled: false, Name: "test2"}),
},
enableVerbose: true,
expectConfigs: 2,
},
{
name: "with sections and verbose disabled",
sections: map[string]ConfigProvider{
"section1": NewStdConfigProvider(&testSectionCfg{Enabled: true, Name: "test"}),
},
enableVerbose: false,
expectConfigs: 1,
},
{
name: "without sections",
sections: map[string]ConfigProvider{},
enableVerbose: true,
expectConfigs: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mockLogger := new(MockLogger)
// Allow any debug calls - we don't care about specific messages
mockLogger.On("Debug", mock.Anything, mock.Anything).Return().Maybe()
app := &StdApplication{
logger: mockLogger,
cfgSections: tt.sections,
}
// Set up verbose config state
app.verboseConfig = tt.enableVerbose
cfgBuilder := NewConfig()
tempConfigs := make(map[string]configInfo)
result := processSectionConfigs(app, cfgBuilder, tempConfigs)
assert.Equal(t, tt.expectConfigs > 0, result)
assert.Len(t, tempConfigs, tt.expectConfigs)
})
}
}