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

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaime Martinez <jmartinez@gitlab.com>2020-11-16 09:20:43 +0300
committerJaime Martinez <jmartinez@gitlab.com>2021-01-14 02:44:13 +0300
commitf2d6fa65a7e3cefab6e35a7807b5f95f4981cedb (patch)
tree5bdcea2314ed89168f9e075431e81bdfd68445f9 /internal/logging
parentf6f10835059cecf92602f57b8dbb1fc1ca07d7c8 (diff)
Refactor domain package
Refactor domain package to handle errors from resolver.
Diffstat (limited to 'internal/logging')
-rw-r--r--internal/logging/logging.go6
-rw-r--r--internal/logging/logging_test.go21
2 files changed, 16 insertions, 11 deletions
diff --git a/internal/logging/logging.go b/internal/logging/logging.go
index 9a3629ff..9ac3c863 100644
--- a/internal/logging/logging.go
+++ b/internal/logging/logging.go
@@ -4,6 +4,7 @@ import (
"net/http"
"github.com/sirupsen/logrus"
+
"gitlab.com/gitlab-org/labkit/log"
"gitlab.com/gitlab-org/gitlab-pages/internal/request"
@@ -59,10 +60,13 @@ func getExtraLogFields(r *http.Request) log.Fields {
}
if d := request.GetDomain(r); d != nil {
- if lp := d.GetLookupPath(r); lp != nil {
+ lp, err := d.GetLookupPath(r)
+ if lp != nil {
logFields["pages_project_serving_type"] = lp.ServingType
logFields["pages_project_prefix"] = lp.Prefix
logFields["pages_project_id"] = lp.ProjectID
+ } else if err != nil {
+ logFields["error"] = err.Error()
}
}
diff --git a/internal/logging/logging_test.go b/internal/logging/logging_test.go
index e87a8c0d..2ed2b6ec 100644
--- a/internal/logging/logging_test.go
+++ b/internal/logging/logging_test.go
@@ -18,15 +18,13 @@ func (f lookupPathFunc) Resolve(r *http.Request) (*serving.Request, error) {
}
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("", "", "", lookupPathFunc(func(*http.Request) *serving.LookupPath {
+ return &serving.LookupPath{
+ ServingType: "file",
+ ProjectID: 100,
+ Prefix: "/prefix",
+ }
+ }))
tests := []struct {
name string
@@ -38,6 +36,7 @@ func TestGetExtraLogFields(t *testing.T) {
expectedProjectID interface{}
expectedProjectPrefix interface{}
expectedServingType interface{}
+ expectedErrMsg interface{}
}{
{
name: "https",
@@ -62,7 +61,7 @@ func TestGetExtraLogFields(t *testing.T) {
expectedServingType: "file",
},
{
- name: "domain_without_resolved",
+ name: "domain_without_resolver",
scheme: request.SchemeHTTP,
host: "githost.io",
domain: &domain.Domain{},
@@ -70,6 +69,7 @@ func TestGetExtraLogFields(t *testing.T) {
expectedHost: "githost.io",
expectedProjectID: nil,
expectedServingType: nil,
+ expectedErrMsg: "not configured",
},
{
name: "no_domain",
@@ -97,6 +97,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"])
})
}
}