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:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2019-12-04 12:56:15 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2019-12-04 12:58:22 +0300
commit061955ee870d483751cd8cef42e6bd694d98d033 (patch)
treed9761c505628f16b1d572637efe10e09023b50dc
parentc8ce9b3637df9a5493d4febce1b23b1112a0db3c (diff)
Handle non-existent domains properly using 204 status
-rw-r--r--acceptance_test.go25
-rw-r--r--helpers_test.go10
-rw-r--r--internal/source/gitlab/gitlab.go6
3 files changed, 32 insertions, 9 deletions
diff --git a/acceptance_test.go b/acceptance_test.go
index 6f2e5fb4..2598f404 100644
--- a/acceptance_test.go
+++ b/acceptance_test.go
@@ -16,7 +16,6 @@ import (
"time"
"github.com/namsral/flag"
- "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -1535,16 +1534,26 @@ func TestGitlabDomainsSource(t *testing.T) {
source := NewGitlabDomainsSourceStub(t)
defer source.Close()
- newSourceDomains := "GITLAB_NEW_SOURCE_DOMAINS=new-source-test.gitlab.io,other-test.gitlab.io"
+ newSourceDomains := "GITLAB_NEW_SOURCE_DOMAINS=new-source-test.gitlab.io,non-existent-domain.gitlab.io"
teardown := RunPagesProcessWithEnvs(t, true, *pagesBinary, listeners, "", []string{newSourceDomains}, "-gitlab-server", source.URL)
defer teardown()
- response, err := GetPageFromListener(t, httpListener, "new-source-test.gitlab.io", "/my/pages/project/")
- require.NoError(t, err)
+ t.Run("when a domain exists", func(t *testing.T) {
+ response, err := GetPageFromListener(t, httpListener, "new-source-test.gitlab.io", "/my/pages/project/")
+ require.NoError(t, err)
- defer response.Body.Close()
- body, _ := ioutil.ReadAll(response.Body)
+ defer response.Body.Close()
+ body, _ := ioutil.ReadAll(response.Body)
+
+ require.Equal(t, http.StatusOK, response.StatusCode)
+ require.Equal(t, "New Pages GitLab Source TEST OK\n", string(body))
+ })
- assert.Equal(t, http.StatusOK, response.StatusCode)
- assert.Equal(t, "New Pages GitLab Source TEST OK\n", string(body))
+ t.Run("when a domain does not exists", func(t *testing.T) {
+ response, err := GetPageFromListener(t, httpListener, "non-existent-domain.gitlab.io", "/path")
+ defer response.Body.Close()
+ require.NoError(t, err)
+
+ require.Equal(t, http.StatusNotFound, response.StatusCode)
+ })
}
diff --git a/helpers_test.go b/helpers_test.go
index b13fb18f..fc903404 100644
--- a/helpers_test.go
+++ b/helpers_test.go
@@ -385,8 +385,16 @@ func waitForRoundtrips(t *testing.T, listeners []ListenSpec, timeout time.Durati
func NewGitlabDomainsSourceStub(t *testing.T) *httptest.Server {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
domain := r.URL.Query().Get("host")
+ path := "shared/lookups/" + domain + ".json"
- fixture, err := os.Open("shared/lookups/" + domain + ".json")
+ if _, err := os.Stat(path); os.IsNotExist(err) {
+ w.WriteHeader(http.StatusNoContent)
+
+ t.Logf("GitLab domain %s source stub served 204", domain)
+ return
+ }
+
+ fixture, err := os.Open(path)
defer fixture.Close()
require.NoError(t, err)
diff --git a/internal/source/gitlab/gitlab.go b/internal/source/gitlab/gitlab.go
index e62b33a2..44e42f14 100644
--- a/internal/source/gitlab/gitlab.go
+++ b/internal/source/gitlab/gitlab.go
@@ -30,6 +30,12 @@ func New(config client.Config) *Gitlab {
// GitLab
func (g *Gitlab) GetDomain(name string) (*domain.Domain, error) {
lookup := g.client.GetLookup(context.Background(), name)
+
+ // NoContent response means that a domain does not exist
+ if lookup.Status == http.StatusNoContent {
+ return nil, nil
+ }
+
if lookup.Error != nil {
return nil, lookup.Error
}