Skip to content

Commit

Permalink
tests: resolve issue with postgresql connectivity
Browse files Browse the repository at this point in the history
  • Loading branch information
arekkas committed Oct 25, 2017
1 parent faf9c2c commit 61c82a3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
docker:
- image: circleci/golang:1.9
environment:
- TEST_DATABASE_POSTGRES=postgres://test:test@localhost:5432/hydra?sslmode=disable
- TEST_DATABASE_POSTGRESQL=postgres://test:test@localhost:5432/hydra?sslmode=disable
- TEST_DATABASE_MYSQL=root:test@(localhost:3306)/mysql?parseTime=true
- image: postgres:9.5
environment:
- POSTGRES_USER=test
- POSTGRES_PASSWORD=test
- POSTGRES_DB=oathkeeper
- POSTGRES_DB=hydra
- image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=test
Expand All @@ -35,8 +35,8 @@ jobs:
- run: go get -u github.com/mattn/goveralls golang.org/x/tools/cmd/cover github.com/ory/go-acc
- run: dep ensure -vendor-only
- run: go install github.com/ory/hydra
- run: go test -race -short $(go list ./... | grep -v cmd)
- run: go-acc -o coverage.txt ./...
- run: go test -race -short $(go list ./... | grep -v cmd)
- run: ./scripts/test-e2e.sh
- run: goveralls -service=circle-ci -coverprofile=coverage.txt -repotoken=$COVERALLS_REPO_TOKEN

Expand Down
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

[[constraint]]
name = "github.com/ory/ladon"
version = "0.8.2"
version = "0.8.3"

[[constraint]]
name = "github.com/pborman/uuid"
Expand Down
25 changes: 23 additions & 2 deletions config/backend_sql_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"flag"
"fmt"
"log"
"net/url"
Expand All @@ -9,9 +10,9 @@ import (
"testing"
"time"

"flag"

_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
"github.com/ory/dockertest"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -125,6 +126,16 @@ func killAll() {
}

func bootstrapMySQL() *url.URL {
if uu := os.Getenv("TEST_DATABASE_MYSQL"); uu != "" {
log.Println("Found mysql test database config, skipping dockertest...")
_, err := sqlx.Open("postgres", uu)
if err != nil {
log.Fatalf("Could not connect to bootstrapped database: %s", err)
}
u, _ := url.Parse("mysql://" + uu)
return u
}

var db *sqlx.DB
var err error
var urls string
Expand Down Expand Up @@ -160,6 +171,16 @@ func bootstrapMySQL() *url.URL {
}

func bootstrapPostgres() *url.URL {
if uu := os.Getenv("TEST_DATABASE_POSTGRESQL"); uu != "" {
log.Println("Found postgresql test database config, skipping dockertest...")
_, err := sqlx.Open("postgres", uu)
if err != nil {
log.Fatalf("Could not connect to bootstrapped database: %s", err)
}
u, _ := url.Parse(uu)
return u
}

var db *sqlx.DB
var err error
var urls string
Expand Down
2 changes: 2 additions & 0 deletions integration/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func KillAll() {

func ConnectToMySQL() *sqlx.DB {
if url := os.Getenv("TEST_DATABASE_MYSQL"); url != "" {
log.Println("Found mysql test database config, skipping dockertest...")
db, err := sqlx.Open("mysql", url)
if err != nil {
log.Fatalf("Could not connect to bootstrapped database: %s", err)
Expand Down Expand Up @@ -65,6 +66,7 @@ func ConnectToMySQL() *sqlx.DB {

func ConnectToPostgres() *sqlx.DB {
if url := os.Getenv("TEST_DATABASE_POSTGRESQL"); url != "" {
log.Println("Found postgresql test database config, skipping dockertest...")
db, err := sqlx.Open("postgres", url)
if err != nil {
log.Fatalf("Could not connect to bootstrapped database: %s", err)
Expand Down
12 changes: 6 additions & 6 deletions integration/sql_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestSQLSchema(t *testing.T) {
crm := oauth2.NewConsentRequestSQLManager(db)
pm := lsql.NewSQLManager(db, nil)

_, err := pm.CreateSchemas("", "hydra_ladon_migration")
_, err := pm.CreateSchemas("", "hydra_policy_migration")
require.NoError(t, err)
_, err = cm.CreateSchemas()
require.NoError(t, err)
Expand All @@ -47,13 +47,13 @@ func TestSQLSchema(t *testing.T) {
_, err = crm.CreateSchemas()
require.NoError(t, err)

require.NoError(t, jm.AddKey("foo", jwk.First(p1)))
require.NoError(t, pm.Create(&ladon.DefaultPolicy{ID: "foo"}))
require.NoError(t, cm.CreateClient(&client.Client{ID: "foo"}))
require.NoError(t, crm.PersistConsentRequest(&oauth2.ConsentRequest{ID: "foo"}))
require.NoError(t, jm.AddKey("integration-test-foo", jwk.First(p1)))
require.NoError(t, pm.Create(&ladon.DefaultPolicy{ID: "integration-test-foo", Resources: []string{"foo"}, Actions: []string{"bar"}, Subjects: []string{"baz"}, Effect: "allow"}))
require.NoError(t, cm.CreateClient(&client.Client{ID: "integration-test-foo"}))
require.NoError(t, crm.PersistConsentRequest(&oauth2.ConsentRequest{ID: "integration-test-foo"}))
require.NoError(t, om.CreateAccessTokenSession(nil, "asdfasdf", r))
require.NoError(t, gm.CreateGroup(&group.Group{
ID: "asdfas",
ID: "integration-test-asdfas",
Members: []string{"asdf"},
}))
}

0 comments on commit 61c82a3

Please sign in to comment.