diff --git a/Dockerfile.regression_test b/Dockerfile.regression_test new file mode 100644 index 00000000..a9544446 --- /dev/null +++ b/Dockerfile.regression_test @@ -0,0 +1,16 @@ +FROM golang:latest + +ENV PATH=$PATH:/src/oef/ +RUN mkdir -p /srv/oef + +COPY config/config.yaml /srv/oef/config/ +COPY oef /srv/oef/ +COPY dist /srv/oef/dist +COPY templates /srv/oef/templates +# COPY renderer /srv/oef/renderer + +WORKDIR /srv/oef/ + +ENTRYPOINT ["/srv/oef/oef"] + +EXPOSE 3000 diff --git a/Makefile b/Makefile index 26a30fb8..9391a39f 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ -PHONY: all +.PHONY: all +.PHONY: regression_test prod: docker-compose -f docker/oef_prod/docker-compose.yml down @@ -19,7 +20,8 @@ test: go run -race main.go --config=docker/oef_test/config/config.yaml & regression_test: + go build . docker-compose -f docker/oef_regression_test/docker-compose.yaml down - docker-compose -f docker/oef_regression_test/docker-compose.yaml up -d + docker-compose -f docker/oef_regression_test/docker-compose.yaml up --build -d all: prod diff --git a/docker/oef_regression_test/config.yaml b/docker/oef_regression_test/config.yaml new file mode 100644 index 00000000..c644c8be --- /dev/null +++ b/docker/oef_regression_test/config.yaml @@ -0,0 +1,29 @@ +url: "http://localhost:3000" +log_level: 2 +language: "it" + +keys: + cookie_store_key: "something-very-secret" + jwt_signing_key: "secret" + +orm: + connection: "oef:oef@tcp(db:3306)/oef_test" + options: "charset=utf8&parseTime=True&loc=Local" + automigrate: true + regenerate: false + +admin: + username: "admin" + password: "admin" + +subscriber: + password: "subscribe" + +smtp: + host: "localhost" + port: 1025 + username: "" + password: "" + from: "no-reply@olimpiadi-economiaefinanza.it" + bcc: "bcc@fake.org" + subject: "[OEF2020] - Credenziali di accesso della scuola" diff --git a/docker/oef_regression_test/docker-compose.yaml b/docker/oef_regression_test/docker-compose.yaml index 00caf139..1e57bcab 100644 --- a/docker/oef_regression_test/docker-compose.yaml +++ b/docker/oef_regression_test/docker-compose.yaml @@ -3,7 +3,9 @@ version: "3.3" services: app: - build: ../../ + build: + context: ../../ + dockerfile: Dockerfile.regression_test container_name: "oef_regression_test" ports: - 3000:3000 @@ -12,7 +14,7 @@ services: - DB_PORT=3306 volumes: - /etc/localtime:/etc/localtime:ro - - ../../config/config_regression_test.yaml:/src/oef/config/config.yaml + - ./config.yaml:/src/oef/config/config.yaml db: image: mariadb diff --git a/regression_test/regression_test.go b/regression_test/regression_test.go index 7f0c2667..ed559b0b 100644 --- a/regression_test/regression_test.go +++ b/regression_test/regression_test.go @@ -3,6 +3,7 @@ package regression_test import ( "fmt" "testing" + "time" "github.com/remogatto/prettytest" "github.com/tebeka/selenium" @@ -37,6 +38,8 @@ func (t *testSuite) BeforeAll() { panic(err) } + wd.SetImplicitWaitTimeout(time.Second * 5) + // Navigate to the simple playground interface. if err = wd.Get("http://oef_regression_test:3000"); err != nil { panic(err) @@ -49,15 +52,44 @@ func (t *testSuite) AfterAll() { } func (t *testSuite) TestLogin() { - paragraph, err := wd.FindElement(selenium.ByCSSSelector, "h1.karmen-title") + err := findElement("#username").SendKeys("admin") if err != nil { panic(err) } - text, err := paragraph.Text() + err = findElement("#password").SendKeys("admin") if err != nil { panic(err) } - t.Equal("Olimpiadi", text) + err = findElement("button").Click() + if err != nil { + panic(err) + } + + expected := []string{"JUNIOR Contest", "SENIOR Contest"} + elements := findElements(".list-group a") + for i, el := range elements { + text, err := el.Text() + if err != nil { + panic(err) + } + t.Equal(expected[i], text) + } +} + +func findElement(selector string) selenium.WebElement { + element, err := wd.FindElement(selenium.ByCSSSelector, selector) + if err != nil { + panic(err) + } + return element +} + +func findElements(selector string) []selenium.WebElement { + elements, err := wd.FindElements(selenium.ByCSSSelector, selector) + if err != nil { + panic(err) + } + return elements }