Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
63f56b42
Commit
63f56b42
authored
Sep 18, 2016
by
Eric Chiang
Committed by
Eric Chiang
Oct 03, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage: hook up conformance tests for SQL
parent
e2bf8ceb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
112 additions
and
6 deletions
+112
-6
conformance.go
storage/conformance/conformance.go
+17
-3
storage_test.go
storage/kubernetes/storage_test.go
+5
-1
memory_test.go
storage/memory/memory_test.go
+1
-2
config_test.go
storage/sql/config_test.go
+89
-0
No files found.
storage/conformance/conformance.go
View file @
63f56b42
...
...
@@ -13,10 +13,24 @@ import (
var
neverExpire
=
time
.
Now
()
.
Add
(
time
.
Hour
*
24
*
365
*
100
)
// StorageFactory is a method for creating a new storage. The returned storage sould be initialized
// but shouldn't have any existing data in it.
type
StorageFactory
func
()
storage
.
Storage
// RunTestSuite runs a set of conformance tests against a storage.
func
RunTestSuite
(
t
*
testing
.
T
,
s
storage
.
Storage
)
{
t
.
Run
(
"UpdateAuthRequest"
,
func
(
t
*
testing
.
T
)
{
testUpdateAuthRequest
(
t
,
s
)
})
t
.
Run
(
"CreateRefresh"
,
func
(
t
*
testing
.
T
)
{
testCreateRefresh
(
t
,
s
)
})
func
RunTestSuite
(
t
*
testing
.
T
,
sf
StorageFactory
)
{
tests
:=
[]
struct
{
name
string
run
func
(
t
*
testing
.
T
,
s
storage
.
Storage
)
}{
{
"UpdateAuthRequest"
,
testUpdateAuthRequest
},
{
"CreateRefresh"
,
testCreateRefresh
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
test
.
run
(
t
,
sf
())
})
}
}
func
testUpdateAuthRequest
(
t
*
testing
.
T
,
s
storage
.
Storage
)
{
...
...
storage/kubernetes/storage_test.go
View file @
63f56b42
...
...
@@ -4,6 +4,7 @@ import (
"os"
"testing"
"github.com/coreos/dex/storage"
"github.com/coreos/dex/storage/conformance"
)
...
...
@@ -73,5 +74,8 @@ func TestURLFor(t *testing.T) {
func
TestStorage
(
t
*
testing
.
T
)
{
client
:=
loadClient
(
t
)
conformance
.
RunTestSuite
(
t
,
client
)
conformance
.
RunTestSuite
(
t
,
func
()
storage
.
Storage
{
// TODO(erichiang): Tear down namespaces between each iteration.
return
client
})
}
storage/memory/memory_test.go
View file @
63f56b42
...
...
@@ -7,6 +7,5 @@ import (
)
func
TestStorage
(
t
*
testing
.
T
)
{
s
:=
New
()
conformance
.
RunTestSuite
(
t
,
s
)
conformance
.
RunTestSuite
(
t
,
New
)
}
storage/sql/config_test.go
View file @
63f56b42
package
sql
import
(
"fmt"
"os"
"runtime"
"testing"
"time"
"github.com/coreos/dex/storage"
"github.com/coreos/dex/storage/conformance"
)
func
withTimeout
(
t
time
.
Duration
,
f
func
())
{
c
:=
make
(
chan
struct
{})
defer
close
(
c
)
go
func
()
{
select
{
case
<-
c
:
case
<-
time
.
After
(
t
)
:
// Dump a stack trace of the program. Useful for debugging deadlocks.
buf
:=
make
([]
byte
,
2
<<
20
)
fmt
.
Fprintf
(
os
.
Stderr
,
"%s
\n
"
,
buf
[
:
runtime
.
Stack
(
buf
,
true
)])
panic
(
"test took too long"
)
}
}()
f
()
}
func
cleanDB
(
c
*
conn
)
error
{
_
,
err
:=
c
.
Exec
(
`
delete from client;
delete from auth_request;
delete from auth_code;
delete from refresh_token;
delete from keys;
`
)
return
err
}
func
TestSQLite3
(
t
*
testing
.
T
)
{
newStorage
:=
func
()
storage
.
Storage
{
// NOTE(ericchiang): In memory means we only get one connection at a time. If we
// ever write tests that require using multiple connections, for instance to test
// transactions, we need to move to a file based system.
s
:=
&
SQLite3
{
":memory:"
}
conn
,
err
:=
s
.
open
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
return
conn
}
withTimeout
(
time
.
Second
*
10
,
func
()
{
conformance
.
RunTestSuite
(
t
,
newStorage
)
})
}
func
TestPostgres
(
t
*
testing
.
T
)
{
if
os
.
Getenv
(
"DEX_POSTGRES_HOST"
)
==
""
{
t
.
Skip
(
"postgres envs not set, skipping tests"
)
}
p
:=
Postgres
{
Database
:
os
.
Getenv
(
"DEX_POSTGRES_DATABASE"
),
User
:
os
.
Getenv
(
"DEX_POSTGRES_USER"
),
Password
:
os
.
Getenv
(
"DEX_POSTGRES_PASSWORD"
),
Host
:
os
.
Getenv
(
"DEX_POSTGRES_HOST"
),
SSL
:
PostgresSSL
{
Mode
:
sslDisable
,
// Postgres container doesn't support SSL.
},
ConnectionTimeout
:
5
,
}
conn
,
err
:=
p
.
open
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
conn
.
Close
()
newStorage
:=
func
()
storage
.
Storage
{
if
err
:=
cleanDB
(
conn
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
return
conn
}
withTimeout
(
time
.
Minute
*
1
,
func
()
{
conformance
.
RunTestSuite
(
t
,
newStorage
)
})
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment