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
92031722
Commit
92031722
authored
Mar 23, 2016
by
Adam Reese
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test(cli): refactor cli test setup
parent
caa14b19
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
53 deletions
+47
-53
deployment_test.go
cmd/helm/deployment_test.go
+14
-31
helm_test.go
cmd/helm/helm_test.go
+33
-22
No files found.
cmd/helm/deployment_test.go
View file @
92031722
...
@@ -24,10 +24,10 @@ import (
...
@@ -24,10 +24,10 @@ import (
"github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/common"
)
)
func
Test
Show
Deployment
(
t
*
testing
.
T
)
{
func
TestDeployment
(
t
*
testing
.
T
)
{
var
deploymentTestCases
=
[]
struct
{
var
deploymentTestCases
=
[]
struct
{
args
[]
string
args
[]
string
resp
*
common
.
Deployment
resp
interface
{}
expected
string
expected
string
}{
}{
{
{
...
@@ -48,43 +48,26 @@ func TestShowDeployment(t *testing.T) {
...
@@ -48,43 +48,26 @@ func TestShowDeployment(t *testing.T) {
},
},
"Name: guestbook.yaml
\n
Status: Failed
\n
Errors:
\n
error message
\n
"
,
"Name: guestbook.yaml
\n
Status: Failed
\n
Errors:
\n
error message
\n
"
,
},
},
{
[]
string
{
"deployment"
,
"list"
},
[]
string
{
"guestbook.yaml"
},
"guestbook.yaml
\n
"
,
},
}
}
for
_
,
tc
:=
range
deploymentTestCases
{
for
_
,
tc
:=
range
deploymentTestCases
{
th
:=
setup
(
)
th
:=
testHelm
(
t
)
th
.
mux
.
HandleFunc
(
"/deployments/"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
th
.
mux
.
HandleFunc
(
"/deployments/"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
data
,
err
:=
json
.
Marshal
(
tc
.
resp
)
data
,
err
:=
json
.
Marshal
(
tc
.
resp
)
if
err
!=
nil
{
th
.
must
(
err
)
t
.
Fatal
(
err
)
}
w
.
Write
(
data
)
w
.
Write
(
data
)
})
})
actual
:=
CaptureOutput
(
func
()
{
th
.
run
(
tc
.
args
...
)
th
.
Run
(
tc
.
args
...
)
})
if
tc
.
expected
!=
actual
{
t
.
Errorf
(
"Expected %v got %v"
,
tc
.
expected
,
actual
)
}
th
.
teardown
()
}
}
func
TestListDeployment
(
t
*
testing
.
T
)
{
if
tc
.
expected
!=
th
.
output
{
th
:=
setup
()
t
.
Errorf
(
"Expected %v got %v"
,
tc
.
expected
,
th
.
output
)
defer
th
.
teardown
()
}
th
.
cleanup
()
th
.
mux
.
HandleFunc
(
"/deployments"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
Write
([]
byte
(
`["guestbook.yaml"]`
))
})
expected
:=
"guestbook.yaml
\n
"
actual
:=
CaptureOutput
(
func
()
{
th
.
Run
(
"deployment"
,
"list"
)
})
if
expected
!=
actual
{
t
.
Errorf
(
"Expected %v got %v"
,
expected
,
actual
)
}
}
}
}
cmd/helm/helm_test.go
View file @
92031722
...
@@ -27,15 +27,16 @@ import (
...
@@ -27,15 +27,16 @@ import (
"github.com/kubernetes/helm/pkg/format"
"github.com/kubernetes/helm/pkg/format"
)
)
type
testHelm
struct
{
type
testHelm
Data
struct
{
t
*
testing
.
T
t
*
testing
.
T
mux
*
http
.
ServeMux
mux
*
http
.
ServeMux
server
*
httptest
.
Server
server
*
httptest
.
Server
app
*
cli
.
App
app
*
cli
.
App
output
string
}
}
func
setup
()
*
testHelm
{
func
testHelm
(
t
*
testing
.
T
)
*
testHelmData
{
th
:=
&
testHelm
{
}
th
:=
&
testHelm
Data
{
t
:
t
}
th
.
app
=
cli
.
NewApp
()
th
.
app
=
cli
.
NewApp
()
th
.
app
.
Commands
=
commands
th
.
app
.
Commands
=
commands
...
@@ -64,39 +65,49 @@ func setup() *testHelm {
...
@@ -64,39 +65,49 @@ func setup() *testHelm {
return
th
return
th
}
}
func
(
th
*
testHelm
)
teardown
()
{
func
(
th
*
testHelm
Data
)
cleanup
()
{
th
.
server
.
Close
()
th
.
server
.
Close
()
}
}
func
(
th
*
testHelm
)
URL
()
string
{
func
(
th
*
testHelm
Data
)
URL
()
string
{
return
th
.
server
.
URL
return
th
.
server
.
URL
}
}
func
(
th
*
testHelm
)
Run
(
args
...
string
)
{
// must gives a fatal error if err is not nil.
args
=
append
([]
string
{
"helm"
,
"--host"
,
th
.
URL
()},
args
...
)
func
(
th
*
testHelmData
)
must
(
err
error
)
{
th
.
app
.
Run
(
args
)
if
err
!=
nil
{
th
.
t
.
Fatal
(
err
)
}
}
}
// CaptureOutput redirect all log/std streams, capture and replace
// check gives a test non-fatal error if err is not nil.
func
CaptureOutput
(
fn
func
())
string
{
func
(
th
*
testHelmData
)
check
(
err
error
)
{
logStderr
:=
format
.
Stderr
if
err
!=
nil
{
logStdout
:=
format
.
Stdout
th
.
t
.
Error
(
err
)
osStdout
:=
os
.
Stdout
}
osStderr
:=
os
.
Stderr
}
func
(
th
*
testHelmData
)
run
(
args
...
string
)
{
th
.
output
=
""
args
=
append
([]
string
{
"helm"
,
"--host"
,
th
.
URL
()},
args
...
)
th
.
output
=
captureOutput
(
func
()
{
th
.
app
.
Run
(
args
)
})
}
// captureOutput redirect all log/std streams, capture and replace
func
captureOutput
(
fn
func
())
string
{
osStdout
,
osStderr
:=
os
.
Stdout
,
os
.
Stderr
logStdout
,
logStderr
:=
format
.
Stdout
,
format
.
Stderr
defer
func
()
{
defer
func
()
{
format
.
Stderr
=
logStderr
os
.
Stdout
,
os
.
Stderr
=
osStdout
,
osStderr
format
.
Stdout
=
logStdout
format
.
Stdout
,
format
.
Stderr
=
logStdout
,
logStderr
os
.
Stdout
=
osStdout
os
.
Stderr
=
osStderr
}()
}()
r
,
w
,
_
:=
os
.
Pipe
()
r
,
w
,
_
:=
os
.
Pipe
()
format
.
Stderr
=
w
os
.
Stdout
,
os
.
Stderr
=
w
,
w
format
.
Stdout
=
w
format
.
Stdout
,
format
.
Stderr
=
w
,
w
os
.
Stdout
=
w
os
.
Stderr
=
w
fn
()
fn
()
...
...
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