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
0172e4f2
Commit
0172e4f2
authored
Dec 24, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style(testutil) rename testutil.Peer -> testutil.Identity
cc @jbenet
parent
2b2ff548
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
36 additions
and
36 deletions
+36
-36
exchange/bitswap/bitswap_test.go
exchange/bitswap/bitswap_test.go
+1
-1
exchange/bitswap/testnet/interface.go
exchange/bitswap/testnet/interface.go
+1
-1
exchange/bitswap/testnet/network_test.go
exchange/bitswap/testnet/network_test.go
+4
-4
exchange/bitswap/testnet/peernet.go
exchange/bitswap/testnet/peernet.go
+1
-1
exchange/bitswap/testnet/virtual.go
exchange/bitswap/testnet/virtual.go
+1
-1
exchange/bitswap/testutils.go
exchange/bitswap/testutils.go
+2
-2
namesys/resolve_test.go
namesys/resolve_test.go
+1
-1
routing/mock/centralized_client.go
routing/mock/centralized_client.go
+1
-1
routing/mock/centralized_server.go
routing/mock/centralized_server.go
+2
-2
routing/mock/centralized_test.go
routing/mock/centralized_test.go
+7
-7
routing/mock/dht.go
routing/mock/dht.go
+2
-2
routing/mock/interface.go
routing/mock/interface.go
+2
-2
util/testutil/identity.go
util/testutil/identity.go
+11
-11
No files found.
exchange/bitswap/bitswap_test.go
View file @
0172e4f2
...
...
@@ -61,7 +61,7 @@ func TestProviderForKeyButNetworkCannotFind(t *testing.T) { // TODO revisit this
defer
g
.
Close
()
block
:=
blocks
.
NewBlock
([]
byte
(
"block"
))
pinfo
:=
testutil
.
Rand
Peer
OrFatal
(
t
)
pinfo
:=
testutil
.
Rand
Identity
OrFatal
(
t
)
rs
.
Client
(
pinfo
)
.
Provide
(
context
.
Background
(),
block
.
Key
())
// but not on network
solo
:=
g
.
Next
()
...
...
exchange/bitswap/testnet/interface.go
View file @
0172e4f2
...
...
@@ -7,7 +7,7 @@ import (
)
type
Network
interface
{
Adapter
(
testutil
.
Peer
)
bsnet
.
BitSwapNetwork
Adapter
(
testutil
.
Identity
)
bsnet
.
BitSwapNetwork
HasPeer
(
peer
.
ID
)
bool
}
exchange/bitswap/testnet/network_test.go
View file @
0172e4f2
...
...
@@ -17,11 +17,11 @@ import (
func
TestSendRequestToCooperativePeer
(
t
*
testing
.
T
)
{
net
:=
VirtualNetwork
(
mockrouting
.
NewServer
(),
delay
.
Fixed
(
0
))
recipientPeer
:=
testutil
.
Rand
Peer
OrFatal
(
t
)
recipientPeer
:=
testutil
.
Rand
Identity
OrFatal
(
t
)
t
.
Log
(
"Get two network adapters"
)
initiator
:=
net
.
Adapter
(
testutil
.
Rand
Peer
OrFatal
(
t
))
initiator
:=
net
.
Adapter
(
testutil
.
Rand
Identity
OrFatal
(
t
))
recipient
:=
net
.
Adapter
(
recipientPeer
)
expectedStr
:=
"response from recipient"
...
...
@@ -67,8 +67,8 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
func
TestSendMessageAsyncButWaitForResponse
(
t
*
testing
.
T
)
{
net
:=
VirtualNetwork
(
mockrouting
.
NewServer
(),
delay
.
Fixed
(
0
))
responderPeer
:=
testutil
.
Rand
Peer
OrFatal
(
t
)
waiter
:=
net
.
Adapter
(
testutil
.
Rand
Peer
OrFatal
(
t
))
responderPeer
:=
testutil
.
Rand
Identity
OrFatal
(
t
)
waiter
:=
net
.
Adapter
(
testutil
.
Rand
Identity
OrFatal
(
t
))
responder
:=
net
.
Adapter
(
responderPeer
)
var
wg
sync
.
WaitGroup
...
...
exchange/bitswap/testnet/peernet.go
View file @
0172e4f2
...
...
@@ -19,7 +19,7 @@ func StreamNet(ctx context.Context, net mockpeernet.Mocknet, rs mockrouting.Serv
return
&
peernet
{
net
,
rs
},
nil
}
func
(
pn
*
peernet
)
Adapter
(
p
testutil
.
Peer
)
bsnet
.
BitSwapNetwork
{
func
(
pn
*
peernet
)
Adapter
(
p
testutil
.
Identity
)
bsnet
.
BitSwapNetwork
{
client
,
err
:=
pn
.
Mocknet
.
AddPeer
(
p
.
PrivateKey
(),
p
.
Address
())
if
err
!=
nil
{
panic
(
err
.
Error
())
...
...
exchange/bitswap/testnet/virtual.go
View file @
0172e4f2
...
...
@@ -29,7 +29,7 @@ type network struct {
delay
delay
.
D
}
func
(
n
*
network
)
Adapter
(
p
testutil
.
Peer
)
bsnet
.
BitSwapNetwork
{
func
(
n
*
network
)
Adapter
(
p
testutil
.
Identity
)
bsnet
.
BitSwapNetwork
{
client
:=
&
networkClient
{
local
:
p
.
ID
(),
network
:
n
,
...
...
exchange/bitswap/testutils.go
View file @
0172e4f2
...
...
@@ -41,7 +41,7 @@ func (g *SessionGenerator) Close() error {
func
(
g
*
SessionGenerator
)
Next
()
Instance
{
g
.
seq
++
p
,
err
:=
testutil
.
Rand
Peer
()
p
,
err
:=
testutil
.
Rand
Identity
()
if
err
!=
nil
{
panic
(
"FIXME"
)
// TODO change signature
}
...
...
@@ -78,7 +78,7 @@ func (i *Instance) SetBlockstoreLatency(t time.Duration) time.Duration {
// NB: It's easy make mistakes by providing the same peer ID to two different
// sessions. To safeguard, use the SessionGenerator to generate sessions. It's
// just a much better idea.
func
session
(
ctx
context
.
Context
,
net
tn
.
Network
,
p
testutil
.
Peer
)
Instance
{
func
session
(
ctx
context
.
Context
,
net
tn
.
Network
,
p
testutil
.
Identity
)
Instance
{
bsdelay
:=
delay
.
Fixed
(
0
)
const
kWriteCacheElems
=
100
...
...
namesys/resolve_test.go
View file @
0172e4f2
...
...
@@ -10,7 +10,7 @@ import (
)
func
TestRoutingResolve
(
t
*
testing
.
T
)
{
d
:=
mockrouting
.
NewServer
()
.
Client
(
testutil
.
Rand
Peer
OrFatal
(
t
))
d
:=
mockrouting
.
NewServer
()
.
Client
(
testutil
.
Rand
Identity
OrFatal
(
t
))
resolver
:=
NewRoutingResolver
(
d
)
publisher
:=
NewRoutingPublisher
(
d
)
...
...
routing/mock/centralized_client.go
View file @
0172e4f2
...
...
@@ -17,7 +17,7 @@ var log = u.Logger("mockrouter")
type
client
struct
{
datastore
ds
.
Datastore
server
server
peer
testutil
.
Peer
peer
testutil
.
Identity
}
// FIXME(brian): is this method meant to simulate putting a value into the network?
...
...
routing/mock/centralized_server.go
View file @
0172e4f2
...
...
@@ -73,11 +73,11 @@ func (rs *s) Providers(k u.Key) []peer.PeerInfo {
return
ret
}
func
(
rs
*
s
)
Client
(
p
testutil
.
Peer
)
Client
{
func
(
rs
*
s
)
Client
(
p
testutil
.
Identity
)
Client
{
return
rs
.
ClientWithDatastore
(
context
.
Background
(),
p
,
ds
.
NewMapDatastore
())
}
func
(
rs
*
s
)
ClientWithDatastore
(
_
context
.
Context
,
p
testutil
.
Peer
,
datastore
ds
.
Datastore
)
Client
{
func
(
rs
*
s
)
ClientWithDatastore
(
_
context
.
Context
,
p
testutil
.
Identity
,
datastore
ds
.
Datastore
)
Client
{
return
&
client
{
peer
:
p
,
datastore
:
ds
.
NewMapDatastore
(),
...
...
routing/mock/centralized_test.go
View file @
0172e4f2
...
...
@@ -13,7 +13,7 @@ import (
func
TestKeyNotFound
(
t
*
testing
.
T
)
{
var
pi
=
testutil
.
Rand
Peer
OrFatal
(
t
)
var
pi
=
testutil
.
Rand
Identity
OrFatal
(
t
)
var
key
=
u
.
Key
(
"mock key"
)
var
ctx
=
context
.
Background
()
...
...
@@ -26,7 +26,7 @@ func TestKeyNotFound(t *testing.T) {
}
func
TestClientFindProviders
(
t
*
testing
.
T
)
{
pi
:=
testutil
.
Rand
Peer
OrFatal
(
t
)
pi
:=
testutil
.
Rand
Identity
OrFatal
(
t
)
rs
:=
NewServer
()
client
:=
rs
.
Client
(
pi
)
...
...
@@ -57,7 +57,7 @@ func TestClientOverMax(t *testing.T) {
k
:=
u
.
Key
(
"hello"
)
numProvidersForHelloKey
:=
100
for
i
:=
0
;
i
<
numProvidersForHelloKey
;
i
++
{
pi
:=
testutil
.
Rand
Peer
OrFatal
(
t
)
pi
:=
testutil
.
Rand
Identity
OrFatal
(
t
)
err
:=
rs
.
Client
(
pi
)
.
Provide
(
context
.
Background
(),
k
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -65,7 +65,7 @@ func TestClientOverMax(t *testing.T) {
}
max
:=
10
pi
:=
testutil
.
Rand
Peer
OrFatal
(
t
)
pi
:=
testutil
.
Rand
Identity
OrFatal
(
t
)
client
:=
rs
.
Client
(
pi
)
providersFromClient
:=
client
.
FindProvidersAsync
(
context
.
Background
(),
k
,
max
)
...
...
@@ -100,7 +100,7 @@ func TestCanceledContext(t *testing.T) {
default
:
}
pi
,
err
:=
testutil
.
Rand
Peer
()
pi
,
err
:=
testutil
.
Rand
Identity
()
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
@@ -112,7 +112,7 @@ func TestCanceledContext(t *testing.T) {
}
}()
local
:=
testutil
.
Rand
Peer
OrFatal
(
t
)
local
:=
testutil
.
Rand
Identity
OrFatal
(
t
)
client
:=
rs
.
Client
(
local
)
t
.
Log
(
"warning: max is finite so this test is non-deterministic"
)
...
...
@@ -138,7 +138,7 @@ func TestCanceledContext(t *testing.T) {
func
TestValidAfter
(
t
*
testing
.
T
)
{
pi
:=
testutil
.
Rand
Peer
OrFatal
(
t
)
pi
:=
testutil
.
Rand
Identity
OrFatal
(
t
)
var
key
=
u
.
Key
(
"mock key"
)
var
ctx
=
context
.
Background
()
conf
:=
DelayConfig
{
...
...
routing/mock/dht.go
View file @
0172e4f2
...
...
@@ -19,11 +19,11 @@ func NewDHTNetwork(mn mocknet.Mocknet) Server {
}
}
func
(
rs
*
mocknetserver
)
Client
(
p
testutil
.
Peer
)
Client
{
func
(
rs
*
mocknetserver
)
Client
(
p
testutil
.
Identity
)
Client
{
return
rs
.
ClientWithDatastore
(
context
.
TODO
(),
p
,
ds
.
NewMapDatastore
())
}
func
(
rs
*
mocknetserver
)
ClientWithDatastore
(
ctx
context
.
Context
,
p
testutil
.
Peer
,
ds
ds
.
Datastore
)
Client
{
func
(
rs
*
mocknetserver
)
ClientWithDatastore
(
ctx
context
.
Context
,
p
testutil
.
Identity
,
ds
ds
.
Datastore
)
Client
{
// FIXME AddPeer doesn't appear to be idempotent
...
...
routing/mock/interface.go
View file @
0172e4f2
...
...
@@ -16,8 +16,8 @@ import (
// Server provides mockrouting Clients
type
Server
interface
{
Client
(
p
testutil
.
Peer
)
Client
ClientWithDatastore
(
context
.
Context
,
testutil
.
Peer
,
ds
.
Datastore
)
Client
Client
(
p
testutil
.
Identity
)
Client
ClientWithDatastore
(
context
.
Context
,
testutil
.
Identity
,
ds
.
Datastore
)
Client
}
// Client implements IpfsRouting
...
...
util/testutil/
peer
.go
→
util/testutil/
identity
.go
View file @
0172e4f2
...
...
@@ -8,46 +8,46 @@ import (
peer
"github.com/jbenet/go-ipfs/peer"
)
type
Peer
interface
{
type
Identity
interface
{
Address
()
ma
.
Multiaddr
ID
()
peer
.
ID
PrivateKey
()
ci
.
PrivKey
PublicKey
()
ci
.
PubKey
}
func
Rand
Peer
()
(
Peer
,
error
)
{
func
Rand
Identity
()
(
Identity
,
error
)
{
p
,
err
:=
RandPeerNetParams
()
if
err
!=
nil
{
return
nil
,
err
}
return
&
testpeer
{
*
p
},
nil
return
&
identity
{
*
p
},
nil
}
func
Rand
Peer
OrFatal
(
t
*
testing
.
T
)
Peer
{
func
Rand
Identity
OrFatal
(
t
*
testing
.
T
)
Identity
{
p
,
err
:=
RandPeerNetParams
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
return
&
testpeer
{
*
p
}
return
&
identity
{
*
p
}
}
//
peer
is a temporary shim to delay binding of PeerNetParams.
type
testpeer
struct
{
//
identity
is a temporary shim to delay binding of PeerNetParams.
type
identity
struct
{
PeerNetParams
}
func
(
p
*
testpeer
)
ID
()
peer
.
ID
{
func
(
p
*
identity
)
ID
()
peer
.
ID
{
return
p
.
PeerNetParams
.
ID
}
func
(
p
*
testpeer
)
Address
()
ma
.
Multiaddr
{
func
(
p
*
identity
)
Address
()
ma
.
Multiaddr
{
return
p
.
Addr
}
func
(
p
*
testpeer
)
PrivateKey
()
ci
.
PrivKey
{
func
(
p
*
identity
)
PrivateKey
()
ci
.
PrivKey
{
return
p
.
PrivKey
}
func
(
p
*
testpeer
)
PublicKey
()
ci
.
PubKey
{
func
(
p
*
identity
)
PublicKey
()
ci
.
PubKey
{
return
p
.
PubKey
}
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