about summary refs log blame commit diff
path: root/src/payload-processor/processor/processor_test.go
blob: 39e965e9f68b169fa62de27e872c53ca053b85b8 (plain) (tree)
1
2
3
4
5
6
7
8
9
10


                 
                 
                 
              
 
                                                  

                                             
                                        


                                       




                                       
 







                                                   
 
                                   
 
                                                 




                                                                           

                                                                          


                               
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)
}