Welcome to mirror list, hosted at ThFree Co, Russian Federation.

info_attributes_test.go « repository « service « gitaly « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 984906469be782f28b5414f9fc761f8bb3f8b48d (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package repository

import (
	"bytes"
	"io/ioutil"
	"os"
	"path/filepath"

	"gitlab.com/gitlab-org/gitaly/internal/testhelper"
	"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
	"gitlab.com/gitlab-org/gitaly/streamio"
)

func (suite *RepositoryServiceTestSuite) TestGetInfoAttributesExisting() {
	require := suite.Require()

	infoPath := filepath.Join(suite.repositoryPath, "info")
	os.MkdirAll(infoPath, 0755)

	buffSize := streamio.WriteBufferSize + 1
	data := bytes.Repeat([]byte("*.pbxproj binary\n"), buffSize)
	attrsPath := filepath.Join(infoPath, "attributes")
	err := ioutil.WriteFile(attrsPath, data, 0644)
	require.NoError(err)

	request := &gitalypb.GetInfoAttributesRequest{Repository: suite.repository}
	testCtx, cancelCtx := testhelper.Context()
	defer cancelCtx()

	stream, err := suite.client.GetInfoAttributes(testCtx, request)
	require.NoError(err)

	receivedData, err := ioutil.ReadAll(streamio.NewReader(func() ([]byte, error) {
		response, err := stream.Recv()
		return response.GetAttributes(), err
	}))

	require.NoError(err)
	require.Equal(data, receivedData)
}

func (suite *RepositoryServiceTestSuite) TestGetInfoAttributesNonExisting() {
	require := suite.Require()

	request := &gitalypb.GetInfoAttributesRequest{Repository: suite.repository}
	testCtx, cancelCtx := testhelper.Context()
	defer cancelCtx()

	response, err := suite.client.GetInfoAttributes(testCtx, request)
	require.NoError(err)

	message, err := response.Recv()
	require.NoError(err)

	require.Empty(message.GetAttributes())
}