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
82c50b97
Commit
82c50b97
authored
Nov 11, 2015
by
JessonChan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new test file
parent
15b0b9b6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
0 deletions
+71
-0
staticfile_test.go
staticfile_test.go
+71
-0
No files found.
staticfile_test.go
0 → 100644
View file @
82c50b97
package
beego
import
(
"bytes"
"compress/flate"
"compress/gzip"
"io"
"io/ioutil"
"os"
"testing"
)
const
licenseFile
=
"./LICENSE"
func
testOpenFile
(
encoding
string
,
content
[]
byte
,
t
*
testing
.
T
)
{
fi
,
_
:=
os
.
Stat
(
licenseFile
)
b
,
n
,
sch
,
err
:=
openFile
(
licenseFile
,
fi
,
encoding
)
if
err
!=
nil
{
t
.
Log
(
err
)
t
.
Fail
()
}
t
.
Log
(
"open static file encoding "
+
n
,
b
)
assetOpenFileAndContent
(
sch
,
content
,
t
)
}
func
TestOpenStaticFile_1
(
t
*
testing
.
T
)
{
file
,
_
:=
os
.
Open
(
licenseFile
)
content
,
_
:=
ioutil
.
ReadAll
(
file
)
testOpenFile
(
""
,
content
,
t
)
}
func
TestOpenStaticFileGzip_1
(
t
*
testing
.
T
)
{
file
,
_
:=
os
.
Open
(
licenseFile
)
var
zipBuf
bytes
.
Buffer
fileWriter
,
_
:=
gzip
.
NewWriterLevel
(
&
zipBuf
,
gzip
.
BestCompression
)
io
.
Copy
(
fileWriter
,
file
)
fileWriter
.
Close
()
content
,
_
:=
ioutil
.
ReadAll
(
&
zipBuf
)
testOpenFile
(
"gzip"
,
content
,
t
)
}
func
TestOpenStaticFileDeflate_1
(
t
*
testing
.
T
)
{
file
,
_
:=
os
.
Open
(
licenseFile
)
var
zipBuf
bytes
.
Buffer
fileWriter
,
_
:=
flate
.
NewWriter
(
&
zipBuf
,
flate
.
BestCompression
)
io
.
Copy
(
fileWriter
,
file
)
fileWriter
.
Close
()
content
,
_
:=
ioutil
.
ReadAll
(
&
zipBuf
)
testOpenFile
(
"deflate"
,
content
,
t
)
}
func
assetOpenFileAndContent
(
sch
*
serveContentHolder
,
content
[]
byte
,
t
*
testing
.
T
)
{
t
.
Log
(
sch
.
size
,
len
(
content
))
if
sch
.
size
!=
int64
(
len
(
content
))
{
t
.
Log
(
"static content file size not same"
)
t
.
Fail
()
}
bs
,
_
:=
ioutil
.
ReadAll
(
sch
)
for
i
,
v
:=
range
content
{
if
v
!=
bs
[
i
]
{
t
.
Log
(
"content not same"
)
t
.
Fail
()
}
}
if
len
(
staticFileMap
)
==
0
{
t
.
Log
(
"men map is empty"
)
t
.
Fail
()
}
}
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