Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
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
beego
Commits
c16b7be9
Commit
c16b7be9
authored
Aug 18, 2014
by
smallfish
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rollback the ToFile func implement, and add testcase
parent
de875293
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
2 deletions
+26
-2
httplib.go
httplib/httplib.go
+6
-2
httplib_test.go
httplib/httplib_test.go
+20
-0
No files found.
httplib/httplib.go
View file @
c16b7be9
...
...
@@ -421,11 +421,15 @@ func (b *BeegoHttpRequest) ToFile(filename string) error {
}
defer
f
.
Close
()
data
,
err
:=
b
.
Bytes
()
resp
,
err
:=
b
.
getResponse
()
if
err
!=
nil
{
return
err
}
_
,
err
=
f
.
Write
(
data
)
if
resp
.
Body
==
nil
{
return
nil
}
defer
resp
.
Body
.
Close
()
_
,
err
=
io
.
Copy
(
f
,
resp
.
Body
)
return
err
}
...
...
httplib/httplib_test.go
View file @
c16b7be9
...
...
@@ -15,6 +15,8 @@
package
httplib
import
(
"io/ioutil"
"os"
"strings"
"testing"
)
...
...
@@ -41,6 +43,10 @@ func TestGet(t *testing.T) {
t
.
Fatal
(
err
)
}
t
.
Log
(
s
)
if
string
(
b
)
!=
s
{
t
.
Fatal
(
"request data not match"
)
}
}
func
TestSimplePost
(
t
*
testing
.
T
)
{
...
...
@@ -171,3 +177,17 @@ func TestToJson(t *testing.T) {
t
.
Fatal
(
"response is not valid ip"
)
}
}
func
TestToFile
(
t
*
testing
.
T
)
{
f
:=
"beego_testfile"
req
:=
Get
(
"http://httpbin.org/ip"
)
err
:=
req
.
ToFile
(
f
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
os
.
Remove
(
f
)
b
,
err
:=
ioutil
.
ReadFile
(
f
)
if
n
:=
strings
.
Index
(
string
(
b
),
"origin"
);
n
==
-
1
{
t
.
Fatal
(
err
)
}
}
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