diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2021-01-20 06:01:43 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2021-01-27 01:54:29 +0300 |
commit | ac0a67449fff1249196dcb857d9c19ed93f1dca7 (patch) | |
tree | 09cc8a438ce222844ba64223be673d60771930ff /internal/logging | |
parent | b6cb354751a88d62980f35ed9c085b0e487d5a80 (diff) |
Update logging tests
Diffstat (limited to 'internal/logging')
-rw-r--r-- | internal/logging/logging.go | 1 | ||||
-rw-r--r-- | internal/logging/logging_test.go | 36 |
2 files changed, 22 insertions, 15 deletions
diff --git a/internal/logging/logging.go b/internal/logging/logging.go index baf87e60..43fe65e6 100644 --- a/internal/logging/logging.go +++ b/internal/logging/logging.go @@ -62,7 +62,6 @@ func getExtraLogFields(r *http.Request) log.Fields { lp, err := d.GetLookupPath(r) if err != nil { logFields["error"] = err.Error() - return logFields } diff --git a/internal/logging/logging_test.go b/internal/logging/logging_test.go index 9079cc9d..f2b344a7 100644 --- a/internal/logging/logging_test.go +++ b/internal/logging/logging_test.go @@ -11,22 +11,27 @@ import ( "gitlab.com/gitlab-org/gitlab-pages/internal/serving" ) -type lookupPathFunc func(*http.Request) *serving.LookupPath +type resolver struct { + err error + f func(*http.Request) *serving.LookupPath +} + +func (r *resolver) Resolve(req *http.Request) (*serving.Request, error) { + if r.f != nil { + return &serving.Request{LookupPath: r.f(req)}, nil + } -func (f lookupPathFunc) Resolve(r *http.Request) (*serving.Request, error) { - return &serving.Request{LookupPath: f(r)}, nil + return nil, r.err } func TestGetExtraLogFields(t *testing.T) { - domainWithResolver := &domain.Domain{ - Resolver: lookupPathFunc(func(*http.Request) *serving.LookupPath { - return &serving.LookupPath{ - ServingType: "file", - ProjectID: 100, - Prefix: "/prefix", - } - }), - } + domainWithResolver := domain.New("", "", "", &resolver{f: func(*http.Request) *serving.LookupPath { + return &serving.LookupPath{ + ServingType: "file", + ProjectID: 100, + Prefix: "/prefix", + } + }}) tests := []struct { name string @@ -38,6 +43,7 @@ func TestGetExtraLogFields(t *testing.T) { expectedProjectID interface{} expectedProjectPrefix interface{} expectedServingType interface{} + expectedErrMsg interface{} }{ { name: "https", @@ -62,7 +68,7 @@ func TestGetExtraLogFields(t *testing.T) { expectedServingType: "file", }, { - name: "domain_without_resolved", + name: "domain_not_configured", scheme: request.SchemeHTTP, host: "githost.io", domain: nil, @@ -75,11 +81,12 @@ func TestGetExtraLogFields(t *testing.T) { name: "no_domain", scheme: request.SchemeHTTP, host: "githost.io", - domain: nil, + domain: domain.New("githost.io", "", "", &resolver{err: domain.ErrDomainDoesNotExist}), expectedHTTPS: false, expectedHost: "githost.io", expectedProjectID: nil, expectedServingType: nil, + expectedErrMsg: domain.ErrDomainDoesNotExist.Error(), }, } @@ -97,6 +104,7 @@ func TestGetExtraLogFields(t *testing.T) { require.Equal(t, tt.expectedProjectID, got["pages_project_id"]) require.Equal(t, tt.expectedProjectPrefix, got["pages_project_prefix"]) require.Equal(t, tt.expectedServingType, got["pages_project_serving_type"]) + require.Equal(t, tt.expectedErrMsg, got["error"]) }) } } |