Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dex
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hdacloud
dex
Commits
d27f5e41
Commit
d27f5e41
authored
8 years ago
by
Eric Chiang
Browse files
Options
Downloads
Patches
Plain Diff
storage/conformance: add garbage collection tests
parent
df6cfa0b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
storage/conformance/conformance.go
+97
-7
97 additions, 7 deletions
storage/conformance/conformance.go
with
97 additions
and
7 deletions
storage/conformance/conformance.go
+
97
−
7
View file @
d27f5e41
...
@@ -18,12 +18,10 @@ import (
...
@@ -18,12 +18,10 @@ import (
// ensure that values being tested on never expire.
// ensure that values being tested on never expire.
var
neverExpire
=
time
.
Now
()
.
UTC
()
.
Add
(
time
.
Hour
*
24
*
365
*
100
)
var
neverExpire
=
time
.
Now
()
.
UTC
()
.
Add
(
time
.
Hour
*
24
*
365
*
100
)
// StorageFactory is a method for creating a new storage. The returned storage sould be initialized
// RunTests runs a set of conformance tests against a storage. newStorage should
// but shouldn't have any existing data in it.
// return an initialized but empty storage. The storage will be closed at the
type
StorageFactory
func
()
storage
.
Storage
// end of each test run.
func
RunTests
(
t
*
testing
.
T
,
newStorage
func
()
storage
.
Storage
)
{
// RunTestSuite runs a set of conformance tests against a storage.
func
RunTestSuite
(
t
*
testing
.
T
,
sf
StorageFactory
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
name
string
run
func
(
t
*
testing
.
T
,
s
storage
.
Storage
)
run
func
(
t
*
testing
.
T
,
s
storage
.
Storage
)
...
@@ -33,10 +31,13 @@ func RunTestSuite(t *testing.T, sf StorageFactory) {
...
@@ -33,10 +31,13 @@ func RunTestSuite(t *testing.T, sf StorageFactory) {
{
"ClientCRUD"
,
testClientCRUD
},
{
"ClientCRUD"
,
testClientCRUD
},
{
"RefreshTokenCRUD"
,
testRefreshTokenCRUD
},
{
"RefreshTokenCRUD"
,
testRefreshTokenCRUD
},
{
"PasswordCRUD"
,
testPasswordCRUD
},
{
"PasswordCRUD"
,
testPasswordCRUD
},
{
"GarbageCollection"
,
testGC
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
test
.
run
(
t
,
sf
())
s
:=
newStorage
()
test
.
run
(
t
,
s
)
s
.
Close
()
})
})
}
}
}
}
...
@@ -276,3 +277,92 @@ func testPasswordCRUD(t *testing.T, s storage.Storage) {
...
@@ -276,3 +277,92 @@ func testPasswordCRUD(t *testing.T, s storage.Storage) {
t
.
Errorf
(
"after deleting password expected storage.ErrNotFound, got %v"
,
err
)
t
.
Errorf
(
"after deleting password expected storage.ErrNotFound, got %v"
,
err
)
}
}
}
}
func
testGC
(
t
*
testing
.
T
,
s
storage
.
Storage
)
{
n
:=
time
.
Now
()
c
:=
storage
.
AuthCode
{
ID
:
storage
.
NewID
(),
ClientID
:
"foobar"
,
RedirectURI
:
"https://localhost:80/callback"
,
Nonce
:
"foobar"
,
Scopes
:
[]
string
{
"openid"
,
"email"
},
Expiry
:
n
.
Add
(
time
.
Second
),
ConnectorID
:
"ldap"
,
ConnectorData
:
[]
byte
(
`{"some":"data"}`
),
Claims
:
storage
.
Claims
{
UserID
:
"1"
,
Username
:
"jane"
,
Email
:
"jane.doe@example.com"
,
EmailVerified
:
true
,
Groups
:
[]
string
{
"a"
,
"b"
},
},
}
if
err
:=
s
.
CreateAuthCode
(
c
);
err
!=
nil
{
t
.
Fatalf
(
"failed creating auth code: %v"
,
err
)
}
if
_
,
err
:=
s
.
GarbageCollect
(
n
);
err
!=
nil
{
t
.
Errorf
(
"garbage collection failed: %v"
,
err
)
}
if
_
,
err
:=
s
.
GetAuthCode
(
c
.
ID
);
err
!=
nil
{
t
.
Errorf
(
"expected to be able to get auth code after GC: %v"
,
err
)
}
if
r
,
err
:=
s
.
GarbageCollect
(
n
.
Add
(
time
.
Minute
));
err
!=
nil
{
t
.
Errorf
(
"garbage collection failed: %v"
,
err
)
}
else
if
r
.
AuthCodes
!=
1
{
t
.
Errorf
(
"expected to garbage collect 1 objects, got %d"
,
r
.
AuthCodes
)
}
if
_
,
err
:=
s
.
GetAuthCode
(
c
.
ID
);
err
==
nil
{
t
.
Errorf
(
"expected auth code to be GC'd"
)
}
else
if
err
!=
storage
.
ErrNotFound
{
t
.
Errorf
(
"expected storage.ErrNotFound, got %v"
,
err
)
}
a
:=
storage
.
AuthRequest
{
ID
:
storage
.
NewID
(),
ClientID
:
"foobar"
,
ResponseTypes
:
[]
string
{
"code"
},
Scopes
:
[]
string
{
"openid"
,
"email"
},
RedirectURI
:
"https://localhost:80/callback"
,
Nonce
:
"foo"
,
State
:
"bar"
,
ForceApprovalPrompt
:
true
,
LoggedIn
:
true
,
Expiry
:
n
,
ConnectorID
:
"ldap"
,
ConnectorData
:
[]
byte
(
`{"some":"data"}`
),
Claims
:
storage
.
Claims
{
UserID
:
"1"
,
Username
:
"jane"
,
Email
:
"jane.doe@example.com"
,
EmailVerified
:
true
,
Groups
:
[]
string
{
"a"
,
"b"
},
},
}
if
err
:=
s
.
CreateAuthRequest
(
a
);
err
!=
nil
{
t
.
Fatalf
(
"failed creating auth request: %v"
,
err
)
}
if
_
,
err
:=
s
.
GarbageCollect
(
n
);
err
!=
nil
{
t
.
Errorf
(
"garbage collection failed: %v"
,
err
)
}
if
_
,
err
:=
s
.
GetAuthRequest
(
a
.
ID
);
err
!=
nil
{
t
.
Errorf
(
"expected to be able to get auth code after GC: %v"
,
err
)
}
if
r
,
err
:=
s
.
GarbageCollect
(
n
.
Add
(
time
.
Minute
));
err
!=
nil
{
t
.
Errorf
(
"garbage collection failed: %v"
,
err
)
}
else
if
r
.
AuthRequests
!=
1
{
t
.
Errorf
(
"expected to garbage collect 1 objects, got %d"
,
r
.
AuthRequests
)
}
if
_
,
err
:=
s
.
GetAuthRequest
(
a
.
ID
);
err
==
nil
{
t
.
Errorf
(
"expected auth code to be GC'd"
)
}
else
if
err
!=
storage
.
ErrNotFound
{
t
.
Errorf
(
"expected storage.ErrNotFound, got %v"
,
err
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment