forked from wasabee-project/Wasabee-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_team_test.go
116 lines (102 loc) · 2.17 KB
/
model_team_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package wasabee_test
import (
"fmt"
"github.com/wasabee-project/Wasabee-Server"
"testing"
)
var tids []wasabee.TeamID
func TestNewTeam(t *testing.T) {
teamID, err := gid.NewTeam("Test Team")
if err != nil {
t.Error(err.Error())
}
// fmt.Printf("TeamID: %s", teamID.String())
q, err := gid.AgentInTeam(teamID, false)
if err != nil {
t.Error(err.Error())
}
if q == false {
t.Error("team creator not in team")
}
err = teamID.Rename("maeT tseT")
if err != nil {
t.Error(err.Error())
}
err = teamID.SetRocks("", "example.com")
if err != nil {
t.Error(err.Error())
}
t2, err := wasabee.RocksTeamID("example.com")
if err != nil {
t.Error(err.Error())
}
if t2.String() != teamID.String() {
t.Error("rocks community mismatch")
}
var td wasabee.TeamData
err = teamID.FetchTeam(&td, true)
if err != nil {
t.Error(err.Error())
}
err = teamID.FetchTeam(&td, false)
if err != nil {
t.Error(err.Error())
}
if td.Name != "maeT tseT" {
t.Errorf("name change did not work: %s", td.Name)
}
if len(td.Agent) < 1 {
t.Error("owner not in team")
}
if td.RocksComm != "example.com" {
t.Error("rocks community mismatch (&td)")
}
err = gid.SetTeamState(teamID, "Off")
if err != nil {
t.Error(err.Error())
}
err = gid.SetTeamState(teamID, "On")
if err != nil {
t.Error(err.Error())
}
// err = gid.SetTeamState(teamID, "Wombat")
//if err == nil {
// t.Error("SetTeamState did not return an error on a bad value")
//}
// err = teamID.SendAnnounce(gid, "testing")
// if err != nil {
// t.Error(err.Error())
//}
err = teamID.Delete()
if err != nil {
t.Error(err.Error())
}
}
func BenchmarkNewTeam(b *testing.B) {
for i := 0; i < b.N; i++ {
teamID, err := gid.NewTeam("Test Team")
if err != nil {
b.Error(err.Error())
}
tids = append(tids, teamID)
}
}
func BenchmarkDeleteTeam(b *testing.B) {
var err error
for _, tid := range tids {
err = tid.Delete()
if err != nil {
b.Error(err.Error())
}
}
}
func TestTeammatesNear(t *testing.T) {
var td wasabee.TeamData
err := gid.TeammatesNear(1000, 10, &td)
if err != nil {
t.Error(err.Error())
}
for _, v := range td.Agent {
fmt.Printf("%s is %fkm away\n", v.Name, v.Distance)
}
}