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
path: root/test
diff options
context:
space:
mode:
authorJaime Martinez <jmartinez@gitlab.com>2021-01-19 04:02:58 +0300
committerJaime Martinez <jmartinez@gitlab.com>2021-01-28 05:57:44 +0300
commit68f85cf0a7ef48e9667cf84fd736dc20fefcb86b (patch)
tree92eca3c0cddc09cb677173c811ba9fba71d38729 /test
parent8627963a4cf1874e2550889cd687bc30ecdab0c6 (diff)
Add acceptance test
Diffstat (limited to 'test')
-rw-r--r--test/acceptance/helpers_test.go19
-rw-r--r--test/acceptance/serving_test.go65
2 files changed, 74 insertions, 10 deletions
diff --git a/test/acceptance/helpers_test.go b/test/acceptance/helpers_test.go
index aa209240..8d8ca8d6 100644
--- a/test/acceptance/helpers_test.go
+++ b/test/acceptance/helpers_test.go
@@ -594,30 +594,29 @@ func NewGitlabDomainsSourceStub(t *testing.T, opts *stubOpts) *httptest.Server {
return httptest.NewServer(mux)
}
-func newConfigFile(configs ...string) (string, error) {
+func newConfigFile(t *testing.T, configs ...string) string {
+ t.Helper()
+
f, err := ioutil.TempFile(os.TempDir(), "gitlab-pages-config")
- if err != nil {
- return "", err
- }
+ require.NoError(t, err)
defer f.Close()
for _, config := range configs {
_, err := fmt.Fprintf(f, "%s\n", config)
- if err != nil {
- return "", err
- }
+ require.NoError(t, err)
}
- return f.Name(), nil
+ return f.Name()
}
func defaultConfigFileWith(t *testing.T, configs ...string) (string, func()) {
+ t.Helper()
+
configs = append(configs, "auth-client-id=clientID",
"auth-client-secret=clientSecret",
"auth-secret=authSecret")
- name, err := newConfigFile(configs...)
- require.NoError(t, err)
+ name := newConfigFile(t, configs...)
cleanup := func() {
err := os.Remove(name)
diff --git a/test/acceptance/serving_test.go b/test/acceptance/serving_test.go
index 31588046..4157908d 100644
--- a/test/acceptance/serving_test.go
+++ b/test/acceptance/serving_test.go
@@ -6,6 +6,7 @@ import (
"net/http"
"os"
"path"
+ "strings"
"testing"
"time"
@@ -645,3 +646,67 @@ func TestQueryStringPersistedInSlashRewrite(t *testing.T) {
defer rsp.Body.Close()
require.Equal(t, http.StatusOK, rsp.StatusCode)
}
+
+func TestServerRepliesWithHeaders(t *testing.T) {
+ tests := map[string]struct {
+ flags []string
+ expectedHeaders map[string][]string
+ }{
+ "single_header": {
+ flags: []string{"X-testing-1: y-value"},
+ expectedHeaders: http.Header{"X-testing-1": {"y-value"}},
+ },
+ "multiple_header": {
+ flags: []string{"X: 1,2", "Y: 3,4"},
+ expectedHeaders: http.Header{"X": {"1,2"}, "Y": {"3,4"}},
+ },
+ }
+
+ for name, test := range tests {
+ testFn := func(envArgs, headerArgs []string) func(*testing.T) {
+ return func(t *testing.T) {
+ teardown := RunPagesProcessWithEnvs(t, true, *pagesBinary, []ListenSpec{httpListener}, "", envArgs, headerArgs...)
+
+ defer teardown()
+
+ rsp, err := GetPageFromListener(t, httpListener, "group.gitlab-example.com", "/")
+ require.NoError(t, err)
+ defer rsp.Body.Close()
+
+ require.Equal(t, http.StatusOK, rsp.StatusCode)
+
+ for key, value := range test.expectedHeaders {
+ fmt.Printf("expected key: %q - value: %+v\n", key, value)
+ got := rsp.Header.Values(key)
+ fmt.Printf("got key: %q - value: %+v\n", key, got)
+ require.Equal(t, value, got)
+ }
+ }
+ }
+
+ t.Run(name+"/from_single_flag", func(t *testing.T) {
+ args := []string{"-header", strings.Join(test.flags, ";;")}
+ testFn([]string{}, args)
+ })
+
+ t.Run(name+"/from_multiple_flags", func(t *testing.T) {
+ args := make([]string, 0, 2*len(test.flags))
+ for _, arg := range test.flags {
+ args = append(args, "-header", arg)
+ }
+
+ testFn([]string{}, args)
+ })
+
+ t.Run(name+"/from_config_file", func(t *testing.T) {
+ file := newConfigFile(t, "-header="+strings.Join(test.flags, ";;"))
+
+ testFn([]string{}, []string{"-config", file})
+ })
+
+ t.Run(name+"/from_env", func(t *testing.T) {
+ args := []string{"header", strings.Join(test.flags, ";;")}
+ testFn(args, []string{})
+ })
+ }
+}