-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
70 lines (55 loc) · 2.06 KB
/
main_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
package main
import (
"strings"
"testing"
"github.com/dowlandaiello/GoP2P/common"
"github.com/dowlandaiello/GoP2P/types/node"
)
// TestMain - test functionality of main() method
func TestMain(t *testing.T) {
currentDir, err := common.GetCurrentDir() // Get working directory
if err != nil { // Check for errors
t.Errorf(err.Error()) // Log found error
t.FailNow() // Panic
}
node, err := node.NewNode("1.1.1.1", false) // Init node
if err != nil && !strings.Contains(err.Error(), "not permitted") { // Check for errors
t.Errorf(err.Error()) // Log found error
t.FailNow() // Panic
} else if err != nil && strings.Contains(err.Error(), "not permitted") { // Check for perm errors
t.Logf("WARNING: node testing requires sudo privileges") // Log sudo required
} else {
err = node.WriteToMemory(currentDir) // Write to working directory
if err != nil { // Check for errors
t.Errorf(err.Error()) // Log found error
t.FailNow() // Panic
}
go main() // :shrug:
}
}
// TestStartRPCServer - test functionality of startRPCServer() method
func TestStartRPCServer(t *testing.T) {
startRPCServer() // Start RPC server
}
// TestStartNode - test functionality of startNode() method
func TestStartNode(t *testing.T) {
currentDir, err := common.GetCurrentDir() // Get working directory
if err != nil { // Check for errors
t.Errorf(err.Error()) // Log found error
t.FailNow() // Panic
}
node, err := node.NewNode("1.1.1.1", false) // Init node
if err != nil && !strings.Contains(err.Error(), "not permitted") { // Check for errors
t.Errorf(err.Error()) // Log found error
t.FailNow() // Panic
} else if err != nil && strings.Contains(err.Error(), "not permitted") { // Check for perm errors
t.Logf("WARNING: node testing requires sudo privileges") // Log sudo required
} else {
err = node.WriteToMemory(currentDir) // Write to working directory
if err != nil { // Check for errors
t.Errorf(err.Error()) // Log found error
t.FailNow() // Panic
}
go startNode() // Start local node
}
}