@@ -3,6 +3,7 @@ package receivepack
3
3
import (
4
4
"bytes"
5
5
"context"
6
+ "fmt"
6
7
"testing"
7
8
8
9
"github.com/stretchr/testify/require"
@@ -17,80 +18,85 @@ import (
17
18
)
18
19
19
20
func TestReceivePack (t * testing.T ) {
20
- gitalyAddress , testServer := testserver .StartGitalyServer (t )
21
+ for _ , network := range []string {"unix" , "tcp" , "dns" } {
22
+ t .Run (fmt .Sprintf ("via %s network" , network ), func (t * testing.T ) {
23
+ gitalyAddress , testServer := testserver .StartGitalyServer (t , network )
24
+ t .Log (fmt .Sprintf ("Server address: %s" , gitalyAddress ))
21
25
22
- requests := requesthandlers .BuildAllowedWithGitalyHandlers (t , gitalyAddress )
23
- url := testserver .StartHttpServer (t , requests )
26
+ requests := requesthandlers .BuildAllowedWithGitalyHandlers (t , gitalyAddress )
27
+ url := testserver .StartHttpServer (t , requests )
24
28
25
- testCases := []struct {
26
- username string
27
- keyId string
28
- }{
29
- {
30
- username : "john.doe" ,
31
- },
32
- {
33
- keyId : "123" ,
34
- },
35
- }
29
+ testCases := []struct {
30
+ username string
31
+ keyId string
32
+ }{
33
+ {
34
+ username : "john.doe" ,
35
+ },
36
+ {
37
+ keyId : "123" ,
38
+ },
39
+ }
36
40
37
- for _ , tc := range testCases {
38
- output := & bytes.Buffer {}
39
- input := & bytes.Buffer {}
40
- repo := "group/repo"
41
+ for _ , tc := range testCases {
42
+ output := & bytes.Buffer {}
43
+ input := & bytes.Buffer {}
44
+ repo := "group/repo"
41
45
42
- env := sshenv.Env {
43
- IsSSHConnection : true ,
44
- OriginalCommand : "git-receive-pack " + repo ,
45
- RemoteAddr : "127.0.0.1" ,
46
- }
46
+ env := sshenv.Env {
47
+ IsSSHConnection : true ,
48
+ OriginalCommand : "git-receive-pack " + repo ,
49
+ RemoteAddr : "127.0.0.1" ,
50
+ }
47
51
48
- args := & commandargs.Shell {
49
- CommandType : commandargs .ReceivePack ,
50
- SshArgs : []string {"git-receive-pack" , repo },
51
- Env : env ,
52
- }
52
+ args := & commandargs.Shell {
53
+ CommandType : commandargs .ReceivePack ,
54
+ SshArgs : []string {"git-receive-pack" , repo },
55
+ Env : env ,
56
+ }
53
57
54
- if tc .username != "" {
55
- args .GitlabUsername = tc .username
56
- } else {
57
- args .GitlabKeyId = tc .keyId
58
- }
58
+ if tc .username != "" {
59
+ args .GitlabUsername = tc .username
60
+ } else {
61
+ args .GitlabKeyId = tc .keyId
62
+ }
59
63
60
- cfg := & config.Config {GitlabUrl : url }
61
- cfg .GitalyClient .InitSidechannelRegistry (context .Background ())
62
- cmd := & Command {
63
- Config : cfg ,
64
- Args : args ,
65
- ReadWriter : & readwriter.ReadWriter {ErrOut : output , Out : output , In : input },
66
- }
64
+ cfg := & config.Config {GitlabUrl : url }
65
+ cfg .GitalyClient .InitSidechannelRegistry (context .Background ())
66
+ cmd := & Command {
67
+ Config : cfg ,
68
+ Args : args ,
69
+ ReadWriter : & readwriter.ReadWriter {ErrOut : output , Out : output , In : input },
70
+ }
67
71
68
- ctx := correlation .ContextWithCorrelation (context .Background (), "a-correlation-id" )
69
- ctx = correlation .ContextWithClientName (ctx , "gitlab-shell-tests" )
72
+ ctx := correlation .ContextWithCorrelation (context .Background (), "a-correlation-id" )
73
+ ctx = correlation .ContextWithClientName (ctx , "gitlab-shell-tests" )
70
74
71
- err := cmd .Execute (ctx )
72
- require .NoError (t , err )
75
+ err := cmd .Execute (ctx )
76
+ require .NoError (t , err )
73
77
74
- if tc .username != "" {
75
- require .Equal (t , "ReceivePack: 1 " + repo , output .String ())
76
- } else {
77
- require .Equal (t , "ReceivePack: key-123 " + repo , output .String ())
78
- }
78
+ if tc .username != "" {
79
+ require .Equal (t , "ReceivePack: 1 " + repo , output .String ())
80
+ } else {
81
+ require .Equal (t , "ReceivePack: key-123 " + repo , output .String ())
82
+ }
79
83
80
- for k , v := range map [string ]string {
81
- "gitaly-feature-cache_invalidator" : "true" ,
82
- "gitaly-feature-inforef_uploadpack_cache" : "false" ,
83
- "x-gitlab-client-name" : "gitlab-shell-tests-git-receive-pack" ,
84
- "key_id" : "123" ,
85
- "user_id" : "1" ,
86
- "remote_ip" : "127.0.0.1" ,
87
- "key_type" : "key" ,
88
- } {
89
- actual := testServer .ReceivedMD [k ]
90
- require .Len (t , actual , 1 )
91
- require .Equal (t , v , actual [0 ])
92
- }
93
- require .Empty (t , testServer .ReceivedMD ["some-other-ff" ])
94
- require .Equal (t , testServer .ReceivedMD ["x-gitlab-correlation-id" ][0 ], "a-correlation-id" )
84
+ for k , v := range map [string ]string {
85
+ "gitaly-feature-cache_invalidator" : "true" ,
86
+ "gitaly-feature-inforef_uploadpack_cache" : "false" ,
87
+ "x-gitlab-client-name" : "gitlab-shell-tests-git-receive-pack" ,
88
+ "key_id" : "123" ,
89
+ "user_id" : "1" ,
90
+ "remote_ip" : "127.0.0.1" ,
91
+ "key_type" : "key" ,
92
+ } {
93
+ actual := testServer .ReceivedMD [k ]
94
+ require .Len (t , actual , 1 )
95
+ require .Equal (t , v , actual [0 ])
96
+ }
97
+ require .Empty (t , testServer .ReceivedMD ["some-other-ff" ])
98
+ require .Equal (t , testServer .ReceivedMD ["x-gitlab-correlation-id" ][0 ], "a-correlation-id" )
99
+ }
100
+ })
95
101
}
96
102
}
0 commit comments