-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrtfs_cluster_test.go
More file actions
80 lines (73 loc) Β· 1.73 KB
/
rtfs_cluster_test.go
File metadata and controls
80 lines (73 loc) Β· 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package rtfsc_test
import (
"context"
"testing"
"github.com/RTradeLtd/rtfsc"
gocid "github.com/ipfs/go-cid"
)
const (
testPIN = "QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv"
// ip address of our first ipfs and ipfs cluster node as per our makefile
nodeOneAPIAddr = "127.0.0.1"
// this is the port of the IPFS Cluster API
nodePort = "9094"
)
func TestInitialize(t *testing.T) {
cm, err := rtfsc.Initialize(context.Background(), nodeOneAPIAddr, nodePort)
if err != nil {
t.Fatal(err)
}
id, err := cm.Client.ID(context.Background())
if err != nil {
t.Fatal(err)
}
if id.Version == "" {
t.Fatal("version is empty string when it shouldn't be")
}
}
func TestInitialize_Failure(t *testing.T) {
if _, err := rtfsc.Initialize(context.Background(), "10.255.255.255", "9094"); err == nil {
t.Fatal("expected error")
}
}
func TestClusterPin(t *testing.T) {
cm, err := rtfsc.Initialize(context.Background(), nodeOneAPIAddr, nodePort)
if err != nil {
t.Fatal(err)
}
decoded, err := gocid.Decode(testPIN)
if err != nil {
t.Fatal(err)
}
type args struct {
cid gocid.Cid
}
tests := []struct {
name string
args args
wantErr bool
}{
{"Success", args{decoded}, false},
{"Failure", args{gocid.Cid{}}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if _, err := cm.Pin(context.Background(), tt.args.cid); (err != nil) != tt.wantErr {
t.Fatalf("Pin() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestListPeers(t *testing.T) {
cm, err := rtfsc.Initialize(context.Background(), nodeOneAPIAddr, nodePort)
if err != nil {
t.Fatal(err)
}
peers, err := cm.ListPeers(context.Background())
if err != nil {
t.Fatal(err)
}
if len(peers) == 0 {
t.Fatal("no pers found")
}
}