Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pondzix committed Nov 12, 2024
1 parent 7db468b commit 4c96a40
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
metrics {
enable_e2e_latency = true
}
44 changes: 44 additions & 0 deletions pkg/transform/snowplow_collector_tstamp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package transform

import (
"testing"
"time"

"github.com/snowplow/snowbridge/pkg/models"
"github.com/stretchr/testify/assert"
)

func TestCollectorTstamp_Snowplow_Data(t *testing.T) {
assert := assert.New(t)

input := models.Message{
Data: SnowplowTsv1,
PartitionKey: "some-key",
}

ts := CollectorTstampTransformation()

good, filtered, invalid, _ := ts(&input, nil)

assert.Equal(time.Date(2019, 5, 10, 14, 40, 35, 972000000, time.UTC), good.CollectorTstamp)
assert.Empty(filtered)
assert.Empty(invalid)
}

func TestCollectorTstamp_Non_Snowplow_Data(t *testing.T) {
assert := assert.New(t)

input := &models.Message{
Data: []byte("Some kind of custom non-Snowplow data"),
PartitionKey: "some-key",
}

ts := CollectorTstampTransformation()

good, filtered, invalid, _ := ts(input, nil)

assert.Equal(input, good)
assert.Empty(good.CollectorTstamp)
assert.Empty(filtered)
assert.Empty(invalid)
}
21 changes: 21 additions & 0 deletions pkg/transform/transformconfig/transform_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"path/filepath"
"strings"
"testing"
"time"

"github.com/stretchr/testify/assert"

Expand Down Expand Up @@ -165,6 +166,21 @@ func TestEnginesAndTransformations(t *testing.T) {
}},
},
},
{
Description: `e2e latency metric enabled -> collector tstamp attached`,
File: "transform-collector-tstamp.hcl",
ExpectedMessages: expectedMessages{
Before: []*models.Message{{
Data: snowplowTsv1,
PartitionKey: "some-key",
}},
After: []*models.Message{{
Data: snowplowTsv1,
PartitionKey: "some-key",
CollectorTstamp: time.Date(2019, 5, 10, 14, 40, 35, 972000000, time.UTC),
}},
},
},
}

// Absolute paths to scripts
Expand Down Expand Up @@ -232,6 +248,11 @@ func TestEnginesAndTransformations(t *testing.T) {
assert.Equal(resultMessage.GetError(), tt.ExpectedMessages.After[idx].GetError())
}

// check if collector timestamp has been attached
for idx, resultMessage := range result.Result {
assert.Equal(resultMessage.CollectorTstamp, tt.ExpectedMessages.After[idx].CollectorTstamp)
}

// check result for transformed messages in case of filtered results
if result.FilteredCount != 0 {
assert.NotNil(result.Filtered)
Expand Down

0 comments on commit 4c96a40

Please sign in to comment.