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
c9b18b27
Commit
c9b18b27
authored
Nov 12, 2018
by
Cosmin Cojocar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for UpateClient API
parent
6531b256
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
171 additions
and
0 deletions
+171
-0
api_test.go
server/api_test.go
+171
-0
No files found.
server/api_test.go
View file @
c9b18b27
...
...
@@ -290,3 +290,174 @@ func TestRefreshToken(t *testing.T) {
t
.
Fatalf
(
"Refresh token returned inspite of revoking it."
)
}
}
func
TestUpdateClient
(
t
*
testing
.
T
)
{
logger
:=
&
logrus
.
Logger
{
Out
:
os
.
Stderr
,
Formatter
:
&
logrus
.
TextFormatter
{
DisableColors
:
true
},
Level
:
logrus
.
DebugLevel
,
}
s
:=
memory
.
New
(
logger
)
client
:=
newAPI
(
s
,
logger
,
t
)
defer
client
.
Close
()
ctx
:=
context
.
Background
()
createClient
:=
func
(
t
*
testing
.
T
,
clientId
string
)
{
resp
,
err
:=
client
.
CreateClient
(
ctx
,
&
api
.
CreateClientReq
{
Client
:
&
api
.
Client
{
Id
:
clientId
,
Secret
:
""
,
RedirectUris
:
[]
string
{},
TrustedPeers
:
nil
,
Public
:
true
,
Name
:
""
,
LogoUrl
:
""
,
},
})
if
err
!=
nil
{
t
.
Fatalf
(
"unable to create the client: %v"
,
err
)
}
if
resp
==
nil
{
t
.
Fatalf
(
"create client returned no response"
)
}
if
resp
.
AlreadyExists
{
t
.
Error
(
"existing client was found"
)
}
if
resp
.
Client
==
nil
{
t
.
Fatalf
(
"no client created"
)
}
}
deleteClient
:=
func
(
t
*
testing
.
T
,
clientId
string
)
{
resp
,
err
:=
client
.
DeleteClient
(
ctx
,
&
api
.
DeleteClientReq
{
Id
:
clientId
,
})
if
err
!=
nil
{
t
.
Fatalf
(
"unable to delete the client: %v"
,
err
)
}
if
resp
==
nil
{
t
.
Fatalf
(
"delete client delete client returned no response"
)
}
}
tests
:=
map
[
string
]
struct
{
setup
func
(
t
*
testing
.
T
,
clientId
string
)
cleanup
func
(
t
*
testing
.
T
,
clientId
string
)
req
*
api
.
UpdateClientReq
wantErr
bool
want
*
api
.
UpdateClientResp
}{
"update client"
:
{
setup
:
createClient
,
cleanup
:
deleteClient
,
req
:
&
api
.
UpdateClientReq
{
Id
:
"test"
,
RedirectUris
:
[]
string
{
"https://redirect"
},
TrustedPeers
:
[]
string
{
"test"
},
Public
:
true
,
Name
:
"test"
,
LogoUrl
:
"https://logout"
,
},
wantErr
:
false
,
want
:
&
api
.
UpdateClientResp
{
NotFound
:
false
,
},
},
"update client without ID"
:
{
setup
:
createClient
,
cleanup
:
deleteClient
,
req
:
&
api
.
UpdateClientReq
{
Id
:
""
,
RedirectUris
:
nil
,
TrustedPeers
:
nil
,
Public
:
false
,
Name
:
"test"
,
LogoUrl
:
"test"
,
},
wantErr
:
true
,
want
:
&
api
.
UpdateClientResp
{
NotFound
:
false
,
},
},
"update client which not exists "
:
{
req
:
&
api
.
UpdateClientReq
{
Id
:
"test"
,
RedirectUris
:
nil
,
TrustedPeers
:
nil
,
Public
:
false
,
Name
:
"test"
,
LogoUrl
:
"test"
,
},
wantErr
:
true
,
want
:
&
api
.
UpdateClientResp
{
NotFound
:
false
,
},
},
}
for
name
,
tc
:=
range
tests
{
t
.
Run
(
name
,
func
(
t
*
testing
.
T
)
{
if
tc
.
setup
!=
nil
{
tc
.
setup
(
t
,
tc
.
req
.
Id
)
}
resp
,
err
:=
client
.
UpdateClient
(
ctx
,
tc
.
req
)
if
err
!=
nil
&&
!
tc
.
wantErr
{
t
.
Fatalf
(
"failed to update the client: %v"
,
err
)
}
if
!
tc
.
wantErr
{
if
resp
==
nil
{
t
.
Fatalf
(
"update client response not found"
)
}
if
tc
.
want
.
NotFound
!=
resp
.
NotFound
{
t
.
Errorf
(
"expected in response NotFound: %t"
,
tc
.
want
.
NotFound
)
}
client
,
err
:=
s
.
GetClient
(
tc
.
req
.
Id
)
if
err
!=
nil
{
t
.
Errorf
(
"no client found in the storage: %v"
,
err
)
}
if
tc
.
req
.
Id
!=
client
.
ID
{
t
.
Errorf
(
"expected stored client with ID: %s, found %s"
,
tc
.
req
.
Id
,
client
.
ID
)
}
if
tc
.
req
.
Name
!=
client
.
Name
{
t
.
Errorf
(
"expected stored client with Name: %s, found %s"
,
tc
.
req
.
Name
,
client
.
Name
)
}
if
tc
.
req
.
LogoUrl
!=
client
.
LogoURL
{
t
.
Errorf
(
"expected stored client with LogoURL: %s, found %s"
,
tc
.
req
.
LogoUrl
,
client
.
LogoURL
)
}
for
_
,
redirectURI
:=
range
tc
.
req
.
RedirectUris
{
found
:=
find
(
redirectURI
,
client
.
RedirectURIs
)
if
!
found
{
t
.
Errorf
(
"expected redirect URI: %s"
,
redirectURI
)
}
}
for
_
,
peer
:=
range
tc
.
req
.
TrustedPeers
{
found
:=
find
(
peer
,
client
.
TrustedPeers
)
if
!
found
{
t
.
Errorf
(
"expected trusted peer: %s"
,
peer
)
}
}
}
if
tc
.
cleanup
!=
nil
{
tc
.
cleanup
(
t
,
tc
.
req
.
Id
)
}
})
}
}
func
find
(
item
string
,
items
[]
string
)
bool
{
for
_
,
i
:=
range
items
{
if
item
==
i
{
return
true
}
}
return
false
}
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