@@ -243,12 +243,54 @@ func TestResolveAllowedDirectories(t *testing.T) {
243243
244244func TestResolveLog (t * testing.T ) {
245245 viperInstance = viper .NewWithOptions (viper .KeyDelimiter (KeyDelimiter ))
246- viperInstance .Set (LogLevelKey , "error" )
247- viperInstance .Set (LogPathKey , "/var/log/test/test.log" )
248246
249- result := resolveLog ()
250- assert .Equal (t , "error" , result .Level )
251- assert .Equal (t , "/var/log/test/test.log" , result .Path )
247+ tests := []struct {
248+ name string
249+ logLevel string
250+ logPath string
251+ expectedLogPath string
252+ expectedLogLevel string
253+ }{
254+ {
255+ name : "Test 1: Log level set to info" ,
256+ logLevel : "info" ,
257+ logPath : "/var/log/test/test.log" ,
258+ expectedLogPath : "/var/log/test/test.log" ,
259+ expectedLogLevel : "info" ,
260+ },
261+ {
262+ name : "Test 2: Invalid log level set" ,
263+ logLevel : "trace" ,
264+ logPath : "/var/log/test/test.log" ,
265+ expectedLogPath : "/var/log/test/test.log" ,
266+ expectedLogLevel : "info" ,
267+ },
268+ {
269+ name : "Test 3: Log level set to debug" ,
270+ logLevel : "debug" ,
271+ logPath : "/var/log/test/test.log" ,
272+ expectedLogPath : "/var/log/test/test.log" ,
273+ expectedLogLevel : "debug" ,
274+ },
275+ {
276+ name : "Test 4: Log level set with capitalization" ,
277+ logLevel : "DEBUG" ,
278+ logPath : "./logs/nginx.log" ,
279+ expectedLogPath : "./logs/nginx.log" ,
280+ expectedLogLevel : "DEBUG" ,
281+ },
282+ }
283+
284+ for _ , test := range tests {
285+ t .Run (test .name , func (t * testing.T ) {
286+ viperInstance .Set (LogLevelKey , test .logLevel )
287+ viperInstance .Set (LogPathKey , test .logPath )
288+
289+ result := resolveLog ()
290+ assert .Equal (t , test .expectedLogLevel , result .Level )
291+ assert .Equal (t , test .expectedLogPath , result .Path )
292+ })
293+ }
252294}
253295
254296func TestResolveClient (t * testing.T ) {
@@ -298,6 +340,59 @@ func TestResolveCollector(t *testing.T) {
298340 })
299341}
300342
343+ func TestResolveCollectorLog (t * testing.T ) {
344+ tests := []struct {
345+ name string
346+ logLevel string
347+ logPath string
348+ agentLogLevel string
349+ expectedLogPath string
350+ expectedLogLevel string
351+ }{
352+ {
353+ name : "Test 1: OTel Log Level Set In Config" ,
354+ logLevel : "" ,
355+ logPath : "/tmp/collector.log" ,
356+ agentLogLevel : "debug" ,
357+ expectedLogPath : "/tmp/collector.log" ,
358+ expectedLogLevel : "DEBUG" ,
359+ },
360+ {
361+ name : "Test 2: Agent Log Level is Warn" ,
362+ logLevel : "" ,
363+ logPath : "/tmp/collector.log" ,
364+ agentLogLevel : "warn" ,
365+ expectedLogPath : "/tmp/collector.log" ,
366+ expectedLogLevel : "WARN" ,
367+ },
368+ {
369+ name : "Test 3: OTel Log Level Set In Config" ,
370+ logLevel : "INFO" ,
371+ logPath : "/tmp/collector.log" ,
372+ agentLogLevel : "debug" ,
373+ expectedLogPath : "/tmp/collector.log" ,
374+ expectedLogLevel : "INFO" ,
375+ },
376+ }
377+
378+ for _ , test := range tests {
379+ t .Run (test .name , func (t * testing.T ) {
380+ viperInstance = viper .NewWithOptions (viper .KeyDelimiter (KeyDelimiter ))
381+ viperInstance .Set (CollectorLogPathKey , test .logPath )
382+ viperInstance .Set (LogLevelKey , test .agentLogLevel )
383+
384+ if test .logLevel != "" {
385+ viperInstance .Set (CollectorLogLevelKey , test .logLevel )
386+ }
387+
388+ log := resolveCollectorLog ()
389+
390+ assert .Equal (t , test .expectedLogLevel , log .Level )
391+ assert .Equal (t , test .expectedLogPath , log .Path )
392+ })
393+ }
394+ }
395+
301396func TestCommand (t * testing.T ) {
302397 viperInstance = viper .NewWithOptions (viper .KeyDelimiter (KeyDelimiter ))
303398 expected := agentConfig ().Command
0 commit comments