Skip to content

Commit

Permalink
test(connector): fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hekike committed Aug 27, 2024
1 parent 7fc83f1 commit 1cd1725
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions openmeter/sink/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,21 @@ func TestInsertEventsQuery(t *testing.T) {

sql, args, err := query.ToSQL()
assert.NoError(t, err)
assert.Equal(t, args, []interface{}{

// Remove the ingested_at and stored_at fields from the args to make the comparison easier
argsWithoutIngestTimes := []interface{}{}
for idx, arg := range args {
// Skip the ingested_at and stored_at fields at indexes 8 and 9
if idx != 0 && (idx%8 == 0 || idx%9 == 0) {
continue
}
argsWithoutIngestTimes = append(argsWithoutIngestTimes, arg)
}

assert.Equal(t, []interface{}{
"my_namespace", "", "1", "api-calls", "source", "subject-1", now.UnixMilli(), `{"duration_ms": 100, "method": "GET", "path": "/api/v1"}`,
"my_namespace", "", "2", "api-calls", "source", "subject-2", now.UnixMilli(), `{"duration_ms": 80, "method": "GET", "path": "/api/v1"}`,
"my_namespace", "event data value cannot be parsed as float64: not a number", "3", "api-calls", "source", "subject-2", now.UnixMilli(), `{"duration_ms": "foo", "method": "GET", "path": "/api/v1"}`,
})
assert.Equal(t, `INSERT INTO database.om_events (namespace, validation_error, id, type, source, subject, time, data) VALUES (?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?)`, sql)
}, argsWithoutIngestTimes)
assert.Equal(t, `INSERT INTO database.om_events (namespace, validation_error, id, type, source, subject, time, data, ingested_at, stored_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?)`, sql)
}

0 comments on commit 1cd1725

Please sign in to comment.