blob: 925a4ff7419f65ca8dae9f28c8167a54a00dbf77 (
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
57
|
package git
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/config"
)
type fakeProtocolMessage struct {
protocol string
}
func (f fakeProtocolMessage) GetGitProtocol() string {
return f.protocol
}
func setGitProtocolV2Support(value bool) func() {
orig := config.Config.Git.ProtocolV2Enabled
config.Config.Git.ProtocolV2Enabled = value
return func() {
config.Config.Git.ProtocolV2Enabled = orig
}
}
func TestAddGitProtocolEnvRespectsConfigEnabled(t *testing.T) {
restore := setGitProtocolV2Support(true)
defer restore()
env := []string{"fake=value"}
msg := fakeProtocolMessage{protocol: "version=2"}
value := AddGitProtocolEnv(context.Background(), msg, env)
require.Equal(t, value, append(env, "GIT_PROTOCOL=version=2"))
}
func TestAddGitProtocolEnvWhenV2NotRequested(t *testing.T) {
restore := setGitProtocolV2Support(true)
defer restore()
env := []string{"fake=value"}
msg := fakeProtocolMessage{protocol: ""}
value := AddGitProtocolEnv(context.Background(), msg, env)
require.Equal(t, value, env)
}
func TestAddGitProtocolEnvRespectsConfigDisabled(t *testing.T) {
restore := setGitProtocolV2Support(false)
defer restore()
env := []string{"fake=value"}
msg := fakeProtocolMessage{protocol: "GIT_PROTOCOL=version=2"}
value := AddGitProtocolEnv(context.Background(), msg, env)
require.Equal(t, value, env)
}
|