Skip to content

Commit

Permalink
Remove unnecessary test files
Browse files Browse the repository at this point in the history
  • Loading branch information
adatzer committed Jul 1, 2024
1 parent 3c58dfa commit e7791ef
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 84 deletions.
6 changes: 0 additions & 6 deletions assets/test/config/configs/invalid-failure-format.hcl

This file was deleted.

3 changes: 0 additions & 3 deletions assets/test/config/configs/invalid-type.hcl

This file was deleted.

3 changes: 0 additions & 3 deletions assets/test/source/configs/source-invalid.hcl

This file was deleted.

8 changes: 0 additions & 8 deletions assets/test/source/configs/source-kafka-with-env.hcl

This file was deleted.

9 changes: 0 additions & 9 deletions assets/test/source/configs/source-kinesis-with-env.hcl

This file was deleted.

3 changes: 0 additions & 3 deletions assets/test/source/configs/source-mock.hcl

This file was deleted.

6 changes: 0 additions & 6 deletions assets/test/source/configs/source-pubsub-with-env.hcl

This file was deleted.

8 changes: 0 additions & 8 deletions assets/test/source/configs/source-sqs-with-env.hcl

This file was deleted.

3 changes: 0 additions & 3 deletions assets/test/source/configs/source-stdin.hcl

This file was deleted.

