forked from berty/berty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting_test.go
72 lines (59 loc) · 1.46 KB
/
testing_test.go
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
package bertyprotocol
import (
"context"
"fmt"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"berty.tech/berty/v2/go/pkg/protocoltypes"
)
func TestClient_impl(t *testing.T) {
var _ Service = (*service)(nil)
var _ protocoltypes.ProtocolServiceServer = (*service)(nil)
}
func TestEmptyArgs(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// initialize new client
client, err := New(ctx, Opts{})
require.NoError(t, err)
err = client.Close()
require.NoError(t, err)
}
func TestTestingProtocol(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
opts := TestingOpts{}
tp, cleanup := NewTestingProtocol(ctx, t, &opts, nil)
assert.NotNil(t, tp)
cleanup()
cancel()
}
func TestTestingProtocolWithMockedPeers(t *testing.T) {
for amount := 0; amount < 5; amount++ {
t.Run(fmt.Sprintf("%d-peers", amount), func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
opts := TestingOpts{}
tp, cleanup := NewTestingProtocolWithMockedPeers(ctx, t, &opts, nil, amount)
assert.NotNil(t, tp)
cleanup()
cancel()
})
}
}
func logTree(t *testing.T, log string, indent int, title bool, args ...interface{}) {
t.Helper()
if os.Getenv("SHOW_LOG_TREES") != "1" {
return
}
if len(args) > 0 {
log = fmt.Sprintf(log, args...)
}
if !title {
log = "└── " + log
}
for i := 0; i < indent; i++ {
log = "│ " + log
}
t.Log(log)
}