Skip to content

Commit e6d42b5

Browse files
committed
add unit test and refactor
1 parent 5d76f97 commit e6d42b5

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

internal/config/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ func ResolveConfig() (*Config, error) {
106106
return nil, fmt.Errorf("invalid configuration: %w", err)
107107
}
108108

109-
if !viperInstance.IsSet(CollectorLogLevelKey) && strings.ToLower(log.Level) == "debug" {
110-
collector.Log.Level = "DEBUG"
111-
}
112-
113109
config := &Config{
114110
UUID: viperInstance.GetString(UUIDKey),
115111
Version: viperInstance.GetString(VersionKey),
@@ -1177,6 +1173,10 @@ func resolveCollectorLog() *Log {
11771173
Path: viperInstance.GetString(CollectorLogPathKey),
11781174
}
11791175

1176+
if !viperInstance.IsSet(CollectorLogLevelKey) {
1177+
log.Level = viperInstance.GetString(LogLevelKey)
1178+
}
1179+
11801180
return log
11811181
}
11821182

internal/config/config_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,32 @@ func TestResolveCollector(t *testing.T) {
298298
})
299299
}
300300

301+
func TestResolveCollectorLog(t *testing.T) {
302+
t.Run("Test 1: OTel Log Level Set In Config", func(t *testing.T) {
303+
viperInstance = viper.NewWithOptions(viper.KeyDelimiter(KeyDelimiter))
304+
305+
viperInstance.Set(CollectorLogLevelKey, "info")
306+
viperInstance.Set(CollectorLogPathKey, "/tmp/collector.log")
307+
viperInstance.Set(LogLevelKey, "debug")
308+
309+
log := resolveCollectorLog()
310+
311+
// Check
312+
assert.Equal(t, "info", log.Level)
313+
assert.Equal(t, "/tmp/collector.log", log.Path)
314+
})
315+
316+
t.Run("Test 2: OTel Log Level Not Set In Config", func(t *testing.T) {
317+
viperInstance = viper.NewWithOptions(viper.KeyDelimiter(KeyDelimiter))
318+
viperInstance.Set(LogLevelKey, "debug")
319+
viperInstance.Set(CollectorLogPathKey, "/tmp/collector.log")
320+
321+
log := resolveCollectorLog()
322+
assert.Equal(t, "debug", log.Level)
323+
assert.Equal(t, "/tmp/collector.log", log.Path)
324+
})
325+
}
326+
301327
func TestCommand(t *testing.T) {
302328
viperInstance = viper.NewWithOptions(viper.KeyDelimiter(KeyDelimiter))
303329
expected := agentConfig().Command

0 commit comments

Comments
 (0)