Skip to content

Commit

Permalink
Add circleci configuration file (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
arekkas authored Oct 21, 2017
1 parent 1e4fc77 commit 76e58f2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 11 deletions.
46 changes: 46 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Golang CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2
jobs:
build:
docker:
- image: circleci/golang:1.9
environment:
- PG_URL=postgres://test:test@localhost:5432/oathkeeper?sslmode=disable
- image: postgres:9.5
environment:
- POSTGRES_USER=test
- POSTGRES_PASSWORD=test
- POSTGRES_DB=oathkeeper

working_directory: /go/src/github.com/ory/oathkeeper
steps:
- checkout
- setup_remote_docker
- run: go get -u github.com/go-swagger/go-swagger/cmd/swagger github.com/bradfitz/goimports github.com/mattn/goveralls golang.org/x/tools/cmd/cover github.com/Masterminds/glide github.com/ory/go-acc

# Installation
- run: glide install
- run: go install github.com/ory/oathkeeper
- run: glide update
- run: go install github.com/ory/oathkeeper

# Format
- run: ./scripts/test-format.sh

# Tests
- run: go-acc -o coverage.txt $(glide novendor)
- run: go test -race -short $(glide novendor | grep -v cmd)

# See if swagger works
- run: ./scripts/run-genswag.sh

# Build and test dockerfiles
- run: docker build -t oathkeeper-proxy-travis-ci -f Dockerfile-proxy .
- run: docker build -t oathkeeper-management-travis-ci -f Dockerfile-management .
- run: docker run -d oathkeeper-proxy-travis-ci
- run: docker run -d oathkeeper-management-travis-ci

# Submit coverage details
- run: goveralls -service=circle-ci -coverprofile=coverage.txt -repotoken=$COVERALLS_REPO_TOKEN
31 changes: 20 additions & 11 deletions rule/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

var resources []*dockertest.Resource
var pool *dockertest.Pool
var pool = new(dockertest.Pool)

func kjillAll() {
for _, resource := range resources {
Expand Down Expand Up @@ -121,28 +121,37 @@ func connectToPostgres(t *testing.T, managers map[string]Manager) {
func connectToPostgresDB(t *testing.T) *sqlx.DB {
var db *sqlx.DB
var err error
pool, err = dockertest.NewPool("")
if err != nil {
t.Fatalf("Could not connect to docker: %s", err)
}
var resource *dockertest.Resource

url := os.Getenv("PG_URL")
if url == "" {
pool, err = dockertest.NewPool("")
if err != nil {
t.Fatalf("Could not connect to docker: %s", err)
}

resource, err := pool.Run("postgres", "9.6", []string{"POSTGRES_PASSWORD=secret", "POSTGRES_DB=oathkeeper"})
if err != nil {
t.Fatalf("Could not start resource: %s", err)
resource, err = pool.Run("postgres", "9.6", []string{"POSTGRES_PASSWORD=secret", "POSTGRES_DB=oathkeeper"})
if err != nil {
t.Fatalf("Could not start resource: %s", err)
}

url = fmt.Sprintf("postgres://postgres:secret@localhost:%s/oathkeeper?sslmode=disable", resource.GetPort("5432/tcp"))
resources = append(resources, resource)
}

if err = pool.Retry(func() error {
var err error
db, err = sqlx.Open("postgres", fmt.Sprintf("postgres://postgres:secret@localhost:%s/oathkeeper?sslmode=disable", resource.GetPort("5432/tcp")))
db, err = sqlx.Open("postgres", url)
if err != nil {
return err
}
return db.Ping()
}); err != nil {
pool.Purge(resource)
if resource != nil {
pool.Purge(resource)
}
t.Fatalf("Could not connect to docker: %s", err)
}

resources = append(resources, resource)
return db
}

0 comments on commit 76e58f2

Please sign in to comment.