ipfs-cluster/test/test_test.go
Hector Sanjuan 65dc17a78b testfixing
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2018-08-07 20:12:05 +02:00

71 lines
1.6 KiB
Go

package test
import (
"reflect"
"testing"
ipfscluster "github.com/ipfs/ipfs-cluster"
)
func TestIpfsMock(t *testing.T) {
ipfsmock := NewIpfsMock()
defer ipfsmock.Close()
}
// Test that our RPC mock resembles the original
func TestRPCMockValid(t *testing.T) {
mock := &mockService{}
real := &ipfscluster.RPCAPI{}
mockT := reflect.TypeOf(mock)
realT := reflect.TypeOf(real)
// Make sure all the methods we have match the original
for i := 0; i < mockT.NumMethod(); i++ {
method := mockT.Method(i)
name := method.Name
origMethod, ok := realT.MethodByName(name)
if !ok {
t.Fatalf("%s method not found in real RPC", name)
}
mType := method.Type
oType := origMethod.Type
if nout := mType.NumOut(); nout != 1 || nout != oType.NumOut() {
t.Errorf("%s: more than 1 out parameter", name)
}
if mType.Out(0).Name() != "error" {
t.Errorf("%s out param should be an error", name)
}
if nin := mType.NumIn(); nin != oType.NumIn() || nin != 4 {
t.Fatalf("%s: num in parameter mismatch: %d vs. %d", name, nin, oType.NumIn())
}
for j := 1; j < 4; j++ {
mn := mType.In(j).String()
on := oType.In(j).String()
if mn != on {
t.Errorf("%s: name mismatch: %s vs %s", name, mn, on)
}
}
}
for i := 0; i < realT.NumMethod(); i++ {
name := realT.Method(i).Name
_, ok := mockT.MethodByName(name)
if !ok {
t.Logf("Warning: %s: unimplemented in mock rpc", name)
}
}
}
// Test that testing directory is created without error
func TestGenerateTestDirs(t *testing.T) {
sth := NewShardingTestHelper()
defer sth.Clean()
_ = sth.GetTreeMultiReader(t)
_ = sth.GetRandFileMultiReader(t, 2)
}