-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check if eve is nil; add test for kinesis
- Loading branch information
Showing
4 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/aws/aws-lambda-go/events" | ||
"github.com/grafana/loki/pkg/logproto" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type MockBatch struct { | ||
streams map[string]*logproto.Stream | ||
size int | ||
} | ||
|
||
func (b *MockBatch) add(ctx context.Context, e entry) error { | ||
return nil | ||
} | ||
|
||
func (b *MockBatch) flushBatch(ctx context.Context) error { | ||
return nil | ||
} | ||
func (b *MockBatch) encode() ([]byte, int, error) { | ||
return nil, 0, nil | ||
} | ||
func (b *MockBatch) createPushRequest() (*logproto.PushRequest, int) { | ||
return nil, 0 | ||
} | ||
|
||
func ReadJSONFromFile(t *testing.T, inputFile string) []byte { | ||
inputJSON, err := ioutil.ReadFile(inputFile) | ||
if err != nil { | ||
t.Errorf("could not open test file. details: %v", err) | ||
} | ||
|
||
return inputJSON | ||
} | ||
|
||
func TestLambdaPromtail_KinesisParseEvents(t *testing.T) { | ||
inputJson, err := ioutil.ReadFile("../testdata/kinesis-event.json") | ||
|
||
if err != nil { | ||
t.Errorf("could not open test file. details: %v", err) | ||
} | ||
|
||
var testEvent events.KinesisEvent | ||
if err := json.Unmarshal(inputJson, &testEvent); err != nil { | ||
t.Errorf("could not unmarshal event. details: %v", err) | ||
} | ||
|
||
ctx := context.TODO() | ||
b := &MockBatch{ | ||
streams: map[string]*logproto.Stream{}, | ||
} | ||
|
||
err = parseKinesisEvent(ctx, b, &testEvent) | ||
|
||
require.Nil(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"Records": [ | ||
{ | ||
"kinesis": { | ||
"kinesisSchemaVersion": "1.0", | ||
"partitionKey": "s1", | ||
"sequenceNumber": "49568167373333333333333333333333333333333333333333333333", | ||
"data": "SGVsbG8gV29ybGQ=", | ||
"approximateArrivalTimestamp": 1480641523.477 | ||
}, | ||
"eventSource": "aws:kinesis", | ||
"eventVersion": "1.0", | ||
"eventID": "shardId-000000000000:49568167373333333333333333333333333333333333333333333333", | ||
"eventName": "aws:kinesis:record", | ||
"invokeIdentityArn": "arn:aws:iam::123456789012:role/LambdaRole", | ||
"awsRegion": "us-east-1", | ||
"eventSourceARN": "arn:aws:kinesis:us-east-1:123456789012:stream/simple-stream" | ||
}, | ||
{ | ||
"kinesis": { | ||
"kinesisSchemaVersion": "1.0", | ||
"partitionKey": "s1", | ||
"sequenceNumber": "49568167373333333334444444444444444444444444444444444444", | ||
"data": "SGVsbG8gV29ybGQ=", | ||
"approximateArrivalTimestamp": 1480841523.477 | ||
}, | ||
"eventSource": "aws:kinesis", | ||
"eventVersion": "1.0", | ||
"eventID": "shardId-000000000000:49568167373333333334444444444444444444444444444444444444", | ||
"eventName": "aws:kinesis:record", | ||
"invokeIdentityArn": "arn:aws:iam::123456789012:role/LambdaRole", | ||
"awsRegion": "us-east-1", | ||
"eventSourceARN": "arn:aws:kinesis:us-east-1:123456789012:stream/simple-stream" | ||
} | ||
] | ||
} |