Skip to content

Commit

Permalink
all: resolve test issues with memory adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeneas Rekkas (arekkas) authored and arekkas committed May 7, 2017
1 parent af52e68 commit 2c3c8e3
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 91 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ glide install
go test $(glide novendor)
```

Then run it without Database:
Then run it with in-memory database:

```
go run main.go host
DATABASE_URL=memory go run main.go host
```

## Sponsors
Expand Down
4 changes: 0 additions & 4 deletions client/manager_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package client_test

import (
r "gopkg.in/gorethink/gorethink.v3"
"log"
"net/http/httptest"
"net/url"
Expand All @@ -18,10 +17,7 @@ import (
"github.com/ory-am/hydra/integration"
"github.com/ory-am/hydra/pkg"
"github.com/ory/ladon"
"github.com/pborman/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"context"
"gopkg.in/ory-am/dockertest.v3"
)

Expand Down
1 change: 1 addition & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func init() {
func TestExecute(t *testing.T) {
var osArgs = make([]string, len(os.Args))
var path = filepath.Join(os.TempDir(), fmt.Sprintf("hydra-%s.yml", uuid.New()))
os.Setenv("DATABASE_URL", "memory")
copy(osArgs, os.Args)

for _, c := range []struct {
Expand Down
20 changes: 0 additions & 20 deletions cmd/server/handler_client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"github.com/ory-am/hydra/client"
"github.com/ory-am/hydra/config"
"github.com/ory/herodot"
"context"
r "gopkg.in/gorethink/gorethink.v3"
)

func newClientManager(c *config.Config) client.Manager {
Expand All @@ -28,24 +26,6 @@ func newClientManager(c *config.Config) client.Manager {
logrus.Fatalf("Could not create client schema: %s", err)
}
return m
case *config.RethinkDBConnection:
con.CreateTableIfNotExists("hydra_clients")
m := &client.RethinkManager{
Session: con.GetSession(),
Table: r.Table("hydra_clients"),
Hasher: ctx.Hasher,
}
if err := m.ColdStart(); err != nil {
logrus.Fatalf("Could not fetch initial state: %s", err)
}
m.Watch(context.Background())
return m
case *config.RedisConnection:
m := &client.RedisManager{
DB: con.RedisSession(),
Hasher: ctx.Hasher,
}
return m
default:
panic("Unknown connection type.")
}
Expand Down
28 changes: 0 additions & 28 deletions cmd/server/handler_jwk_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import (
"github.com/ory-am/hydra/config"
"github.com/ory/herodot"
"github.com/ory-am/hydra/jwk"
"github.com/square/go-jose"
"context"
r "gopkg.in/gorethink/gorethink.v3"
)

func injectJWKManager(c *config.Config) {
Expand All @@ -30,31 +27,6 @@ func injectJWKManager(c *config.Config) {
}
ctx.KeyManager = m
break
case *config.RethinkDBConnection:
con.CreateTableIfNotExists("hydra_json_web_keys")
m := &jwk.RethinkManager{
Session: con.GetSession(),
Keys: map[string]jose.JsonWebKeySet{},
Table: r.Table("hydra_json_web_keys"),
Cipher: &jwk.AEAD{
Key: c.GetSystemSecret(),
},
}
if err := m.ColdStart(); err != nil {
logrus.Fatalf("Could not fetch initial state: %s", err)
}
m.Watch(context.Background())
ctx.KeyManager = m
break
case *config.RedisConnection:
m := &jwk.RedisManager{
DB: con.RedisSession(),
Cipher: &jwk.AEAD{
Key: c.GetSystemSecret(),
},
}
ctx.KeyManager = m
break
default:
logrus.Fatalf("Unknown connection type.")
}
Expand Down
34 changes: 0 additions & 34 deletions cmd/server/handler_oauth2_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package server
import (
"fmt"
"net/url"

"github.com/Sirupsen/logrus"
"github.com/gorilla/sessions"
"github.com/julienschmidt/httprouter"
Expand All @@ -16,8 +15,6 @@ import (
"github.com/ory-am/hydra/oauth2"
"github.com/ory-am/hydra/pkg"
"github.com/pkg/errors"
"context"
r "gopkg.in/gorethink/gorethink.v3"
)

func injectFositeStore(c *config.Config, clients client.Manager) {
Expand All @@ -44,37 +41,6 @@ func injectFositeStore(c *config.Config, clients client.Manager) {
}
store = m
break
case *config.RethinkDBConnection:
con.CreateTableIfNotExists("hydra_oauth2_authorize_code")
con.CreateTableIfNotExists("hydra_oauth2_id_sessions")
con.CreateTableIfNotExists("hydra_oauth2_access_token")
con.CreateTableIfNotExists("hydra_oauth2_implicit")
con.CreateTableIfNotExists("hydra_oauth2_refresh_token")
m := &oauth2.FositeRethinkDBStore{
Session: con.GetSession(),
Manager: clients,
AuthorizeCodesTable: r.Table("hydra_oauth2_authorize_code"),
IDSessionsTable: r.Table("hydra_oauth2_id_sessions"),
AccessTokensTable: r.Table("hydra_oauth2_access_token"),
RefreshTokensTable: r.Table("hydra_oauth2_refresh_token"),
AuthorizeCodes: make(oauth2.RDBItems),
IDSessions: make(oauth2.RDBItems),
AccessTokens: make(oauth2.RDBItems),
RefreshTokens: make(oauth2.RDBItems),
}
if err := m.ColdStart(); err != nil {
logrus.Fatalf("Could not fetch initial state: %s", err)
}
m.Watch(context.Background())
store = m
break
case *config.RedisConnection:
m := &oauth2.FositeRedisStore{
DB: con.RedisSession(),
Manager: clients,
}
store = m
break
default:
panic("Unknown connection type.")
}
Expand Down
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (c *Config) Context() *Context {
}

var connection interface{} = &MemoryConnection{}
if c.DatabaseURL != "" {
if c.DatabaseURL == "" {
logrus.Fatalf(`DATABASE_URL is not set, use "export DATABASE_URL=memory" for an in memory storage or the documented database adapters.`)
} else if c.DatabaseURL != "memory" {
u, err := url.Parse(c.DatabaseURL)
Expand All @@ -180,7 +180,7 @@ func (c *Config) Context() *Context {
connection = &SQLConnection{URL: u}
break
default:
logrus.Fatalf("Unkown DSN %s in DATABASE_URL: %s", u.Scheme, c.DatabaseURL)
logrus.Fatalf(`Unkown DSN "%s" in DATABASE_URL: %s`, u.Scheme, c.DatabaseURL)
}
}

Expand Down
4 changes: 3 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
)

func TestConfig(t *testing.T) {
c := &Config{}
c := &Config{
DatabaseURL: "memory",
}
_ = c.Context()

assert.Equal(t, c.GetAccessTokenLifespan(), time.Hour)
Expand Down

0 comments on commit 2c3c8e3

Please sign in to comment.