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
|
/*
Copyright (c) 2019 Ben Morrison (gbmor)
This file is part of Registry.
Registry is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Registry is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Registry. If not, see <https://www.gnu.org/licenses/>.
*/
package registry
import (
"strings"
"testing"
)
// This tests all the operations on an registry.
func Test_Integration(t *testing.T) {
var integration = func(t *testing.T) {
t.Logf("Creating registry object ...\n")
registry := New(nil)
t.Logf("Fetching remote twtxt file ...\n")
mainregistry, _, err := GetTwtxt("https://gbmor.dev/twtxt.txt", nil)
if err != nil {
t.Errorf("%v\n", err)
}
t.Logf("Parsing remote twtxt file ...\n")
parsed, errz := ParseUserTwtxt(mainregistry, "gbmor", "https://gbmor.dev/twtxt.txt")
if errz != nil {
t.Errorf("%v\n", errz)
}
t.Logf("Adding new user to registry ...\n")
err = registry.AddUser("TestRegistry", "https://gbmor.dev/twtxt.txt", nil, parsed)
if err != nil {
t.Errorf("%v\n", err)
}
t.Logf("Querying user statuses ...\n")
queryuser, err := registry.QueryUser("TestRegistry")
if err != nil {
t.Errorf("%v\n", err)
}
for _, e := range queryuser {
if !strings.Contains(e, "TestRegistry") {
t.Errorf("QueryUser() returned incorrect data\n")
}
}
t.Logf("Querying for keyword in statuses ...\n")
querystatus, err := registry.QueryInStatus("morning")
if err != nil {
t.Errorf("%v\n", err)
}
for _, e := range querystatus {
if !strings.Contains(e, "morning") {
t.Errorf("QueryInStatus() returned incorrect data\n")
}
}
t.Logf("Querying for all statuses ...\n")
allstatus, err := registry.QueryAllStatuses()
if err != nil {
t.Errorf("%v\n", err)
}
if len(allstatus) == 0 || allstatus == nil {
t.Errorf("Got nil/zero from QueryAllStatuses")
}
t.Logf("Querying for all users ...\n")
allusers, err := registry.QueryUser("")
if err != nil {
t.Errorf("%v\n", err)
}
if len(allusers) == 0 || allusers == nil {
t.Errorf("Got nil/zero users on empty QueryUser() query")
}
t.Logf("Deleting user ...\n")
err = registry.DelUser("https://gbmor.dev/twtxt.txt")
if err != nil {
t.Errorf("%v\n", err)
}
}
t.Run("Integration Test", integration)
}
|