Skip to content

Commit

Permalink
Added test for bad config for task logs (flyteorg#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmahindrakar-oss authored Nov 30, 2022
1 parent 85c512e commit b0f20e8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
35 changes: 28 additions & 7 deletions go/tasks/config_load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()
Expand Down Expand Up @@ -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)
})
}
7 changes: 7 additions & 0 deletions go/tasks/testdata/incorrect-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Sample plugins config
plugins:
# Logging configuration
logs:
config:
kubernetes-enabled: true
kubernetes-url: "http://localhost:30082"

0 comments on commit b0f20e8

Please sign in to comment.