Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-cmds
Commits
a661a196
Commit
a661a196
authored
May 25, 2017
by
Jan Winkelmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add/fix tests and formatting
parent
89b520b8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
4 deletions
+103
-4
cli/responseemitter_test.go
cli/responseemitter_test.go
+101
-0
command.go
command.go
+0
-1
http/client.go
http/client.go
+0
-1
legacy_test.go
legacy_test.go
+2
-2
No files found.
cli/responseemitter_test.go
0 → 100644
View file @
a661a196
package
cli
import
(
"bytes"
//"io"
"testing"
"github.com/ipfs/go-ipfs-cmds"
"gx/ipfs/QmWdiBLZ22juGtuNceNbvvHV11zKzCaoQFMP76x2w1XDFZ/go-ipfs-cmdkit"
)
type
writeCloser
struct
{
*
bytes
.
Buffer
}
func
(
wc
writeCloser
)
Close
()
error
{
return
nil
}
type
tcSetError
struct
{
stdout
,
stderr
*
bytes
.
Buffer
exStdout
,
exStderr
string
exExit
int
f
func
(
re
ResponseEmitter
,
t
*
testing
.
T
)
}
func
(
tc
tcSetError
)
Run
(
t
*
testing
.
T
)
{
req
,
err
:=
cmds
.
NewEmptyRequest
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
cmdsre
,
exitCh
:=
NewResponseEmitter
(
tc
.
stdout
,
tc
.
stderr
,
nil
,
req
)
re
:=
cmdsre
.
(
ResponseEmitter
)
go
tc
.
f
(
re
,
t
)
if
exitCode
:=
<-
exitCh
;
exitCode
!=
tc
.
exExit
{
t
.
Fatalf
(
"expected exit code %d, got %d"
,
tc
.
exExit
,
exitCode
)
}
if
tc
.
stdout
.
String
()
!=
tc
.
exStdout
{
t
.
Fatalf
(
`expected stdout string "%s" but got "%s"`
,
tc
.
exStdout
,
tc
.
stdout
.
String
())
}
if
tc
.
stderr
.
String
()
!=
tc
.
exStderr
{
t
.
Fatalf
(
`expected stderr string "%s" but got "%s"`
,
tc
.
exStderr
,
tc
.
stderr
.
String
())
}
t
.
Logf
(
"stdout:
\n
---
\n
%s---
\n
"
,
tc
.
stdout
.
Bytes
())
t
.
Logf
(
"stderr:
\n
---
\n
%s---
\n
"
,
tc
.
stderr
.
Bytes
())
}
func
TestSetError
(
t
*
testing
.
T
)
{
tcs
:=
[]
tcSetError
{
tcSetError
{
stdout
:
bytes
.
NewBuffer
(
nil
),
stderr
:
bytes
.
NewBuffer
(
nil
),
exStdout
:
"a
\n
"
,
exStderr
:
"Error: some error
\n
"
,
exExit
:
1
,
f
:
func
(
re
ResponseEmitter
,
t
*
testing
.
T
)
{
re
.
Emit
(
"a"
)
re
.
SetError
(
"some error"
,
cmdsutil
.
ErrFatal
)
re
.
Emit
(
"b"
)
},
},
tcSetError
{
stdout
:
bytes
.
NewBuffer
(
nil
),
stderr
:
bytes
.
NewBuffer
(
nil
),
exStdout
:
"a
\n
b
\n
"
,
exStderr
:
"Error: some error
\n
"
,
exExit
:
1
,
f
:
func
(
re
ResponseEmitter
,
t
*
testing
.
T
)
{
defer
re
.
Close
()
re
.
Emit
(
"a"
)
re
.
SetError
(
"some error"
,
cmdsutil
.
ErrNormal
)
re
.
Emit
(
"b"
)
},
},
tcSetError
{
stdout
:
bytes
.
NewBuffer
(
nil
),
stderr
:
bytes
.
NewBuffer
(
nil
),
exStdout
:
"a
\n
b
\n
"
,
exStderr
:
"Error: some error
\n
"
,
exExit
:
3
,
f
:
func
(
re
ResponseEmitter
,
t
*
testing
.
T
)
{
re
.
Emit
(
"a"
)
re
.
SetError
(
"some error"
,
cmdsutil
.
ErrNormal
)
re
.
Emit
(
"b"
)
re
.
Exit
(
3
)
},
},
}
for
i
,
tc
:=
range
tcs
{
t
.
Log
(
i
)
tc
.
Run
(
t
)
}
}
command.go
View file @
a661a196
...
...
@@ -71,7 +71,6 @@ var ErrIncorrectType = errors.New("The command returned a value with a different
// Call invokes the command for the given Request
func
(
c
*
Command
)
Call
(
req
Request
,
re
ResponseEmitter
)
(
err
error
)
{
// we need the named return parameter so we can change the value from defer()
defer
re
.
Close
()
cmd
,
err
:=
c
.
Get
(
req
.
Path
())
...
...
http/client.go
View file @
a661a196
...
...
@@ -41,7 +41,6 @@ func NewClient(address string) Client {
}
func
(
c
*
client
)
Send
(
req
cmds
.
Request
)
(
cmds
.
Response
,
error
)
{
if
req
.
Context
()
==
nil
{
log
.
Warningf
(
"no context set in request"
)
if
err
:=
req
.
SetRootContext
(
context
.
TODO
());
err
!=
nil
{
...
...
legacy_test.go
View file @
a661a196
...
...
@@ -141,11 +141,11 @@ func TestPipePair(t *testing.T) {
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
str
,
ok
:=
v
.
(
string
)
str
,
ok
:=
v
.
(
*
string
)
if
!
ok
{
t
.
Fatalf
(
"expected type %T but got %T"
,
expect
,
v
)
}
if
str
!=
expect
{
if
*
str
!=
expect
{
t
.
Fatalf
(
"expected value %#v but got %#v"
,
expect
,
v
)
}
...
...
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