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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
52 deletions
+46
-52
deployment_test.go
cmd/helm/deployment_test.go
+14
-31
helm_test.go
cmd/helm/helm_test.go
+32
-21
No files found.
cmd/helm/deployment_test.go
View file @
92031722
...
...
@@ -24,10 +24,10 @@ import (
"github.com/kubernetes/helm/pkg/common"
)
func
Test
Show
Deployment
(
t
*
testing
.
T
)
{
func
TestDeployment
(
t
*
testing
.
T
)
{
var
deploymentTestCases
=
[]
struct
{
args
[]
string
resp
*
common
.
Deployment
resp
interface
{}
expected
string
}{
{
...
...
@@ -48,43 +48,26 @@ func TestShowDeployment(t *testing.T) {
},
"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
{
th
:=
setup
(
)
th
:=
testHelm
(
t
)
th
.
mux
.
HandleFunc
(
"/deployments/"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
data
,
err
:=
json
.
Marshal
(
tc
.
resp
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
th
.
must
(
err
)
w
.
Write
(
data
)
})
actual
:=
CaptureOutput
(
func
()
{
th
.
Run
(
tc
.
args
...
)
})
if
tc
.
expected
!=
actual
{
t
.
Errorf
(
"Expected %v got %v"
,
tc
.
expected
,
actual
)
}
th
.
teardown
()
}
}
func
TestListDeployment
(
t
*
testing
.
T
)
{
th
:=
setup
()
defer
th
.
teardown
()
th
.
mux
.
HandleFunc
(
"/deployments"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
Write
([]
byte
(
`["guestbook.yaml"]`
))
})
expected
:=
"guestbook.yaml
\n
"
th
.
run
(
tc
.
args
...
)
actual
:=
CaptureOutput
(
func
()
{
th
.
Run
(
"deployment"
,
"list"
)
})
if
expected
!=
actual
{
t
.
Errorf
(
"Expected %v got %v"
,
expected
,
actual
)
if
tc
.
expected
!=
th
.
output
{
t
.
Errorf
(
"Expected %v got %v"
,
tc
.
expected
,
th
.
output
)
}
th
.
cleanup
()
}
}
cmd/helm/helm_test.go
View file @
92031722
...
...
@@ -27,15 +27,16 @@ import (
"github.com/kubernetes/helm/pkg/format"
)
type
testHelm
struct
{
type
testHelm
Data
struct
{
t
*
testing
.
T
mux
*
http
.
ServeMux
server
*
httptest
.
Server
app
*
cli
.
App
output
string
}
func
setup
()
*
testHelm
{
th
:=
&
testHelm
{
}
func
testHelm
(
t
*
testing
.
T
)
*
testHelmData
{
th
:=
&
testHelm
Data
{
t
:
t
}
th
.
app
=
cli
.
NewApp
()
th
.
app
.
Commands
=
commands
...
...
@@ -64,39 +65,49 @@ func setup() *testHelm {
return
th
}
func
(
th
*
testHelm
)
teardown
()
{
func
(
th
*
testHelm
Data
)
cleanup
()
{
th
.
server
.
Close
()
}
func
(
th
*
testHelm
)
URL
()
string
{
func
(
th
*
testHelm
Data
)
URL
()
string
{
return
th
.
server
.
URL
}
func
(
th
*
testHelm
)
Run
(
args
...
string
)
{
// must gives a fatal error if err is not nil.
func
(
th
*
testHelmData
)
must
(
err
error
)
{
if
err
!=
nil
{
th
.
t
.
Fatal
(
err
)
}
}
// check gives a test non-fatal error if err is not nil.
func
(
th
*
testHelmData
)
check
(
err
error
)
{
if
err
!=
nil
{
th
.
t
.
Error
(
err
)
}
}
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
{
logStderr
:=
format
.
Stderr
logStdout
:=
format
.
Stdout
osStdout
:=
os
.
Stdout
osStderr
:=
os
.
Stderr
// 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
()
{
format
.
Stderr
=
logStderr
format
.
Stdout
=
logStdout
os
.
Stdout
=
osStdout
os
.
Stderr
=
osStderr
os
.
Stdout
,
os
.
Stderr
=
osStdout
,
osStderr
format
.
Stdout
,
format
.
Stderr
=
logStdout
,
logStderr
}()
r
,
w
,
_
:=
os
.
Pipe
()
format
.
Stderr
=
w
format
.
Stdout
=
w
os
.
Stdout
=
w
os
.
Stderr
=
w
os
.
Stdout
,
os
.
Stderr
=
w
,
w
format
.
Stdout
,
format
.
Stderr
=
w
,
w
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