Skip to content

Commit

Permalink
Fail tests on NewConfig error (closes #145)
Browse files Browse the repository at this point in the history
  • Loading branch information
adatzer committed Jun 20, 2022
1 parent 28d550d commit 910929d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 24 deletions.
13 changes: 10 additions & 3 deletions config/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ func TestCreateTargetComponentHCL(t *testing.T) {

c, err := NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

use := c.Data.Target.Use
decoderOpts := &DecoderOptions{
Expand Down Expand Up @@ -260,7 +262,9 @@ func TestCreateFailureTargetComponentENV(t *testing.T) {

c, err := NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

assert.Equal(c.Data.FailureTarget.Target.Name, "kafka")
decoderOpts := &DecoderOptions{
Expand Down Expand Up @@ -305,7 +309,10 @@ func TestCreateObserverComponentHCL(t *testing.T) {

c, err := NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

assert.Equal(c.Data.StatsReceiver.TimeoutSec, 2)
assert.Equal(c.Data.StatsReceiver.BufferSec, 20)

Expand Down
52 changes: 38 additions & 14 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ func TestNewConfig(t *testing.T) {

c, err := NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

assert.Equal("info", c.Data.LogLevel)
assert.Equal("stdout", c.Data.Target.Use.Name)
assert.Equal("none", c.Data.Transformation)
assert.Equal("none", c.Data.Transform.Transformation)
assert.Equal("stdin", c.Data.Source.Use.Name)

// Tests on sources moved to the source package.
Expand Down Expand Up @@ -60,7 +62,9 @@ func TestNewConfig_FromEnv(t *testing.T) {

c, err := NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

assert.Equal("debug", c.Data.LogLevel)
assert.Equal("kinesis", c.Data.Target.Use.Name)
Expand Down Expand Up @@ -88,7 +92,9 @@ func TestNewConfig_InvalidTransformation(t *testing.T) {

c, err := NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

transformation, err := c.GetTransformations()
assert.Nil(transformation)
Expand All @@ -105,7 +111,9 @@ func TestNewConfig_FilterFailure(t *testing.T) {

c, err := NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

transformation, err := c.GetTransformations()
assert.Nil(transformation)
Expand All @@ -122,7 +130,9 @@ func TestNewConfig_InvalidTarget(t *testing.T) {

c, err := NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

source, err := c.GetTarget()
assert.Nil(source)
Expand All @@ -139,7 +149,9 @@ func TestNewConfig_InvalidFailureTarget(t *testing.T) {

c, err := NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

source, err := c.GetFailureTarget("testAppName", "0.0.0")
assert.Nil(source)
Expand All @@ -156,7 +168,9 @@ func TestNewConfig_InvalidFailureFormat(t *testing.T) {

c, err := NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

source, err := c.GetFailureTarget("testAppName", "0.0.0")
assert.Nil(source)
Expand All @@ -173,7 +187,9 @@ func TestNewConfig_InvalidStatsReceiver(t *testing.T) {

c, err := NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

source, err := c.GetObserver(map[string]string{})
assert.Nil(source)
Expand All @@ -186,7 +202,9 @@ func TestNewConfig_GetTags(t *testing.T) {

c, err := NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

tags, err := c.GetTags()
assert.NotNil(tags)
Expand All @@ -208,7 +226,9 @@ func TestNewConfig_Hcl_invalids(t *testing.T) {

c, err := NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

t.Run("invalid_transformation", func(t *testing.T) {
transformation, err := c.GetTransformations()
Expand Down Expand Up @@ -241,7 +261,9 @@ func TestNewConfig_Hcl_defaults(t *testing.T) {

c, err := NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

assert.Equal(c.Data.Source.Use.Name, "stdin")
assert.Equal(c.Data.Target.Use.Name, "stdout")
Expand All @@ -251,7 +273,7 @@ func TestNewConfig_Hcl_defaults(t *testing.T) {
assert.Equal(c.Data.Sentry.Debug, false)
assert.Equal(c.Data.StatsReceiver.TimeoutSec, 1)
assert.Equal(c.Data.StatsReceiver.BufferSec, 15)
assert.Equal(c.Data.Transformation, "none")
assert.Equal(c.Data.Transform.Transformation, "none")
assert.Equal(c.Data.LogLevel, "info")
}

Expand All @@ -263,7 +285,9 @@ func TestNewConfig_Hcl_sentry(t *testing.T) {

c, err := NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

assert.Equal(c.Data.Sentry.Debug, true)
assert.Equal(c.Data.Sentry.Tags, "{\"testKey\":\"testValue\"}")
Expand Down
8 changes: 6 additions & 2 deletions pkg/source/kinesis/kinesis_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ func TestGetSource_WithKinesisSource(t *testing.T) {

c, err := config.NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

// Use our function generator to interact with localstack
kinesisSourceConfigFunctionWithLocalstack := configFunctionGeneratorWithInterfaces(kinesisClient, dynamodbClient, "00000000000")
Expand Down Expand Up @@ -248,7 +250,9 @@ func TestKinesisSourceHCL(t *testing.T) {

c, err := config.NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

use := c.Data.Source.Use
decoderOpts := &config.DecoderOptions{
Expand Down
4 changes: 3 additions & 1 deletion pkg/source/sourceconfig/source_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ func TestNewConfig_InvalidSource(t *testing.T) {

c, err := config.NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

supportedSources := []ConfigPair{}

Expand Down
10 changes: 7 additions & 3 deletions pkg/source/sqs/sqs_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ func TestGetSource_WithSQSSource(t *testing.T) {

c, err := config.NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

sqsSourceConfigFunctionWithLocalStack := configFunctionGeneratorWithInterfaces(sqsClient, "00000000000")
adaptedHandle := adapterGenerator(sqsSourceConfigFunctionWithLocalStack)
Expand All @@ -134,7 +136,7 @@ func TestGetSource_WithSQSSource(t *testing.T) {
assert.IsType(&sqsSource{}, source)
}

func TestKinesisSourceHCL(t *testing.T) {
func TestSQSSourceHCL(t *testing.T) {
testFixPath := "../../../config/test-fixtures"
testCases := []struct {
File string
Expand Down Expand Up @@ -162,7 +164,9 @@ func TestKinesisSourceHCL(t *testing.T) {

c, err := config.NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

use := c.Data.Source.Use
decoderOpts := &config.DecoderOptions{
Expand Down
4 changes: 3 additions & 1 deletion pkg/source/stdin/stdin_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ func TestGetSource_WithStdinSource(t *testing.T) {

c, err := config.NewConfig()
assert.NotNil(c)
assert.Nil(err)
if err != nil {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

stdinSource, err := sourceconfig.GetSource(c, supportedSources)

Expand Down

0 comments on commit 910929d

Please sign in to comment.