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
fccfcc8e
Commit
fccfcc8e
authored
Feb 08, 2016
by
Adam Reese
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13 from adamreese/dm-tests
test(dm): add unit tests for dm client
parents
692a27bb
fd7e9b96
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
20 deletions
+62
-20
Makefile
Makefile
+1
-1
helm.go
cmd/helm/helm.go
+10
-0
list.go
cmd/helm/list.go
+8
-2
client.go
dm/client.go
+5
-17
client_test.go
dm/client_test.go
+38
-0
No files found.
Makefile
View file @
fccfcc8e
...
@@ -47,7 +47,7 @@ quicktest:
...
@@ -47,7 +47,7 @@ quicktest:
$(PATH_WITH_HELM)
go
test
-short
$
(
addprefix ./,
$(GO_PACKAGES)
)
$(PATH_WITH_HELM)
go
test
-short
$
(
addprefix ./,
$(GO_PACKAGES)
)
test
:
test-style
test
:
test-style
$(PATH_WITH_HELM)
go
test
-v
$
(
addprefix ./,
$(GO_PACKAGES)
)
$(PATH_WITH_HELM)
go
test
-v
-cover
$
(
addprefix ./,
$(GO_PACKAGES)
)
test-style
:
test-style
:
@
if
[
$(
shell
gofmt
-e
-l
-s
*
.go
$(GO_PACKAGES))
]
;
then
\
@
if
[
$(
shell
gofmt
-e
-l
-s
*
.go
$(GO_PACKAGES))
]
;
then
\
...
...
cmd/helm/helm.go
View file @
fccfcc8e
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
)
)
var
version
=
"0.0.1"
var
version
=
"0.0.1"
var
isDebugging
bool
func
main
()
{
func
main
()
{
app
:=
cli
.
NewApp
()
app
:=
cli
.
NewApp
()
...
@@ -24,6 +25,15 @@ func main() {
...
@@ -24,6 +25,15 @@ func main() {
EnvVar
:
"HELM_HOST"
,
EnvVar
:
"HELM_HOST"
,
Value
:
"https://localhost:8181/FIXME_NOT_RIGHT"
,
Value
:
"https://localhost:8181/FIXME_NOT_RIGHT"
,
},
},
cli
.
BoolFlag
{
Name
:
"debug"
,
Usage
:
"Enable verbose debugging output"
,
},
}
app
.
Before
=
func
(
ctx
*
cli
.
Context
)
error
{
isDebugging
=
ctx
.
Bool
(
"debug"
)
return
nil
}
}
app
.
Run
(
os
.
Args
)
app
.
Run
(
os
.
Args
)
...
...
cmd/helm/list.go
View file @
fccfcc8e
package
main
package
main
import
(
import
(
"fmt"
"os"
"os"
"github.com/codegangsta/cli"
"github.com/codegangsta/cli"
...
@@ -22,6 +23,11 @@ func listCmd() cli.Command {
...
@@ -22,6 +23,11 @@ func listCmd() cli.Command {
}
}
func
list
(
host
string
)
error
{
func
list
(
host
string
)
error
{
client
:=
dm
.
NewClient
(
host
)
.
SetDebug
(
true
)
client
:=
dm
.
NewClient
(
host
)
.
SetDebug
(
isDebugging
)
return
client
.
ListDeployments
()
list
,
err
:=
client
.
ListDeployments
()
if
err
!=
nil
{
return
err
}
fmt
.
Println
(
list
)
return
nil
}
}
dm/client.go
View file @
fccfcc8e
...
@@ -11,8 +11,6 @@ import (
...
@@ -11,8 +11,6 @@ import (
"path/filepath"
"path/filepath"
"strings"
"strings"
"time"
"time"
"github.com/ghodss/yaml"
)
)
// The default HTTP timeout
// The default HTTP timeout
...
@@ -94,15 +92,6 @@ func (c *Client) CallService(path, method, action string, dest interface{}, read
...
@@ -94,15 +92,6 @@ func (c *Client) CallService(path, method, action string, dest interface{}, read
if
err
:=
json
.
Unmarshal
([]
byte
(
resp
),
dest
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
([]
byte
(
resp
),
dest
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to parse JSON response from service: %s"
,
resp
)
return
fmt
.
Errorf
(
"Failed to parse JSON response from service: %s"
,
resp
)
}
}
// From here down is just printing the data.
y
,
err
:=
yaml
.
Marshal
(
dest
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to serialize JSON response from service: %s"
,
resp
)
}
fmt
.
Println
(
string
(
y
))
return
nil
return
nil
}
}
...
@@ -137,14 +126,13 @@ func (c *Client) callHTTP(path, method, action string, reader io.ReadCloser) (st
...
@@ -137,14 +126,13 @@ func (c *Client) callHTTP(path, method, action string, reader io.ReadCloser) (st
}
}
// ListDeployments lists the deployments in DM.
// ListDeployments lists the deployments in DM.
func
(
c
*
Client
)
ListDeployments
()
error
{
func
(
c
*
Client
)
ListDeployments
()
([]
string
,
error
)
{
var
d
interface
{}
var
l
[]
string
if
err
:=
c
.
CallService
(
"deployments"
,
"GET"
,
"foo"
,
&
d
,
nil
);
err
!=
nil
{
if
err
:=
c
.
CallService
(
"deployments"
,
"GET"
,
"foo"
,
&
l
,
nil
);
err
!=
nil
{
return
err
return
nil
,
err
}
}
fmt
.
Printf
(
"%#v
\n
"
,
d
)
return
l
,
nil
return
nil
}
}
// DeployChart sends a chart to DM for deploying.
// DeployChart sends a chart to DM for deploying.
...
...
dm/client_test.go
View file @
fccfcc8e
package
dm
package
dm
import
(
import
(
"net/http"
"net/http/httptest"
"testing"
"testing"
)
)
...
@@ -58,3 +60,39 @@ func TestURL(t *testing.T) {
...
@@ -58,3 +60,39 @@ func TestURL(t *testing.T) {
}
}
}
}
}
}
type
fakeClient
struct
{
*
Client
server
*
httptest
.
Server
handler
http
.
HandlerFunc
response
[]
byte
}
func
(
c
*
fakeClient
)
setup
()
*
fakeClient
{
c
.
handler
=
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
Write
(
c
.
response
)
})
c
.
server
=
httptest
.
NewServer
(
c
.
handler
)
c
.
Client
=
NewClient
(
c
.
server
.
URL
)
return
c
}
func
(
c
*
fakeClient
)
teardown
()
{
c
.
server
.
Close
()
}
func
TestListDeployments
(
t
*
testing
.
T
)
{
fc
:=
&
fakeClient
{
response
:
[]
byte
(
`["guestbook.yaml"]`
),
}
defer
fc
.
teardown
()
l
,
err
:=
fc
.
setup
()
.
ListDeployments
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
l
)
!=
1
{
t
.
Fatal
(
"expected a single deployment"
)
}
}
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