Welcome to mirror list, hosted at ThFree Co, Russian Federation.

logging_test.go « logging « internal - gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8b49a4132cb0f1c93881d699783f2c740e0ebd3d (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
package logging

import (
	"net/http"
	"testing"

	"github.com/stretchr/testify/require"

	"gitlab.com/gitlab-org/gitlab-pages/internal/domain"
	"gitlab.com/gitlab-org/gitlab-pages/internal/request"
)

func TestGetExtraLogFields(t *testing.T) {
	tests := []struct {
		name   string
		https  bool
		host   string
		domain *domain.D
	}{
		{
			name:   "https",
			https:  true,
			host:   "githost.io",
			domain: &domain.D{},
		},
		{
			name:   "http",
			https:  false,
			host:   "githost.io",
			domain: &domain.D{},
		},
		{
			name:   "no_domain",
			https:  false,
			host:   "githost.io",
			domain: nil,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			req, err := http.NewRequest("GET", "/", nil)
			require.NoError(t, err)

			req = request.WithHTTPSFlag(req, tt.https)
			req = request.WithHostAndDomain(req, tt.host, tt.domain)

			got := getExtraLogFields(req)
			require.Equal(t, got["pages_https"], tt.https)
			require.Equal(t, got["pages_host"], tt.host)
			require.Equal(t, got["pages_project_id"], uint64(0x0))
		})
	}
}