From df98c3685323d296d44e8f8f12d7478d056565ca Mon Sep 17 00:00:00 2001 From: Hunter Long Date: Sun, 19 Aug 2018 16:51:56 -0700 Subject: [PATCH] docker cypress testing image --- .gitignore | 6 ++++-- Makefile | 20 ++++++++++---------- core/services_test.go | 6 +++--- dev/Dockerfile-cypress | 18 ++++++++++++++++++ dev/Dockerfile-test | 23 ----------------------- dev/test/package.json | 1 + dev/test/test-docker.sh | 5 +++++ handlers/routes.go | 4 ---- handlers/setup.go | 5 ++++- 9 files changed, 45 insertions(+), 43 deletions(-) create mode 100644 dev/Dockerfile-cypress delete mode 100644 dev/Dockerfile-test create mode 100755 dev/test/test-docker.sh diff --git a/.gitignore b/.gitignore index 323a4ffb..ae61a010 100644 --- a/.gitignore +++ b/.gitignore @@ -14,9 +14,11 @@ assets *.log .env logs -dev/test/node_modules +/dev/test/node_modules dev/test/cypress/videos dev/test/cypress/screenshots dev/test/app source/rice-box.go -sass \ No newline at end of file +sass +.DS_Store +source/css/base.css.map diff --git a/Makefile b/Makefile index d475eb76..f5f135ed 100644 --- a/Makefile +++ b/Makefile @@ -83,10 +83,10 @@ docker-push-latest: docker docker-run-dev: docker-dev docker run -t -p 8080:8080 hunterlong/statup:dev -docker-test: docker-dev clean - docker build -t hunterlong/statup:test -f dev/Dockerfile-test . +docker-cypress: clean + docker build -t hunterlong/statup:test -f dev/Dockerfile-cypress . -docker-run-test: docker-test +docker-run-cypress: docker-cypress docker run -t -p 8080:8080 --entrypoint "go test -v -p=1 $(BUILDVERSION) ./..." hunterlong/statup:test docker-base: clean @@ -124,13 +124,13 @@ dev-deps: dep clean: rm -rf ./{logs,assets,plugins,statup.db,config.yml,.sass-cache,config.yml,statup,build} - rm -rf cmd/{logs,assets,plugins,statup.db,config.yml,.sass-cache} - rm -rf core/{logs,assets,plugins,statup.db,config.yml,.sass-cache} - rm -rf handlers/{logs,assets,plugins,statup.db,config.yml,.sass-cache} - rm -rf notifiers/{logs,assets,plugins,statup.db,config.yml,.sass-cache} - rm -rf source/{logs,assets,plugins,statup.db,config.yml,.sass-cache} - rm -rf types/{logs,assets,plugins,statup.db,config.yml,.sass-cache} - rm -rf utils/{logs,assets,plugins,statup.db,config.yml,.sass-cache} + rm -rf cmd/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log} + rm -rf core/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log} + rm -rf handlers/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log} + rm -rf notifiers/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log} + rm -rf source/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log} + rm -rf types/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log} + rm -rf utils/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log} rm -rf dev/test/cypress/videos rm -rf .sass-cache rm -f coverage.out diff --git a/core/services_test.go b/core/services_test.go index c16e7c0b..d06216e0 100644 --- a/core/services_test.go +++ b/core/services_test.go @@ -146,7 +146,7 @@ func TestCountOnline(t *testing.T) { } func TestCreateService(t *testing.T) { - s := &Service{Service: &types.Service{ + s := &Service{&types.Service{ Name: "That'll do 🐢", Domain: "https://www.youtube.com/watch?v=rjQtzV9IZ0Q", ExpectedStatus: 200, @@ -170,7 +170,7 @@ func TestViewNewService(t *testing.T) { } func TestCreateFailingHTTPService(t *testing.T) { - s := &Service{Service: &types.Service{ + s := &Service{&types.Service{ Name: "Bad URL", Domain: "http://localhost/iamnothere", ExpectedStatus: 200, @@ -195,7 +195,7 @@ func TestServiceFailedCheck(t *testing.T) { } func TestCreateFailingTCPService(t *testing.T) { - s := &Service{Service: &types.Service{ + s := &Service{&types.Service{ Name: "Bad TCP", Domain: "localhost", Port: 5050, diff --git a/dev/Dockerfile-cypress b/dev/Dockerfile-cypress new file mode 100644 index 00000000..46ef9b47 --- /dev/null +++ b/dev/Dockerfile-cypress @@ -0,0 +1,18 @@ +FROM cypress/browsers:chrome67 +MAINTAINER "Hunter Long (https://github.com/hunterlong)" +# Statup 'test' image for running a full test using the production environment + +WORKDIR $HOME/statup +ADD dev/test . + +ENV VERSION=v0.46 + +RUN wget -q https://github.com/hunterlong/statup/releases/download/$VERSION/statup-linux-alpine.tar.gz && \ + tar -xvzf statup-linux-alpine.tar.gz && \ + chmod +x statup && \ + mv statup /usr/local/bin/statup + +RUN npm install node-sass +ENV SASS=node-sass +RUN npm install +RUN npm run test-docker \ No newline at end of file diff --git a/dev/Dockerfile-test b/dev/Dockerfile-test deleted file mode 100644 index edc8b087..00000000 --- a/dev/Dockerfile-test +++ /dev/null @@ -1,23 +0,0 @@ -FROM golang:1.10.3-alpine -MAINTAINER "Hunter Long (https://github.com/hunterlong)" -# Statup 'test' image for running a full test using the production environment - -RUN apk add --no-cache libstdc++ gcc g++ make git ca-certificates linux-headers wget curl - -RUN curl -L -s https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 -o /go/bin/dep && \ - chmod +x /go/bin/dep - -RUN curl -L -s https://assets.statup.io/sass -o /usr/local/bin/sass && \ - chmod +x /usr/local/bin/sass - -WORKDIR /go/src/github.com/hunterlong/statup -ADD . /go/src/github.com/hunterlong/statup - -ENV VERSION=$(VERSION) -ENV IS_DOCKER=true - -RUN make dev-deps -RUN make install - -EXPOSE 8080 -ENTRYPOINT make test \ No newline at end of file diff --git a/dev/test/package.json b/dev/test/package.json index 07f64e9f..e08cb7ef 100644 --- a/dev/test/package.json +++ b/dev/test/package.json @@ -14,6 +14,7 @@ "cy:run-video": "cypress run --record --key $CYPRESS_KEY", "cy:run": "cypress run", "test": "bash -c \"./test.sh\"", + "test-docker": "bash -c \"./test-docker.sh\"", "testnovid": "cypress run", "open": "cypress open" }, diff --git a/dev/test/test-docker.sh b/dev/test/test-docker.sh new file mode 100755 index 00000000..7296e230 --- /dev/null +++ b/dev/test/test-docker.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +statup > /dev/null & + +./node_modules/.bin/start-server-and-test start http://localhost:8080/robots.txt cy:run \ No newline at end of file diff --git a/handlers/routes.go b/handlers/routes.go index 01154d8e..f0cc48eb 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -23,7 +23,6 @@ import ( "github.com/hunterlong/statup/source" "github.com/hunterlong/statup/utils" "net/http" - "os" "time" ) @@ -89,9 +88,6 @@ func Router() *mux.Router { r.Handle("/api/users", http.HandlerFunc(ApiAllUsersHandler)) r.Handle("/api/users/{id}", http.HandlerFunc(ApiUserHandler)) r.Handle("/metrics", http.HandlerFunc(PrometheusHandler)) - if os.Getenv("GO_ENV") == "test" { - r.Handle("/reset", http.HandlerFunc(ResetDbHandler)) - } r.NotFoundHandler = http.HandlerFunc(Error404Handler) return r } diff --git a/handlers/setup.go b/handlers/setup.go index 505f329d..b5a1e59a 100644 --- a/handlers/setup.go +++ b/handlers/setup.go @@ -16,6 +16,7 @@ package handlers import ( + "fmt" "github.com/hunterlong/statup/core" "github.com/hunterlong/statup/types" "github.com/hunterlong/statup/utils" @@ -88,9 +89,11 @@ func ProcessSetupHandler(w http.ResponseWriter, r *http.Request) { Password: password, Email: email, Error: nil, - Location: ".", + Location: utils.Directory, }} + fmt.Println(config) + err := config.Save() if err != nil { utils.Log(4, err)