Skip to content

Commit

Permalink
all: Replaces internal dockertest with sqlcon
Browse files Browse the repository at this point in the history
  • Loading branch information
arekkas committed May 17, 2018
1 parent 246e491 commit 5cbf121
Show file tree
Hide file tree
Showing 24 changed files with 1,462 additions and 1,313 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

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

1 change: 0 additions & 1 deletion client/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ type swaggerUpdateClientPayload struct {

// swagger:parameters listOAuth2Clients
type swaggerListClientsParameter struct {

// The maximum amount of policies returned.
// in: query
Limit int `json:"limit"`
Expand Down
35 changes: 20 additions & 15 deletions client/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ import (
"flag"
"fmt"
"log"
"os"
"testing"

"github.com/ory/fosite"
. "github.com/ory/hydra/client"
"github.com/ory/hydra/integration"
"github.com/ory/sqlcon/dockertest"
)

var clientManagers = map[string]Manager{}
Expand All @@ -39,37 +38,43 @@ func init() {
}

func TestMain(m *testing.M) {
runner := dockertest.Register()

flag.Parse()
if !testing.Short() {
if !testing.Short() {
integration.BootParallel([]func(){
connectToPG,
connectToMySQL,
})
}
dockertest.Parallel([]func(){
connectToPG,
connectToMySQL,
})
}

s := m.Run()
integration.KillAll()
os.Exit(s)
runner.Exit(m.Run())
}

func connectToMySQL() {
var db = integration.ConnectToMySQL()
db, err := dockertest.ConnectToTestMySQL()
if err != nil {
log.Fatalf("Could not connect to database: %v", err)
}

s := &SQLManager{DB: db, Hasher: &fosite.BCrypt{WorkFactor: 4}}
if _, err := s.CreateSchemas(); err != nil {
log.Fatalf("Could not create postgres schema: %v", err)
log.Fatalf("Could not create schema: %v", err)
}

clientManagers["mysql"] = s
}

func connectToPG() {
var db = integration.ConnectToPostgres()
db, err := dockertest.ConnectToTestPostgreSQL()
if err != nil {
log.Fatalf("Could not connect to database: %v", err)
}

s := &SQLManager{DB: db, Hasher: &fosite.BCrypt{WorkFactor: 4}}

if _, err := s.CreateSchemas(); err != nil {
log.Fatalf("Could not create postgres schema: %v", err)
log.Fatalf("Could not create schema: %v", err)
}

clientManagers["postgres"] = s
Expand Down
5 changes: 2 additions & 3 deletions cmd/cli/handler_introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ import (
//"context"
//"encoding/json"
"fmt"
"net/http"
"strings"

"github.com/ory/hydra/config"
//"github.com/ory/hydra/oauth2"

"net/http"
"strings"

hydra "github.com/ory/hydra/sdk/go/hydra/swagger"
"github.com/spf13/cobra"
)
Expand Down
1 change: 0 additions & 1 deletion cmd/cli/handler_jwk.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package cli
import (
"crypto/tls"
"fmt"

"net/http"

"github.com/ory/hydra/config"
Expand Down
20 changes: 14 additions & 6 deletions cmd/cli/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,33 @@ package cli

import (
"flag"
"os"
"log"
"testing"

"github.com/jmoiron/sqlx"
"github.com/ory/hydra/config"
"github.com/ory/hydra/integration"
"github.com/ory/sqlcon/dockertest"
)

var db *sqlx.DB

func TestMain(m *testing.M) {
runner := dockertest.Register()

flag.Parse()
if !testing.Short() {
db = integration.ConnectToPostgres()
dockertest.Parallel([]func(){
func() {
var err error
db, err = dockertest.ConnectToTestPostgreSQL()
if err != nil {
log.Fatalf("Unable to connect to database: %s", err)
}
},
})
}

code := m.Run()
integration.KillAll()
os.Exit(code)
runner.Exit(m.Run())
}

func TestNewHandler(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion cmd/server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"net/http"
"net/url"
"os"

"strconv"
"strings"

Expand Down
3 changes: 2 additions & 1 deletion cmd/server/handler_client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/ory/herodot"
"github.com/ory/hydra/client"
"github.com/ory/hydra/config"
"github.com/ory/sqlcon"
)

func newClientManager(c *config.Config) client.Manager {
Expand All @@ -33,7 +34,7 @@ func newClientManager(c *config.Config) client.Manager {
switch con := ctx.Connection.(type) {
case *config.MemoryConnection:
return client.NewMemoryManager(ctx.Hasher)
case *config.SQLConnection:
case *sqlcon.SQLConnection:
return &client.SQLManager{
DB: con.GetDatabase(),
Hasher: ctx.Hasher,
Expand Down
3 changes: 2 additions & 1 deletion cmd/server/handler_consent_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/ory/hydra/client"
"github.com/ory/hydra/config"
"github.com/ory/hydra/consent"
"github.com/ory/sqlcon"
)

func injectConsentManager(c *config.Config, cm client.Manager) {
Expand All @@ -36,7 +37,7 @@ func injectConsentManager(c *config.Config, cm client.Manager) {
case *config.MemoryConnection:
manager = consent.NewMemoryManager()
break
case *config.SQLConnection:
case *sqlcon.SQLConnection:
manager = consent.NewSQLManager(
con.GetDatabase(),
cm,
Expand Down
3 changes: 2 additions & 1 deletion cmd/server/handler_jwk_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/ory/herodot"
"github.com/ory/hydra/config"
"github.com/ory/hydra/jwk"
"github.com/ory/sqlcon"
)

func injectJWKManager(c *config.Config) {
Expand All @@ -34,7 +35,7 @@ func injectJWKManager(c *config.Config) {
case *config.MemoryConnection:
ctx.KeyManager = &jwk.MemoryManager{}
break
case *config.SQLConnection:
case *sqlcon.SQLConnection:
ctx.KeyManager = &jwk.SQLManager{
DB: con.GetDatabase(),
Cipher: &jwk.AEAD{
Expand Down
3 changes: 2 additions & 1 deletion cmd/server/handler_oauth2_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/ory/hydra/jwk"
"github.com/ory/hydra/oauth2"
"github.com/ory/hydra/pkg"
"github.com/ory/sqlcon"
)

func injectFositeStore(c *config.Config, clients client.Manager) {
Expand All @@ -46,7 +47,7 @@ func injectFositeStore(c *config.Config, clients client.Manager) {
case *config.MemoryConnection:
store = oauth2.NewFositeMemoryStore(clients, c.GetAccessTokenLifespan())
break
case *config.SQLConnection:
case *sqlcon.SQLConnection:
store = oauth2.NewFositeSQLStore(clients, con.GetDatabase(), c.GetLogger(), c.GetAccessTokenLifespan())
break
case *config.PluginConnection:
Expand Down
128 changes: 0 additions & 128 deletions config/backend_sql.go

This file was deleted.

Loading

0 comments on commit 5cbf121

Please sign in to comment.