3 changes: 0 additions & 3 deletions cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,8 @@ func TestInit_SLULAFailre(t *testing.T) {

func TestInit_Failure(t *testing.T) {
assert := assert.New(t)
filename := filepath.Join(assets.AssetsRootDir, "test", "config", "configs", "invalid-type.hcl")
t.Setenv("SNOWBRIDGE_CONFIG_FILE", filename)

t.Setenv("ACCEPT_LIMITED_USE_LICENSE", "on")
t.Setenv("STATS_RECEIVER_TIMEOUT_SEC", "debug")

cfg, _, err := Init()
assert.Nil(cfg)
Expand Down
8 changes: 6 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestNewConfig_NoConfig(t *testing.T) {
func TestNewConfig_InvalidFailureFormat(t *testing.T) {
assert := assert.New(t)

filename := filepath.Join(assets.AssetsRootDir, "test", "config", "configs", "invalid-failure-format.hcl")
filename := filepath.Join(assets.AssetsRootDir, "test", "config", "configs", "empty.hcl")
t.Setenv("SNOWBRIDGE_CONFIG_FILE", filename)

c, err := NewConfig()
Expand All @@ -43,6 +43,7 @@ func TestNewConfig_InvalidFailureFormat(t *testing.T) {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

c.Data.FailureTarget.Format = "fakeHCL"
ft, err := c.GetFailureTarget("testAppName", "0.0.0")
assert.Nil(ft)
assert.NotNil(err)
Expand Down Expand Up @@ -78,7 +79,7 @@ func TestNewConfig_GetTags(t *testing.T) {
func TestNewConfig_Hcl_invalids(t *testing.T) {
assert := assert.New(t)

filename := filepath.Join(assets.AssetsRootDir, "test", "config", "configs", "invalids.hcl")
filename := filepath.Join(assets.AssetsRootDir, "test", "config", "configs", "empty.hcl")
t.Setenv("SNOWBRIDGE_CONFIG_FILE", filename)

c, err := NewConfig()
Expand All @@ -87,6 +88,9 @@ func TestNewConfig_Hcl_invalids(t *testing.T) {
t.Fatalf("function NewConfig failed with error: %q", err.Error())
}

c.Data.Target.Use.Name = "fakeHCL"
c.Data.FailureTarget.Target.Name = "fakeHCL"
c.Data.StatsReceiver.Receiver.Name = "fakeHCL"
t.Run("invalid_target", func(t *testing.T) {
target, err := c.GetTarget()
assert.Nil(target)
Expand Down
31 changes: 23 additions & 8 deletions pkg/source/kafka/kafka_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/IBM/sarama"
"github.com/hashicorp/hcl/v2/hclparse"
"github.com/snowplow/snowbridge/assets"
"github.com/snowplow/snowbridge/config"
"github.com/snowplow/snowbridge/pkg/source/sourceconfig"
Expand Down Expand Up @@ -74,22 +75,37 @@ func TestKafkaSource_ReadAndReturnSuccessIntegration(t *testing.T) {
}

// Configure the kafka source
filename := filepath.Join(assets.AssetsRootDir, "test", "source", "configs", "source-kafka-with-env.hcl")
filename := filepath.Join(assets.AssetsRootDir, "test", "config", "configs", "empty.hcl")
t.Setenv("SNOWBRIDGE_CONFIG_FILE", filename)

t.Setenv("TEST_KAFKA_BROKERS", "localhost:9092")
t.Setenv("TEST_KAFKA_TOPIC_NAME", topicName)
t.Setenv("TEST_KAFKA_CONSUMER_NAME", "integration")
t.Setenv("TEST_KAFKA_OFFSETS_INITIAL", "-2")

adaptedHandle := adapterGenerator(configFunction)

kafkaSourceConfigPair := config.ConfigurationPair{Name: "kafka", Handle: adaptedHandle}
supportedSources := []config.ConfigurationPair{kafkaSourceConfigPair}

// Construct the config
kafkaSourceConfig, err := config.NewConfig()
assert.NotNil(kafkaSourceConfig)
assert.Nil(err)

if err != nil {
t.Fatalf("unexpected error: %q", err.Error())
}

configBytesToMerge := []byte(fmt.Sprintf(`
brokers = "localhost:9092"
topic_name = "%s"
consumer_name = "integration"
offsets_initial = "-2"
`, topicName))

parser := hclparse.NewParser()
fileHCL, diags := parser.ParseHCL(configBytesToMerge, "placeholder")
if diags.HasErrors() {
t.Fatalf("failed to parse config bytes")
}

kafkaSourceConfig.Data.Source.Use.Name = "kafka"
kafkaSourceConfig.Data.Source.Use.Body = fileHCL.Body

kafkaSource, err := sourceconfig.GetSource(kafkaSourceConfig, supportedSources)

Expand Down Expand Up @@ -117,5 +133,4 @@ func TestKafkaSource_ReadAndReturnSuccessIntegration(t *testing.T) {
for i, valFound := range found {
assert.Equal(i, valFound)
}

}
24 changes: 19 additions & 5 deletions pkg/source/kinesis/kinesis_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ package kinesissource

import (
"errors"
"fmt"
"os"
"path/filepath"
"reflect"
"testing"
"time"

"github.com/davecgh/go-spew/spew"
"github.com/hashicorp/hcl/v2/hclparse"
"github.com/stretchr/testify/assert"

"github.com/snowplow/snowbridge/assets"
Expand Down Expand Up @@ -237,19 +239,31 @@ func TestGetSource_WithKinesisSource(t *testing.T) {
}
defer testutil.DeleteAWSLocalstackDynamoDBTables(dynamodbClient, appName)

filename := filepath.Join(assets.AssetsRootDir, "test", "source", "configs", "source-kinesis-with-env.hcl")
filename := filepath.Join(assets.AssetsRootDir, "test", "config", "configs", "empty.hcl")
t.Setenv("SNOWBRIDGE_CONFIG_FILE", filename)

t.Setenv("TEST_KINESIS_STREAM_NAME", streamName)
t.Setenv("TEST_KINESIS_REGION", testutil.AWSLocalstackRegion)
t.Setenv("TEST_KINESIS_APP_NAME", appName)

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

configBytesToMerge := []byte(fmt.Sprintf(`
stream_name = "%s"
region = "%s"
app_name = "%s"
`, streamName, testutil.AWSLocalstackRegion, appName))

parser := hclparse.NewParser()
fileHCL, diags := parser.ParseHCL(configBytesToMerge, "placeholder")
if diags.HasErrors() {
t.Fatalf("failed to parse config bytes")
}

c.Data.Source.Use.Name = "kinesis"
c.Data.Source.Use.Body = fileHCL.Body

// use our function generator to interact with localstack
kinesisSourceConfigFunctionWithLocalstack := configFunctionGeneratorWithInterfaces(kinesisClient, dynamodbClient, "00000000000")
adaptedHandle := adapterGenerator(kinesisSourceConfigFunctionWithLocalstack)
Expand Down
50 changes: 40 additions & 10 deletions pkg/source/pubsub/pubsub_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package pubsubsource

import (
"context"
"fmt"
"os"
"path/filepath"
"sort"
Expand All @@ -21,6 +22,7 @@ import (
"testing"
"time"

"github.com/hashicorp/hcl/v2/hclparse"
"github.com/stretchr/testify/assert"

"github.com/snowplow/snowbridge/assets"
Expand Down Expand Up @@ -48,20 +50,34 @@ func TestPubSubSource_ReadAndReturnSuccessIntegration(t *testing.T) {
// Write to topic
testutil.WriteToPubSubTopic(t, topic, 10)

filename := filepath.Join(assets.AssetsRootDir, "test", "source", "configs", "source-pubsub-with-env.hcl")
filename := filepath.Join(assets.AssetsRootDir, "test", "config", "configs", "empty.hcl")
t.Setenv("SNOWBRIDGE_CONFIG_FILE", filename)

t.Setenv("TEST_PUBSUB_SUBSCRIPTION_ID", "test-sub")
t.Setenv("TEST_PUBSUB_PROJECT_ID", `project-test`)

adaptedHandle := adapterGenerator(configFunction)

pubsubSourceConfigPair := config.ConfigurationPair{Name: "pubsub", Handle: adaptedHandle}
supportedSources := []config.ConfigurationPair{pubsubSourceConfigPair}

// Construct the config
pubsubConfig, err := config.NewConfig()
assert.NotNil(pubsubConfig)
assert.Nil(err)
if err != nil {
t.Fatalf("unexpected error: %q", err.Error())
}

configBytesToMerge := []byte(fmt.Sprintf(`
project_id = "project-test"
subscription_id = "test-sub"
`))

parser := hclparse.NewParser()
fileHCL, diags := parser.ParseHCL(configBytesToMerge, "placeholder")
if diags.HasErrors() {
t.Fatalf("failed to parse config bytes")
}

pubsubConfig.Data.Source.Use.Name = "pubsub"
pubsubConfig.Data.Source.Use.Body = fileHCL.Body

pubsubSource, err := sourceconfig.GetSource(pubsubConfig, supportedSources)

Expand Down Expand Up @@ -165,20 +181,34 @@ func TestPubSubSource_ReadAndReturnSuccessWithMock_DelayedAcks(t *testing.T) {
}
wg.Wait()

filename := filepath.Join(assets.AssetsRootDir, "test", "source", "configs", "source-pubsub-with-env.hcl")
filename := filepath.Join(assets.AssetsRootDir, "test", "config", "configs", "empty.hcl")
t.Setenv("SNOWBRIDGE_CONFIG_FILE", filename)

t.Setenv("TEST_PUBSUB_SUBSCRIPTION_ID", "test-sub")
t.Setenv("TEST_PUBSUB_PROJECT_ID", `project-test`)

adaptedHandle := adapterGenerator(configFunction)

pubsubSourceConfigPair := config.ConfigurationPair{Name: "pubsub", Handle: adaptedHandle}
supportedSources := []config.ConfigurationPair{pubsubSourceConfigPair}

// Construct the config
pubsubConfig, err := config.NewConfig()
assert.NotNil(pubsubConfig)
assert.Nil(err)
if err != nil {
t.Fatalf("unexpected error: %q", err.Error())
}

configBytesToMerge := []byte(fmt.Sprintf(`
project_id = "project-test"
subscription_id = "test-sub"
`))

parser := hclparse.NewParser()
fileHCL, diags := parser.ParseHCL(configBytesToMerge, "placeholder")
if diags.HasErrors() {
t.Fatalf("failed to parse config bytes")
}

pubsubConfig.Data.Source.Use.Name = "pubsub"
pubsubConfig.Data.Source.Use.Body = fileHCL.Body

pubsubSource, err := sourceconfig.GetSource(pubsubConfig, supportedSources)

Expand Down
9 changes: 6 additions & 3 deletions pkg/source/sourceconfig/source_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ var mockConfigPair = config.ConfigurationPair{
func TestGetSource_ValidSource(t *testing.T) {
assert := assert.New(t)

filename := filepath.Join(assets.AssetsRootDir, "test", "source", "configs", "source-mock.hcl")
filename := filepath.Join(assets.AssetsRootDir, "test", "config", "configs", "empty.hcl")
t.Setenv("SNOWBRIDGE_CONFIG_FILE", filename)

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

supportedSources := []config.ConfigurationPair{mockConfigPair}

Expand All @@ -97,14 +98,15 @@ func TestGetSource_ValidSource(t *testing.T) {
func TestGetSource_InvalidSource(t *testing.T) {
assert := assert.New(t)

filename := filepath.Join(assets.AssetsRootDir, "test", "source", "configs", "source-invalid.hcl")
filename := filepath.Join(assets.AssetsRootDir, "test", "config", "configs", "empty.hcl")
t.Setenv("SNOWBRIDGE_CONFIG_FILE", filename)

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

supportedSources := []config.ConfigurationPair{}

Expand Down Expand Up @@ -132,14 +134,15 @@ var mockUnhappyConfigPair = config.ConfigurationPair{
func TestGetSource_BadConfig(t *testing.T) {
assert := assert.New(t)

filename := filepath.Join(assets.AssetsRootDir, "test", "source", "configs", "source-mock.hcl")
filename := filepath.Join(assets.AssetsRootDir, "test", "config", "configs", "empty.hcl")
t.Setenv("SNOWBRIDGE_CONFIG_FILE", filename)

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

supportedSources := []config.ConfigurationPair{mockUnhappyConfigPair}

Expand Down
Loading

0 comments on commit e7791ef

Please sign in to comment.