about summary refs log tree commit diff
path: root/src/payload-processor/processor/processor_test.go
blob: 4a55e484df9af29e9e532f06401ae69df4c3818b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package processor

import (
	"context"
	"testing"
	"time"

	"github.com/Baitinq/fs-tracer-backend/lib"
	"github.com/segmentio/kafka-go"
	"github.com/stretchr/testify/require"
	gomock "go.uber.org/mock/gomock"
)

func TestProcessMessage(t *testing.T) {
	ctrl := gomock.NewController(t)
	mockdb := NewMockDB(ctrl)
	processor := Processor{
		db: mockdb,
	}

	message := []byte(`
	{
		"absolute_path": "/tmp/file.txt",
		"contents": "hello world",
		"timestamp": "2021-01-01T00:00:00Z"
	}
	`)

	ctx := context.Background()

	mockdb.EXPECT().InsertFile(ctx, lib.File{
		Absolute_path: "/tmp/file.txt",
		Contents:      "hello world",
		Timestamp:     time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
	}, "USER_ID").Return(nil)

	err := processor.handleMessage(ctx, kafka.Message{Value: message}, "USER_ID")

	require.NoError(t, err)
}