about summary refs log tree commit diff
path: root/src/payload-processor/processor/processor_test.go
blob: 39e965e9f68b169fa62de27e872c53ca053b85b8 (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
41
42
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(`
	{
		"user_id": "1",
		"absolute_path": "/tmp/file.txt",
		"contents": "hello world",
		"timestamp": "2021-01-01T00:00:00Z"
	}
	`)

	ctx := context.Background()

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

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

	require.NoError(t, err)
}