//go:build !windows && unit // +build !windows,unit // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"). You may // not use this file except in compliance with the License. A copy of the // License is located at // // http://aws.amazon.com/apache2.0/ // // or in the "license" file accompanying this file. This file is distributed // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either // express or implied. See the License for the specific language governing // permissions and limitations under the License. package logger import ( "os" "testing" "github.com/stretchr/testify/require" ) func TestSeelogConfig_Default(t *testing.T) { Config = &logConfig{ logfile: "foo.log", driverLevel: DEFAULT_LOGLEVEL, instanceLevel: DEFAULT_LOGLEVEL, RolloverType: DEFAULT_ROLLOVER_TYPE, outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, } c := seelogConfig() require.Equal(t, ` `, c) } func TestSeelogConfig_WithoutLogFile(t *testing.T) { Config = &logConfig{ driverLevel: DEFAULT_LOGLEVEL, instanceLevel: DEFAULT_LOGLEVEL, RolloverType: DEFAULT_ROLLOVER_TYPE, outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, } c := seelogConfig() require.Equal(t, ` `, c) } func TestSeelogConfig_DebugLevel(t *testing.T) { Config = &logConfig{ logfile: "foo.log", driverLevel: "debug", instanceLevel: DEFAULT_LOGLEVEL, RolloverType: DEFAULT_ROLLOVER_TYPE, outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, } c := seelogConfig() require.Equal(t, ` `, c) } func TestSeelogConfig_SizeRollover(t *testing.T) { Config = &logConfig{ logfile: "foo.log", driverLevel: DEFAULT_LOGLEVEL, instanceLevel: DEFAULT_LOGLEVEL, RolloverType: "size", outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, } c := seelogConfig() require.Equal(t, ` `, c) } func TestSeelogConfig_SizeRolloverFileSizeChange(t *testing.T) { Config = &logConfig{ logfile: "foo.log", driverLevel: DEFAULT_LOGLEVEL, instanceLevel: DEFAULT_LOGLEVEL, RolloverType: "size", outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: 15, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, } c := seelogConfig() require.Equal(t, ` `, c) } func TestSeelogConfig_SizeRolloverRollCountChange(t *testing.T) { Config = &logConfig{ logfile: "foo.log", driverLevel: DEFAULT_LOGLEVEL, instanceLevel: DEFAULT_LOGLEVEL, RolloverType: "size", outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: 15, MaxRollCount: 10, } c := seelogConfig() require.Equal(t, ` `, c) } func TestSeelogConfig_JSONOutput(t *testing.T) { Config = &logConfig{ logfile: "foo.log", driverLevel: DEFAULT_LOGLEVEL, instanceLevel: DEFAULT_LOGLEVEL, RolloverType: DEFAULT_ROLLOVER_TYPE, outputFormat: "json", MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: 10, } c := seelogConfig() require.Equal(t, ` `, c) } func TestSeelogConfig_NoOnInstanceLog(t *testing.T) { Config = &logConfig{ logfile: "foo.log", driverLevel: DEFAULT_LOGLEVEL, instanceLevel: DEFAULT_LOGLEVEL_WHEN_DRIVER_SET, RolloverType: DEFAULT_ROLLOVER_TYPE, outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, } c := seelogConfig() require.Equal(t, ` `, c) } func TestSeelogConfig_DifferentLevels(t *testing.T) { Config = &logConfig{ logfile: "foo.log", driverLevel: "warn", instanceLevel: "critical", RolloverType: DEFAULT_ROLLOVER_TYPE, outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, } c := seelogConfig() require.Equal(t, ` `, c) } func TestSeelogConfig_FileLevelDefault(t *testing.T) { os.Setenv(LOG_DRIVER_ENV_VAR, "awslogs") defer os.Unsetenv(LOG_DRIVER_ENV_VAR) Config = &logConfig{ logfile: "foo.log", driverLevel: DEFAULT_LOGLEVEL, instanceLevel: setInstanceLevelDefault(), RolloverType: DEFAULT_ROLLOVER_TYPE, outputFormat: DEFAULT_OUTPUT_FORMAT, MaxFileSizeMB: DEFAULT_MAX_FILE_SIZE, MaxRollCount: DEFAULT_MAX_ROLL_COUNT, } c := seelogConfig() require.Equal(t, ` `, c) }