-
Notifications
You must be signed in to change notification settings - Fork 7
/
topicchanger_test.go
80 lines (71 loc) · 2.28 KB
/
topicchanger_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
package main
import (
"database/sql"
"testing"
"time"
)
func TestInsertNextEvent(t *testing.T) {
// overwrite DB query function to return locally defined event
evt := event{}
getNextEvent = func() (*event, error) {
return &evt, nil
}
// setup different possibilities and expected results
date := time.Date(2014, 4, 23, 18, 12, 0, 0, time.UTC)
evtTreff := event{
stammtisch: false,
override: "",
location: sql.NullString{String: "garbage", Valid: false},
date: date,
topic: sql.NullString{String: "Testing", Valid: true},
speaker: sql.NullString{String: "Test-Speaker", Valid: true},
}
strTreff := RobotBlockIdentifier + " 2014-04-23: c¼h: Testing von Test-Speaker"
evtStammtisch := event{
stammtisch: true,
override: "",
location: sql.NullString{String: "Mr. Woot", Valid: true},
date: date,
topic: sql.NullString{String: "GARBAGE", Valid: false},
speaker: sql.NullString{String: "GaRbAgE", Valid: false},
}
strStammtisch := RobotBlockIdentifier + " 2014-04-23: Stammtisch @ Mr. Woot https://www.noname-ev.de/yarpnarp.html bitte zu/absagen"
now := time.Now()
evtSpecial := event{
stammtisch: false,
override: "RGB2R",
location: sql.NullString{String: "gArBaGe", Valid: false},
date: now,
topic: sql.NullString{String: "GArbAGe", Valid: false},
speaker: sql.NullString{String: "gaRBagE", Valid: false},
}
strSpecial := RobotBlockIdentifier + " HEUTE (" + now.Format("02.Jan") + "): Ausnahmsweise: RGB2R"
strOld := RobotBlockIdentifier + " Derp"
// Test if replacement works correctly
evt = evtTreff
var tests = map[event]map[string]string{
evtTreff: map[string]string{
"NoName": "NoName | " + strTreff,
"NoName | " + strOld: "NoName | " + strTreff,
"NoName | " + strOld + " | Derp": "NoName | " + strTreff + " | Derp",
},
evtStammtisch: map[string]string{
"NoName": "NoName | " + strStammtisch,
},
evtSpecial: map[string]string{
"NoName": "NoName | " + strSpecial,
},
}
for curEvt, topics := range tests {
evt = curEvt
for from, to := range topics {
newTopic, err := replaceTopic(from)
if err != nil {
t.Fatal(err)
}
if newTopic != to {
t.Errorf("insertNextEvent(%v)\n GOT: %q\nWANT: %q", from, newTopic, to)
}
}
}
}