-
Notifications
You must be signed in to change notification settings - Fork 3
/
node_id_test.go
70 lines (62 loc) · 1.63 KB
/
node_id_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 meshtastic
import (
"bytes"
"testing"
)
const testNodeID = 3735928559
func TestNodeID_Uint32(t *testing.T) {
nodeID := NodeID(testNodeID)
got := nodeID.Uint32()
if got != testNodeID {
t.Errorf("expected %v, got %v", testNodeID, got)
}
}
func TestNodeID_Bytes(t *testing.T) {
nodeID := NodeID(testNodeID)
want := []byte{0xde, 0xad, 0xbe, 0xef}
got := nodeID.Bytes()
if !bytes.Equal(got, want) {
t.Errorf("expected %v, got %v", want, got)
}
}
func TestNodeID_String(t *testing.T) {
nodeID := NodeID(testNodeID)
want := "!deadbeef"
got := nodeID.String()
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
}
func TestNodeID_DefaultShortName(t *testing.T) {
nodeID := NodeID(testNodeID)
want := "beef"
got := nodeID.DefaultShortName()
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
}
func TestNodeID_DefaultLongName(t *testing.T) {
nodeID := NodeID(testNodeID)
want := "Meshtastic beef"
got := nodeID.DefaultLongName()
if want != got {
t.Errorf("expected %v, got %v", want, got)
}
}
// TestRandomNodeID ensures that RandomNodeID generates a valid NodeID and that multiple calls generate different
// NodeIDs.
func TestRandomNodeID(t *testing.T) {
nodeID1, err := RandomNodeID()
if err != nil {
t.Errorf("expected no error when generating the first node id, got %v", err)
}
t.Logf("nodeID1: %s", nodeID1)
nodeID2, err := RandomNodeID()
if err != nil {
t.Errorf("expected no error when generating the second node id, got %v", err)
}
t.Logf("nodeID2: %s", nodeID2)
if nodeID1 == nodeID2 {
t.Errorf("expected random node ids to be different, got %s and %s", nodeID1, nodeID2)
}
}