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 acceptance_test
import (
"io/ioutil"
"net/http"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestProxyv2(t *testing.T) {
skipUnlessEnabled(t)
logBuf, teardown := RunPagesProcessWithOutput(t, *pagesBinary, supportedListeners(), "")
defer teardown()
// the dummy client IP 10.1.1.1 is set by TestProxyv2Client
tests := map[string]struct {
host string
urlSuffix string
expectedStatusCode int
expectedContent string
expectedLog string
}{
"basic_proxyv2_request": {
host: "group.gitlab-example.com",
urlSuffix: "project/",
expectedStatusCode: http.StatusOK,
expectedContent: "project-subdir\n",
expectedLog: "group.gitlab-example.com 10.1.1.1",
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
logBuf.Reset()
response, err := GetPageFromListener(t, httpsProxyv2Listener, tt.host, tt.urlSuffix)
require.NoError(t, err)
defer response.Body.Close()
require.Equal(t, tt.expectedStatusCode, response.StatusCode)
body, err := ioutil.ReadAll(response.Body)
require.NoError(t, err)
require.Contains(t, string(body), tt.expectedContent, "content mismatch")
// give the process enough time to write the log message
require.Eventually(t, func() bool {
require.Contains(t, logBuf.String(), tt.expectedLog, "log mismatch")
return true
}, time.Second, time.Millisecond)
})
}
}
|