about summary refs log tree commit diff
path: root/src/rest-api/handler/handler_test.go
blob: 94b58e421c4d30806e61e04f79eb3f88ffd05688 (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
package handler

import (
	"fmt"
	"net/http"
	"net/http/httptest"
	"strings"
	"testing"

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

func TestHandleGet(t *testing.T) {
	ctrl := gomock.NewController(t)
	db := NewMockDB(ctrl)
	recorder := httptest.NewRecorder()

	handler := Handler{db: db}

	file := &lib.File{
		Absolute_path: "/tmp/file.txt",
	}
	db.EXPECT().GetLatestFileByPath(gomock.Any(), "/tmp/file.txt").Return(file, nil)

	handler.handleGet(recorder, httptest.NewRequest(http.MethodGet, "/file/%2ftmp%2Ffile.txt", nil))

	require.Equal(t, http.StatusOK, recorder.Code)
	require.Equal(t, fmt.Sprintln("File: ", file), recorder.Body.String())
}