Add TestLogin regression test
This commit is contained in:
parent
aca7db4d14
commit
9a193fcf32
5 changed files with 88 additions and 7 deletions
16
Dockerfile.regression_test
Normal file
16
Dockerfile.regression_test
Normal 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
|
6
Makefile
6
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
|
||||
|
|
29
docker/oef_regression_test/config.yaml
Normal file
29
docker/oef_regression_test/config.yaml
Normal 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"
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue