Skip to content

Commit

Permalink
Fix unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
zackwine committed Jul 10, 2020
1 parent 8d294d5 commit 7d52cb2
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions kinesis/kinesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (

// newMockOutputPlugin creates an mock OutputPlugin object
func newMockOutputPlugin(client *mock_kinesis.MockPutRecordsClient) (*OutputPlugin, error) {
records := make([]*kinesis.PutRecordsRequestEntry, 0, 500)

timer, _ := plugins.NewTimeout(func(d time.Duration) {
logrus.Errorf("[kinesis] timeout threshold reached: Failed to send logs for %v", d)
Expand All @@ -34,15 +33,13 @@ func newMockOutputPlugin(client *mock_kinesis.MockPutRecordsClient) (*OutputPlug
}

return &OutputPlugin{
stream: "stream",
client: client,
records: records,
dataKeys: "",
partitionKey: "",
lastInvalidPartitionKeyIndex: -1,
timer: timer,
PluginID: 0,
random: random,
stream: "stream",
client: client,
dataKeys: "",
partitionKey: "",
timer: timer,
PluginID: 0,
random: random,
}, nil
}

Expand All @@ -67,19 +64,23 @@ func TestStringOrByteArray(t *testing.T) {
}

func TestAddRecord(t *testing.T) {
records := make([]*kinesis.PutRecordsRequestEntry, 0, 500)

record := map[interface{}]interface{}{
"testkey": []byte("test value"),
}

outputPlugin, _ := newMockOutputPlugin(nil)

timeStamp := time.Now()
retCode := outputPlugin.AddRecord(record, &timeStamp)
retCode := outputPlugin.AddRecord(&records, record, &timeStamp)
assert.Equal(t, retCode, fluentbit.FLB_OK, "Expected return code to be FLB_OK")
assert.Len(t, outputPlugin.records, 1, "Expected output to contain 1 record")
assert.Len(t, records, 1, "Expected output to contain 1 record")
}

func TestAddRecordAndFlush(t *testing.T) {
records := make([]*kinesis.PutRecordsRequestEntry, 0, 500)

record := map[interface{}]interface{}{
"testkey": []byte("test value"),
}
Expand All @@ -94,9 +95,9 @@ func TestAddRecordAndFlush(t *testing.T) {
outputPlugin, _ := newMockOutputPlugin(mockKinesis)

timeStamp := time.Now()
retCode := outputPlugin.AddRecord(record, &timeStamp)
retCode := outputPlugin.AddRecord(&records, record, &timeStamp)
assert.Equal(t, retCode, fluentbit.FLB_OK, "Expected return code to be FLB_OK")

retCode = outputPlugin.Flush()
retCode = outputPlugin.Flush(&records)
assert.Equal(t, retCode, fluentbit.FLB_OK, "Expected return code to be FLB_OK")
}

0 comments on commit 7d52cb2

Please sign in to comment.