diff options
-rw-r--r-- | .gitlab-ci.yml | 3 | ||||
-rw-r--r-- | Makefile.util.mk | 4 | ||||
-rw-r--r-- | helpers_test.go | 14 |
3 files changed, 17 insertions, 4 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9b75c6ee..41dfb14d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,7 +5,10 @@ image: golang:1.8 - make setup - make verify - make cover + - echo "Running all tests without daemonizing..." - make test + - echo "Running just the acceptance tests daemonized...." + - TEST_DAEMONIZE=1 make acceptance artifacts: paths: - bin/gitlab-pages diff --git a/Makefile.util.mk b/Makefile.util.mk index 808e2607..ece6e3bb 100644 --- a/Makefile.util.mk +++ b/Makefile.util.mk @@ -14,9 +14,13 @@ lint: bin/golint complexity: .GOPATH/.ok bin/gocyclo $Q ./bin/gocyclo -over 9 $(allfiles) + test: .GOPATH/.ok gitlab-pages go test $(if $V,-v) $(allpackages) +acceptance: .GOPATH/.ok gitlab-pages + go test $(if $V,-v) $(IMPORT_PATH) + bench: .GOPATH/.ok gitlab-pages go test -bench=. -run=^$$ $(allpackages) diff --git a/helpers_test.go b/helpers_test.go index a8d804c2..97374d19 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -9,6 +9,7 @@ import ( "net/http" "os" "os/exec" + "strconv" "strings" "testing" "time" @@ -229,10 +230,15 @@ func getPagesArgs(t *testing.T, listeners []ListenSpec, promPort string, extraAr } // At least one of `-daemon-uid` and `-daemon-gid` must be non-zero - if os.Geteuid() == 0 { - t.Log("Running pages as a daemon") - args = append(args, "-daemon-uid", "0") - args = append(args, "-daemon-gid", "65534") // Root user can switch to "nobody" + if daemon, _ := strconv.ParseBool(os.Getenv("TEST_DAEMONIZE")); daemon { + if os.Geteuid() == 0 { + t.Log("Running pages as a daemon") + args = append(args, "-daemon-uid", "0") + args = append(args, "-daemon-gid", "65534") // Root user can switch to "nobody" + } else { + t.Log("Privilege-dropping requested but not running as root!") + t.FailNow() + } } args = append(args, extraArgs...) |