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
Commits
7ba3cadb
Commit
7ba3cadb
authored
Nov 08, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #289 from jbenet/update-random-sharness-tests
Update random for test/
parents
7ee0c6dc
1e434ef3
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
278 additions
and
21 deletions
+278
-21
Godeps/Godeps.json
Godeps/Godeps.json
+4
-0
Godeps/_workspace/src/github.com/jbenet/go-random/LICENSE
Godeps/_workspace/src/github.com/jbenet/go-random/LICENSE
+21
-0
Godeps/_workspace/src/github.com/jbenet/go-random/README.md
Godeps/_workspace/src/github.com/jbenet/go-random/README.md
+29
-0
Godeps/_workspace/src/github.com/jbenet/go-random/lib.go
Godeps/_workspace/src/github.com/jbenet/go-random/lib.go
+47
-0
Godeps/_workspace/src/github.com/jbenet/go-random/random/.gitignore
...rkspace/src/github.com/jbenet/go-random/random/.gitignore
+1
-0
Godeps/_workspace/src/github.com/jbenet/go-random/random/random.go
...orkspace/src/github.com/jbenet/go-random/random/random.go
+47
-0
Godeps/_workspace/src/github.com/jbenet/go-random/random_test.go
..._workspace/src/github.com/jbenet/go-random/random_test.go
+96
-0
test/.gitignore
test/.gitignore
+3
-1
test/Makefile
test/Makefile
+8
-7
test/lib/install-sharness.sh
test/lib/install-sharness.sh
+3
-2
test/lib/random-dep.go
test/lib/random-dep.go
+8
-0
test/lib/test-aggregate-results.sh
test/lib/test-aggregate-results.sh
+1
-1
test/lib/test-lib.sh
test/lib/test-lib.sh
+3
-3
test/t0010-basic-commands.sh
test/t0010-basic-commands.sh
+1
-1
test/t0020-init.sh
test/t0020-init.sh
+1
-1
test/t0030-mount.sh
test/t0030-mount.sh
+1
-1
test/t0040-add-and-cat.sh
test/t0040-add-and-cat.sh
+4
-4
No files found.
Godeps/Godeps.json
View file @
7ba3cadb
...
...
@@ -110,6 +110,10 @@
"Comment"
:
"0.1.0-5-g1976046"
,
"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
View file @
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
View file @
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
View file @
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
View file @
7ba3cadb
random
Godeps/_workspace/src/github.com/jbenet/go-random/random/random.go
0 → 100644
View file @
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
View file @
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
View file @
7ba3cadb
sharness/
lib/sharness/
bin/ipfs
bin/random
test-results/
trash directory.*.sh/
test/Makefile
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
'
...
...
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