Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
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
helm3
Commits
e1efff4b
Commit
e1efff4b
authored
Mar 25, 2016
by
Matt Butcher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(manager): add test for listDeploymentsRequestHandler
parent
d3975520
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
3 deletions
+43
-3
deployments_test.go
cmd/manager/deployments_test.go
+28
-0
testutil.go
cmd/manager/testutil.go
+15
-3
No files found.
cmd/manager/deployments_test.go
View file @
e1efff4b
...
@@ -76,3 +76,31 @@ func TestCreateDeployments(t *testing.T) {
...
@@ -76,3 +76,31 @@ func TestCreateDeployments(t *testing.T) {
t
.
Errorf
(
"Expected status %d, got %d"
,
http
.
StatusCreated
,
res
.
StatusCode
)
t
.
Errorf
(
"Expected status %d, got %d"
,
http
.
StatusCreated
,
res
.
StatusCode
)
}
}
}
}
func
TestListDeployments
(
t
*
testing
.
T
)
{
c
:=
stubContext
()
s
:=
httpHarness
(
c
,
"GET /deployments"
,
listDeploymentsHandlerFunc
)
defer
s
.
Close
()
man
:=
c
.
Manager
.
(
*
mockManager
)
man
.
deployments
=
[]
*
common
.
Deployment
{
&
common
.
Deployment
{
Name
:
"one"
,
State
:
&
common
.
DeploymentState
{
Status
:
common
.
CreatedStatus
}},
&
common
.
Deployment
{
Name
:
"two"
,
State
:
&
common
.
DeploymentState
{
Status
:
common
.
DeployedStatus
}},
}
res
,
err
:=
http
.
Get
(
s
.
URL
+
"/deployments"
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed GET: %s"
,
err
)
}
else
if
res
.
StatusCode
!=
http
.
StatusOK
{
t
.
Errorf
(
"Unexpected status code: %d"
,
res
.
StatusCode
)
}
var
out
[]
string
if
err
:=
json
.
NewDecoder
(
res
.
Body
)
.
Decode
(
&
out
);
err
!=
nil
{
t
.
Errorf
(
"Failed to parse results: %s"
,
err
)
return
}
if
len
(
out
)
!=
2
{
t
.
Errorf
(
"Expected 2 names, got %d"
,
len
(
out
))
}
}
cmd/manager/testutil.go
View file @
e1efff4b
...
@@ -47,16 +47,28 @@ func httpHarness(c *router.Context, route string, fn router.HandlerFunc) *httpte
...
@@ -47,16 +47,28 @@ func httpHarness(c *router.Context, route string, fn router.HandlerFunc) *httpte
func
stubContext
()
*
router
.
Context
{
func
stubContext
()
*
router
.
Context
{
return
&
router
.
Context
{
return
&
router
.
Context
{
Config
:
&
router
.
Config
{},
Config
:
&
router
.
Config
{},
Manager
:
&
mockManager
{}
,
Manager
:
newMockManager
()
,
CredentialProvider
:
repo
.
NewInmemCredentialProvider
(),
CredentialProvider
:
repo
.
NewInmemCredentialProvider
(),
Encoder
:
httputil
.
DefaultEncoder
,
Encoder
:
httputil
.
DefaultEncoder
,
}
}
}
}
type
mockManager
struct
{}
func
newMockManager
()
*
mockManager
{
return
&
mockManager
{
deployments
:
[]
*
common
.
Deployment
{},
}
}
type
mockManager
struct
{
deployments
[]
*
common
.
Deployment
}
func
(
m
*
mockManager
)
ListDeployments
()
([]
common
.
Deployment
,
error
)
{
func
(
m
*
mockManager
)
ListDeployments
()
([]
common
.
Deployment
,
error
)
{
return
[]
common
.
Deployment
{},
nil
d
:=
make
([]
common
.
Deployment
,
len
(
m
.
deployments
))
for
i
,
dd
:=
range
m
.
deployments
{
d
[
i
]
=
*
dd
}
return
d
,
nil
}
}
func
(
m
*
mockManager
)
GetDeployment
(
name
string
)
(
*
common
.
Deployment
,
error
)
{
func
(
m
*
mockManager
)
GetDeployment
(
name
string
)
(
*
common
.
Deployment
,
error
)
{
...
...
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