2023-03-29 12:58:09 +00:00
|
|
|
package root
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2023-04-06 10:54:58 +00:00
|
|
|
"github.com/databricks/bricks/libs/cmdio"
|
2023-03-29 12:58:09 +00:00
|
|
|
"github.com/databricks/bricks/libs/flags"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestInitializeErrorOnIncompatibleConfig(t *testing.T) {
|
|
|
|
logLevel.Set("info")
|
|
|
|
logFile.Set("stderr")
|
|
|
|
progressFormat.Set("inplace")
|
|
|
|
_, err := initializeProgressLogger(context.Background())
|
|
|
|
assert.ErrorContains(t, err, "inplace progress logging cannot be used when log-file is stderr")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNoErrorOnDisabledLogLevel(t *testing.T) {
|
|
|
|
logLevel.Set("disabled")
|
|
|
|
logFile.Set("stderr")
|
|
|
|
progressFormat.Set("inplace")
|
|
|
|
_, err := initializeProgressLogger(context.Background())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNoErrorOnNonStderrLogFile(t *testing.T) {
|
|
|
|
logLevel.Set("info")
|
|
|
|
logFile.Set("stdout")
|
|
|
|
progressFormat.Set("inplace")
|
|
|
|
_, err := initializeProgressLogger(context.Background())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultLoggerModeResolution(t *testing.T) {
|
|
|
|
progressFormat = flags.NewProgressLogFormat()
|
|
|
|
require.Equal(t, progressFormat, flags.ModeDefault)
|
|
|
|
ctx, err := initializeProgressLogger(context.Background())
|
|
|
|
require.NoError(t, err)
|
2023-04-06 10:54:58 +00:00
|
|
|
logger, ok := cmdio.FromContext(ctx)
|
2023-03-29 12:58:09 +00:00
|
|
|
assert.True(t, ok)
|
|
|
|
assert.Equal(t, logger.Mode, flags.ModeAppend)
|
|
|
|
}
|