exec_test.go 976 Bytes
Newer Older
1 2 3 4
package handler

import (
	"context"
5
	"errors"
6 7 8 9
	"testing"

	"github.com/stretchr/testify/require"
	"google.golang.org/grpc"
10

Nick Thomas's avatar
Nick Thomas committed
11
	"gitlab.com/gitlab-org/gitlab-shell/internal/config"
12 13
)

14 15 16 17
func makeHandler(t *testing.T, err error) func(context.Context, *grpc.ClientConn) (int32, error) {
	return func(ctx context.Context, client *grpc.ClientConn) (int32, error) {
		require.NotNil(t, ctx)
		require.NotNil(t, client)
18

19
		return 0, err
20
	}
21 22 23 24 25 26
}

func TestRunGitalyCommand(t *testing.T) {
	cmd := GitalyCommand{
		Config:  &config.Config{},
		Address: "tcp://localhost:9999",
27 28
	}

29 30
	err := cmd.RunGitalyCommand(makeHandler(t, nil))
	require.NoError(t, err)
31

32 33 34 35
	expectedErr := errors.New("error")
	err = cmd.RunGitalyCommand(makeHandler(t, expectedErr))
	require.Equal(t, err, expectedErr)
}
36

37 38 39 40 41
func TestMissingGitalyAddress(t *testing.T) {
	cmd := GitalyCommand{Config: &config.Config{}}

	err := cmd.RunGitalyCommand(makeHandler(t, nil))
	require.EqualError(t, err, "no gitaly_address given")
42
}