Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
7ba3cadb
提交
7ba3cadb
authored
11月 08, 2014
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #289 from jbenet/update-random-sharness-tests
Update random for test/
上级
7ee0c6dc
1e434ef3
隐藏空白字符变更
内嵌
并排
正在显示
17 个修改的文件
包含
278 行增加
和
21 行删除
+278
-21
Godeps.json
Godeps/Godeps.json
+4
-0
LICENSE
Godeps/_workspace/src/github.com/jbenet/go-random/LICENSE
+21
-0
README.md
Godeps/_workspace/src/github.com/jbenet/go-random/README.md
+29
-0
lib.go
Godeps/_workspace/src/github.com/jbenet/go-random/lib.go
+47
-0
.gitignore
...rkspace/src/github.com/jbenet/go-random/random/.gitignore
+1
-0
random.go
...orkspace/src/github.com/jbenet/go-random/random/random.go
+47
-0
random_test.go
..._workspace/src/github.com/jbenet/go-random/random_test.go
+96
-0
.gitignore
test/.gitignore
+3
-1
Makefile
test/Makefile
+8
-7
install-sharness.sh
test/lib/install-sharness.sh
+3
-2
random-dep.go
test/lib/random-dep.go
+8
-0
test-aggregate-results.sh
test/lib/test-aggregate-results.sh
+1
-1
test-lib.sh
test/lib/test-lib.sh
+3
-3
t0010-basic-commands.sh
test/t0010-basic-commands.sh
+1
-1
t0020-init.sh
test/t0020-init.sh
+1
-1
t0030-mount.sh
test/t0030-mount.sh
+1
-1
t0040-add-and-cat.sh
test/t0040-add-and-cat.sh
+4
-4
没有找到文件。
Godeps/Godeps.json
浏览文件 @
7ba3cadb
...
...
@@ -111,6 +111,10 @@
"Rev"
:
"1976046c2b0db0b668791b3e541d76a38b7c1af7"
},
{
"ImportPath"
:
"github.com/jbenet/go-random"
,
"Rev"
:
"e4585173eb8c47eea36c3dbff22f26f3f94d3586"
},
{
"ImportPath"
:
"github.com/kr/binarydist"
,
"Rev"
:
"9955b0ab8708602d411341e55fffd7e0700f86bd"
},
...
...
Godeps/_workspace/src/github.com/jbenet/go-random/LICENSE
0 → 100644
浏览文件 @
7ba3cadb
The MIT License (MIT)
Copyright (c) 2014 Juan Batiz-Benet
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Godeps/_workspace/src/github.com/jbenet/go-random/README.md
0 → 100644
浏览文件 @
7ba3cadb
# go-random outputs randomness
This is a unix util that outputs randomness.
It is a thin wrapper around
`crypto/rand`
.
It aims to be portable (though it may not yet be).
### Install
```
sh
go install github.com/jbenet/go-random/random
```
(The extra /random is there because go get is stupidly too proscriptive about
package/repository names and I don't yet know how to change the default binary
output name)
### Usage:
```
> random
Usage: random <int>
Print <int> random bytes (from Go's crypto/rand)
> random 6
2q���#
```
### License
MIT
Godeps/_workspace/src/github.com/jbenet/go-random/lib.go
0 → 100644
浏览文件 @
7ba3cadb
package
random
import
(
"bytes"
randcrypto
"crypto/rand"
"io"
randmath
"math/rand"
)
func
WriteRandomBytes
(
count
int64
,
w
io
.
Writer
)
error
{
r
:=
&
io
.
LimitedReader
{
R
:
randcrypto
.
Reader
,
N
:
count
}
_
,
err
:=
io
.
Copy
(
w
,
r
)
return
err
}
func
WritePseudoRandomBytes
(
count
int64
,
w
io
.
Writer
,
seed
int64
)
error
{
randmath
.
Seed
(
seed
)
// Configurable buffer size
bufsize
:=
int64
(
1024
*
1024
*
4
)
b
:=
make
([]
byte
,
bufsize
)
for
count
>
0
{
if
bufsize
>
count
{
bufsize
=
count
b
=
b
[
:
bufsize
]
}
var
n
int64
for
i
:=
int64
(
0
);
i
<
bufsize
;
i
++
{
n
=
randmath
.
Int63
()
for
j
:=
0
;
j
<
8
&&
i
<
bufsize
;
j
++
{
b
[
i
]
=
byte
(
n
&
0xff
)
n
>>=
8
i
++
}
}
count
=
count
-
bufsize
r
:=
bytes
.
NewReader
(
b
)
_
,
err
:=
io
.
Copy
(
w
,
r
)
if
err
!=
nil
{
return
err
}
}
return
nil
}
Godeps/_workspace/src/github.com/jbenet/go-random/random/.gitignore
0 → 100644
浏览文件 @
7ba3cadb
random
Godeps/_workspace/src/github.com/jbenet/go-random/random/random.go
0 → 100644
浏览文件 @
7ba3cadb
package
main
import
(
"fmt"
"os"
"strconv"
random
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random"
)
func
main
()
{
l
:=
len
(
os
.
Args
)
if
l
!=
2
&&
l
!=
3
{
usageError
()
}
count
,
err
:=
strconv
.
ParseInt
(
os
.
Args
[
1
],
10
,
64
)
if
err
!=
nil
{
usageError
()
}
if
l
==
2
{
err
=
random
.
WriteRandomBytes
(
count
,
os
.
Stdout
)
}
else
{
seed
,
err2
:=
strconv
.
ParseInt
(
os
.
Args
[
2
],
10
,
64
)
if
err2
!=
nil
{
usageError
()
}
err
=
random
.
WritePseudoRandomBytes
(
count
,
os
.
Stdout
,
seed
)
}
if
err
!=
nil
{
die
(
err
)
}
}
func
usageError
()
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Usage: %s <count> [<seed>]
\n
"
,
os
.
Args
[
0
])
fmt
.
Fprintf
(
os
.
Stderr
,
"If <seed> is given, output <count> pseudo random bytes made from <seed> (from Go's math/rand)
\n
"
)
fmt
.
Fprintf
(
os
.
Stderr
,
"Otherwise, output <count> random bytes (from Go's crypto/rand)
\n
"
)
os
.
Exit
(
-
1
)
}
func
die
(
err
error
)
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Error: %v"
,
err
)
os
.
Exit
(
-
1
)
}
Godeps/_workspace/src/github.com/jbenet/go-random/random_test.go
0 → 100644
浏览文件 @
7ba3cadb
package
random
import
(
"bytes"
"io/ioutil"
"testing"
"time"
)
func
TestPseudoRandom
(
t
*
testing
.
T
)
{
var
testCases
=
[]
int
{
1024
,
187654
,
1048576
,
4932132
,
}
for
_
,
size
:=
range
testCases
{
var
buf
bytes
.
Buffer
err
:=
WritePseudoRandomBytes
(
int64
(
size
),
&
buf
,
int64
(
time
.
Now
()
.
UnixNano
()))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
buf
.
Len
()
!=
size
{
t
.
Fatal
(
"buffer not of the right size: %d != %d"
,
buf
.
Len
(),
size
)
}
}
}
func
TestPseudoRandomSeed
(
t
*
testing
.
T
)
{
var
first
[]
byte
var
size
=
int64
(
1024
*
4
)
seed
:=
time
.
Now
()
.
UnixNano
()
for
i
:=
0
;
i
<
100
;
i
++
{
var
bufs
bytes
.
Buffer
var
bufr
bytes
.
Buffer
if
err
:=
WritePseudoRandomBytes
(
size
,
&
bufs
,
seed
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:=
WritePseudoRandomBytes
(
size
,
&
bufr
,
time
.
Now
()
.
UnixNano
());
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
bufs
.
Len
()
!=
int
(
size
)
{
t
.
Fatal
(
"buffer not of the right size: %d != %d"
,
bufs
.
Len
(),
size
)
}
if
bufr
.
Len
()
!=
int
(
size
)
{
t
.
Fatal
(
"buffer not of the right size: %d != %d"
,
bufr
.
Len
(),
size
)
}
if
first
==
nil
{
first
=
bufs
.
Bytes
()
}
else
if
!
bytes
.
Equal
(
first
,
bufs
.
Bytes
())
{
t
.
Fatal
(
"seeded constructed different bytes"
)
}
if
bytes
.
Equal
(
first
,
bufr
.
Bytes
())
{
t
.
Fatal
(
"non-seeded constructed same bytes"
)
}
}
}
func
TestCryptoRandom
(
t
*
testing
.
T
)
{
var
testCases
=
[]
int
{
1024
,
187654
,
1048576
,
}
for
_
,
size
:=
range
testCases
{
var
buf
bytes
.
Buffer
err
:=
WriteRandomBytes
(
int64
(
size
),
&
buf
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
buf
.
Len
()
!=
size
{
t
.
Fatal
(
"buffer not of the right size: %d != %d"
,
buf
.
Len
(),
size
)
}
}
}
func
BenchmarkCryptoRandom
(
b
*
testing
.
B
)
{
WriteRandomBytes
(
int64
(
b
.
N
),
ioutil
.
Discard
)
}
func
BenchmarkPseudoRandom
(
b
*
testing
.
B
)
{
WritePseudoRandomBytes
(
int64
(
b
.
N
),
ioutil
.
Discard
,
time
.
Now
()
.
UnixNano
())
}
test/.gitignore
浏览文件 @
7ba3cadb
sharness/
lib/sharness/
bin/ipfs
bin/random
test-results/
trash directory.*.sh/
test/Makefile
浏览文件 @
7ba3cadb
...
...
@@ -5,7 +5,8 @@
#
T
=
$
(
sort
$
(
wildcard t[0-9][0-9][0-9][0-9]-
*
.sh
))
SHARNESS
=
sharness/sharness.sh
SHARNESS
=
lib/sharness/sharness.sh
RANDOMSRC
=
Godeps/_workspace/src/github.com/jbenet/go-random/random
all
:
clean deps $(T) aggregate
...
...
@@ -19,24 +20,24 @@ $(T):
aggregate
:
@
echo
"***
$@
***"
.
/test-aggregate-results.sh
lib
/test-aggregate-results.sh
deps
:
$(SHARNESS) ipfs random
$(SHARNESS)
:
@
echo
"*** installing
$@
***"
.
/install-sharness.sh
lib
/install-sharness.sh
# phony to ensure we re-build it every time we run tests
ipfs
:
@
echo
"*** installing
$@
***"
mkdir
-p
bin
cd
../cmd/ipfs
&&
go build
cp ../cmd/ipfs/ipfs ipfs
cp ../cmd/ipfs/ipfs
bin/
ipfs
random
:
@
echo
"*** installing
$@
***"
go get github.com/jbenet/go-random/random
go install github.com/jbenet/go-random/random
cp
`
which random
`
random
mkdir
-p
bin
go build
-o
bin/random ../
$(RANDOMSRC)
.PHONY
:
all clean $(T) aggregate ipfs random
test/install-sharness.sh
→
test/
lib/
install-sharness.sh
浏览文件 @
7ba3cadb
...
...
@@ -8,6 +8,7 @@
# settings
version
=
50229a79ba22b2f13ccd82451d86570fecbd194c
urlprefix
=
https://raw.githubusercontent.com/mlafeldt/sharness/
$version
installpath
=
lib/sharness
# files to download
sfile
=
sharness.sh
...
...
@@ -39,8 +40,8 @@ verified_download() {
return
0
}
mkdir
-p
sharness
||
die
"Could not create 'sharness' directory"
cd
sharness
||
die
"Could not cd into 'sharness' directory"
mkdir
-p
$installpath
||
die
"Could not create 'sharness' directory"
cd
$installpath
||
die
"Could not cd into 'sharness' directory"
verified_download
"
$sfile
"
"
$shash
"
;
sok
=
$?
verified_download
"
$afile
"
"
$ahash
"
;
aok
=
$?
...
...
test/lib/random-dep.go
0 → 100644
浏览文件 @
7ba3cadb
// package randomdep is here to introduce a dependency in random for godep to
// function properly. this way we can keep go-random vendored and not
// accidentally break our tests when we change it.
package
randomdep
import
(
_
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random"
)
test/test-aggregate-results.sh
→
test/
lib/
test-aggregate-results.sh
浏览文件 @
7ba3cadb
...
...
@@ -6,7 +6,7 @@
# MIT Licensed; see the LICENSE file in this repository.
#
SHARNESS_AGGREGATE
=
"sharness/aggregate-results.sh"
SHARNESS_AGGREGATE
=
"
lib/
sharness/aggregate-results.sh"
test
-f
"
$SHARNESS_AGGREGATE
"
||
{
echo
>
&2
"Cannot find:
$SHARNESS_AGGREGATE
"
...
...
test/test-lib.sh
→
test/
lib/
test-lib.sh
浏览文件 @
7ba3cadb
...
...
@@ -9,16 +9,16 @@
# use the ipfs tool to test against
# add current directory to path, for ipfs tool.
PATH
=
$(
pwd
)
:
${
PATH
}
PATH
=
$(
pwd
)
/bin
:
${
PATH
}
# assert the `ipfs` we're using is the right one.
if
test
`
which ipfs
`
!=
$(
pwd
)
/ipfs
;
then
if
test
`
which ipfs
`
!=
$(
pwd
)
/
bin/
ipfs
;
then
echo
>
&2
"Cannot find the tests' local ipfs tool."
echo
>
&2
"Please check test and ipfs tool installation."
exit
1
fi
SHARNESS_LIB
=
"sharness/sharness.sh"
SHARNESS_LIB
=
"
lib/
sharness/sharness.sh"
.
"
$SHARNESS_LIB
"
||
{
echo
>
&2
"Cannot source:
$SHARNESS_LIB
"
...
...
test/t0010-basic-commands.sh
浏览文件 @
7ba3cadb
...
...
@@ -6,7 +6,7 @@
test_description
=
"Test installation and some basic commands"
.
.
/test-lib.sh
.
lib
/test-lib.sh
test_expect_success
"current dir is writable"
'
echo "It works!" >test.txt
...
...
test/t0020-init.sh
浏览文件 @
7ba3cadb
...
...
@@ -6,7 +6,7 @@
test_description
=
"Test init command"
.
.
/test-lib.sh
.
lib
/test-lib.sh
test_expect_success
"ipfs init succeeds"
'
export IPFS_DIR="$(pwd)/.go-ipfs" &&
...
...
test/t0030-mount.sh
浏览文件 @
7ba3cadb
...
...
@@ -6,7 +6,7 @@
test_description
=
"Test mount command"
.
.
/test-lib.sh
.
lib
/test-lib.sh
# if in travis CI, dont test mount (no fuse)
if
!
test_have_prereq FUSE
;
then
...
...
test/t0040-add-and-cat.sh
浏览文件 @
7ba3cadb
...
...
@@ -6,7 +6,7 @@
test_description
=
"Test add and cat commands"
.
.
/test-lib.sh
.
lib
/test-lib.sh
test_launch_ipfs_mount
...
...
@@ -47,7 +47,7 @@ test_expect_success "generate 100MB file using go-random" '
'
test_expect_success
"sha1 of the file looks ok"
'
echo "
54dc0dbbc353b2ffb745285793f89af0c9d98449
mountdir/bigfile" >sha1_expected &&
echo "
ae986dd159e4f014aee7409cdc2001ea74f618d1
mountdir/bigfile" >sha1_expected &&
shasum mountdir/bigfile >sha1_actual &&
test_cmp sha1_expected sha1_actual
'
...
...
@@ -57,7 +57,7 @@ test_expect_success "ipfs add bigfile succeeds" '
'
test_expect_success
"ipfs add bigfile output looks good"
'
HASH="Qm
eZVkWkDu4W1vxWdDgUbqKYba9K3u45hJEdPA4Wr2sHZz
" &&
HASH="Qm
Vm3Da371opC3hpsCLuYSozdyM6wRvu9UoUqoyW8u4LRq
" &&
echo "added $HASH $(pwd)/mountdir/bigfile" >expected &&
test_cmp expected actual
'
...
...
@@ -67,7 +67,7 @@ test_expect_success "ipfs cat succeeds" '
'
test_expect_success
"ipfs cat output looks good"
'
echo "
54dc0dbbc353b2ffb745285793f89af0c9d98449
-" >sha1_expected &&
echo "
ae986dd159e4f014aee7409cdc2001ea74f618d1
-" >sha1_expected &&
test_cmp sha1_expected sha1_actual
'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论