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-unixfs
Commits
a85aa9b5
Commit
a85aa9b5
authored
Dec 23, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: rename testutil func
parent
81a67338
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
29 additions
and
35 deletions
+29
-35
net/backpressure/backpressure_test.go
net/backpressure/backpressure_test.go
+1
-1
net/conn/dial_test.go
net/conn/dial_test.go
+4
-4
net/id_test.go
net/id_test.go
+1
-1
net/swarm/swarm_test.go
net/swarm/swarm_test.go
+1
-1
util/testutil/gen.go
util/testutil/gen.go
+15
-7
util/testutil/peer.go
util/testutil/peer.go
+7
-21
No files found.
net/backpressure/backpressure_test.go
View file @
a85aa9b5
...
...
@@ -18,7 +18,7 @@ import (
var
log
=
eventlog
.
Logger
(
"backpressure"
)
func
GenNetwork
(
t
*
testing
.
T
,
ctx
context
.
Context
)
(
inet
.
Network
,
error
)
{
p
:=
testutil
.
RandPeerNetParams
(
t
)
p
:=
testutil
.
RandPeerNetParams
OrFatal
(
t
)
ps
:=
peer
.
NewPeerstore
()
ps
.
AddAddress
(
p
.
ID
,
p
.
Addr
)
ps
.
AddPubKey
(
p
.
ID
,
p
.
PubKey
)
...
...
net/conn/dial_test.go
View file @
a85aa9b5
...
...
@@ -49,8 +49,8 @@ func setupSingleConn(t *testing.T, ctx context.Context) (a, b Conn, p1, p2 tu.Pe
func
setupConn
(
t
*
testing
.
T
,
ctx
context
.
Context
,
secure
bool
)
(
a
,
b
Conn
,
p1
,
p2
tu
.
PeerNetParams
)
{
p1
=
tu
.
RandPeerNetParams
(
t
)
p2
=
tu
.
RandPeerNetParams
(
t
)
p1
=
tu
.
RandPeerNetParams
OrFatal
(
t
)
p2
=
tu
.
RandPeerNetParams
OrFatal
(
t
)
laddr
:=
p1
.
Addr
key1
:=
p1
.
PrivKey
...
...
@@ -95,8 +95,8 @@ func setupConn(t *testing.T, ctx context.Context, secure bool) (a, b Conn, p1, p
func
testDialer
(
t
*
testing
.
T
,
secure
bool
)
{
// t.Skip("Skipping in favor of another test")
p1
:=
tu
.
RandPeerNetParams
(
t
)
p2
:=
tu
.
RandPeerNetParams
(
t
)
p1
:=
tu
.
RandPeerNetParams
OrFatal
(
t
)
p2
:=
tu
.
RandPeerNetParams
OrFatal
(
t
)
key1
:=
p1
.
PrivKey
key2
:=
p2
.
PrivKey
...
...
net/id_test.go
View file @
a85aa9b5
...
...
@@ -14,7 +14,7 @@ import (
)
func
GenNetwork
(
t
*
testing
.
T
,
ctx
context
.
Context
)
inet
.
Network
{
p
:=
testutil
.
RandPeerNetParams
(
t
)
p
:=
testutil
.
RandPeerNetParams
OrFatal
(
t
)
ps
:=
peer
.
NewPeerstore
()
ps
.
AddAddress
(
p
.
ID
,
p
.
Addr
)
ps
.
AddPubKey
(
p
.
ID
,
p
.
PubKey
)
...
...
net/swarm/swarm_test.go
View file @
a85aa9b5
...
...
@@ -51,7 +51,7 @@ func makeSwarms(ctx context.Context, t *testing.T, num int) ([]*Swarm, []testuti
peersnp
:=
make
([]
testutil
.
PeerNetParams
,
0
,
num
)
for
i
:=
0
;
i
<
num
;
i
++
{
localnp
:=
testutil
.
RandPeerNetParams
(
t
)
localnp
:=
testutil
.
RandPeerNetParams
OrFatal
(
t
)
peersnp
=
append
(
peersnp
,
localnp
)
peerstore
:=
peer
.
NewPeerstore
()
...
...
util/testutil/gen.go
View file @
a85aa9b5
...
...
@@ -107,21 +107,29 @@ func (p *PeerNetParams) checkKeys() error {
return
nil
// ok. move along.
}
func
RandPeerNetParams
(
t
*
testing
.
T
)
(
p
PeerNetParams
)
{
func
RandPeerNetParamsOrFatal
(
t
*
testing
.
T
)
PeerNetParams
{
p
,
err
:=
RandPeerNetParams
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
PeerNetParams
{}
// TODO return nil
}
return
*
p
}
func
RandPeerNetParams
()
(
*
PeerNetParams
,
error
)
{
var
p
PeerNetParams
var
err
error
p
.
Addr
=
RandLocalTCPAddress
()
p
.
PrivKey
,
p
.
PubKey
,
err
=
ci
.
GenerateKeyPair
(
ci
.
RSA
,
512
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
nil
,
err
}
p
.
ID
,
err
=
peer
.
IDFromPublicKey
(
p
.
PubKey
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
nil
,
err
}
if
err
:=
p
.
checkKeys
();
err
!=
nil
{
t
.
Fatal
(
err
)
return
nil
,
err
}
return
p
return
&
p
,
nil
}
util/testutil/peer.go
View file @
a85aa9b5
package
testutil
import
(
"testing"
ma
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
ci
"github.com/jbenet/go-ipfs/crypto"
ipfs
peer
"github.com/jbenet/go-ipfs/peer"
peer
"github.com/jbenet/go-ipfs/peer"
)
type
Peer
interface
{
Address
()
ma
.
Multiaddr
ID
()
ipfs
peer
.
ID
ID
()
peer
.
ID
PrivateKey
()
ci
.
PrivKey
PublicKey
()
ci
.
PubKey
}
func
RandPeer
(
t
*
testing
.
T
)
Peer
{
p
:=
RandPeerNetParams
(
t
)
var
err
error
p
.
Addr
=
RandLocalTCPAddress
()
p
.
PrivKey
,
p
.
PubKey
,
err
=
ci
.
GenerateKeyPair
(
ci
.
RSA
,
512
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
p
.
ID
,
err
=
ipfspeer
.
IDFromPublicKey
(
p
.
PubKey
)
func
RandPeer
()
(
Peer
,
error
)
{
p
,
err
:=
RandPeerNetParams
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:=
p
.
checkKeys
();
err
!=
nil
{
t
.
Fatal
(
err
)
return
nil
,
err
}
return
&
testpeer
{
p
}
return
&
testpeer
{
*
p
}
,
nil
}
// peer is a temporary shim to delay binding of PeerNetParams.
...
...
@@ -40,7 +26,7 @@ type testpeer struct {
PeerNetParams
}
func
(
p
*
testpeer
)
ID
()
ipfs
peer
.
ID
{
func
(
p
*
testpeer
)
ID
()
peer
.
ID
{
return
p
.
PeerNetParams
.
ID
}
...
...
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