Add TestLogin regression test

This commit is contained in:
Andrea Fazzi 2020-02-07 09:56:08 +01:00
parent aca7db4d14
commit 9a193fcf32
5 changed files with 88 additions and 7 deletions

View file

@ -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

View file

@ -1,4 +1,5 @@
PHONY: all .PHONY: all
.PHONY: regression_test
prod: prod:
docker-compose -f docker/oef_prod/docker-compose.yml down 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 & go run -race main.go --config=docker/oef_test/config/config.yaml &
regression_test: 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 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 all: prod

View file

@ -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"

View file

@ -3,7 +3,9 @@ version: "3.3"
services: services:
app: app:
build: ../../ build:
context: ../../
dockerfile: Dockerfile.regression_test
container_name: "oef_regression_test" container_name: "oef_regression_test"
ports: ports:
- 3000:3000 - 3000:3000
@ -12,7 +14,7 @@ services:
- DB_PORT=3306 - DB_PORT=3306
volumes: volumes:
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
- ../../config/config_regression_test.yaml:/src/oef/config/config.yaml - ./config.yaml:/src/oef/config/config.yaml
db: db:
image: mariadb image: mariadb

View file

@ -3,6 +3,7 @@ package regression_test
import ( import (
"fmt" "fmt"
"testing" "testing"
"time"
"github.com/remogatto/prettytest" "github.com/remogatto/prettytest"
"github.com/tebeka/selenium" "github.com/tebeka/selenium"
@ -37,6 +38,8 @@ func (t *testSuite) BeforeAll() {
panic(err) panic(err)
} }
wd.SetImplicitWaitTimeout(time.Second * 5)
// Navigate to the simple playground interface. // Navigate to the simple playground interface.
if err = wd.Get("http://oef_regression_test:3000"); err != nil { if err = wd.Get("http://oef_regression_test:3000"); err != nil {
panic(err) panic(err)
@ -49,15 +52,44 @@ func (t *testSuite) AfterAll() {
} }
func (t *testSuite) TestLogin() { func (t *testSuite) TestLogin() {
paragraph, err := wd.FindElement(selenium.ByCSSSelector, "h1.karmen-title") err := findElement("#username").SendKeys("admin")
if err != nil { if err != nil {
panic(err) panic(err)
} }
text, err := paragraph.Text() err = findElement("#password").SendKeys("admin")
if err != nil { if err != nil {
panic(err) 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
} }