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
57
58
59
60
61
|
package repository
import (
"bytes"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v14/streamio"
)
func TestGetInfoAttributesExisting(t *testing.T) {
t.Parallel()
_, repo, repoPath, client := setupRepositoryService(t)
infoPath := filepath.Join(repoPath, "info")
require.NoError(t, os.MkdirAll(infoPath, 0o755))
buffSize := streamio.WriteBufferSize + 1
data := bytes.Repeat([]byte("*.pbxproj binary\n"), buffSize)
attrsPath := filepath.Join(infoPath, "attributes")
err := ioutil.WriteFile(attrsPath, data, 0o644)
require.NoError(t, err)
request := &gitalypb.GetInfoAttributesRequest{Repository: repo}
testCtx, cancelCtx := testhelper.Context()
defer cancelCtx()
stream, err := client.GetInfoAttributes(testCtx, request)
require.NoError(t, err)
receivedData, err := io.ReadAll(streamio.NewReader(func() ([]byte, error) {
response, err := stream.Recv()
return response.GetAttributes(), err
}))
require.NoError(t, err)
require.Equal(t, data, receivedData)
}
func TestGetInfoAttributesNonExisting(t *testing.T) {
t.Parallel()
_, repo, _, client := setupRepositoryService(t)
request := &gitalypb.GetInfoAttributesRequest{Repository: repo}
testCtx, cancelCtx := testhelper.Context()
defer cancelCtx()
response, err := client.GetInfoAttributes(testCtx, request)
require.NoError(t, err)
message, err := response.Recv()
require.NoError(t, err)
require.Empty(t, message.GetAttributes())
}
|