From b0f20e809e84eb48214359d4fe689bbfba90a6e0 Mon Sep 17 00:00:00 2001 From: pmahindrakar-oss Date: Wed, 30 Nov 2022 12:11:20 +0530 Subject: [PATCH] Added test for bad config for task logs (#298) --- go/tasks/config_load_test.go | 35 ++++++++++++++++++++----- go/tasks/testdata/incorrect-config.yaml | 7 +++++ 2 files changed, 35 insertions(+), 7 deletions(-) create mode 100755 go/tasks/testdata/incorrect-config.yaml diff --git a/go/tasks/config_load_test.go b/go/tasks/config_load_test.go index f86589d893..7ece0eae55 100755 --- a/go/tasks/config_load_test.go +++ b/go/tasks/config_load_test.go @@ -4,18 +4,16 @@ import ( "context" "testing" - "k8s.io/apimachinery/pkg/api/resource" - - sagemakerConfig "github.com/flyteorg/flyteplugins/go/tasks/plugins/k8s/sagemaker/config" - - "github.com/flyteorg/flytestdlib/config" - "github.com/flyteorg/flytestdlib/config/viper" "github.com/stretchr/testify/assert" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" "github.com/flyteorg/flyteplugins/go/tasks/logs" flyteK8sConfig "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/flytek8s/config" + sagemakerConfig "github.com/flyteorg/flyteplugins/go/tasks/plugins/k8s/sagemaker/config" "github.com/flyteorg/flyteplugins/go/tasks/plugins/k8s/spark" + "github.com/flyteorg/flytestdlib/config" + "github.com/flyteorg/flytestdlib/config/viper" ) func TestLoadConfig(t *testing.T) { @@ -26,7 +24,6 @@ func TestLoadConfig(t *testing.T) { err := configAccessor.UpdateConfig(context.TODO()) assert.NoError(t, err) - t.Run("k8s-config-test", func(t *testing.T) { k8sConfig := flyteK8sConfig.GetK8sPluginConfig() @@ -127,3 +124,27 @@ func TestLoadConfig(t *testing.T) { assert.NotNil(t, sagemakerConfig.GetSagemakerConfig()) }) } + +func TestLoadIncorrectConfig(t *testing.T) { + t.Run("logs-config-test-accept-bad-config", func(t *testing.T) { + configAccessor := viper.NewAccessor(config.Options{ + StrictMode: false, + SearchPaths: []string{"testdata/incorrect-config.yaml"}, + }) + + err := configAccessor.UpdateConfig(context.TODO()) + assert.NoError(t, err) + assert.NotNil(t, logs.GetLogConfig()) + assert.True(t, logs.GetLogConfig().IsKubernetesEnabled) + }) + + t.Run("logs-config-test-failfast", func(t *testing.T) { + configAccessor := viper.NewAccessor(config.Options{ + StrictMode: true, + SearchPaths: []string{"testdata/incorrect-config.yaml"}, + }) + + err := configAccessor.UpdateConfig(context.TODO()) + assert.Error(t, err) + }) +} diff --git a/go/tasks/testdata/incorrect-config.yaml b/go/tasks/testdata/incorrect-config.yaml new file mode 100755 index 0000000000..719b6113d7 --- /dev/null +++ b/go/tasks/testdata/incorrect-config.yaml @@ -0,0 +1,7 @@ +# Sample plugins config +plugins: + # Logging configuration + logs: + config: + kubernetes-enabled: true + kubernetes-url: "http://localhost:30082"