Initial test, added CommandHandler to main
This commit is contained in:
parent
d42be83709
commit
c42a651055
|
@ -0,0 +1,39 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"html/template"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCommandHandler_DoesNothing(t *testing.T) {
|
||||||
|
f, err := os.CreateTemp("", "TestSatelLastSeenFiltering")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
tempFileName := f.Name()
|
||||||
|
assert.NoError(t, f.Close())
|
||||||
|
defer os.Remove(f.Name())
|
||||||
|
|
||||||
|
fakeLog := log.New(io.Discard, "", log.Ltime)
|
||||||
|
ds := MakeDataStore(fakeLog, tempFileName)
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
|
|
||||||
|
mockBot := MakeMockTgBotAPI()
|
||||||
|
mockSatel := MockSatelNameGetter{"test"}
|
||||||
|
tpl := template.Must(template.New("IRCMessage").Parse(IRCMessageTemplate))
|
||||||
|
config := AppConfig{}
|
||||||
|
config.AllowedIndexes = []int{}
|
||||||
|
config.AllowedTypes = []SatelChangeType{}
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
HandleTelegramCommands(mockBot, fakeLog, &ds, config, tpl, &mockSatel)
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
mockBot.StopReceivingUpdates()
|
||||||
|
wg.Wait()
|
||||||
|
}
|
7
main.go
7
main.go
|
@ -106,6 +106,13 @@ func main() {
|
||||||
|
|
||||||
collect.Collect(s.Events, &wg, func() {})
|
collect.Collect(s.Events, &wg, func() {})
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
HandleTelegramCommands(bot, log.New(os.Stderr, "CommandHandler", log.Lmicroseconds),
|
||||||
|
&dataStore, config, tgTpl, s)
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
go CloseSatelOnCtrlC(s, &cleanShutdown)
|
go CloseSatelOnCtrlC(s, &cleanShutdown)
|
||||||
|
|
||||||
closeDebugTools := make(chan interface{})
|
closeDebugTools := make(chan interface{})
|
||||||
|
|
|
@ -20,16 +20,16 @@ type MockTgBotAPI struct {
|
||||||
updates chan tgbotapi.Update
|
updates chan tgbotapi.Update
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MakeMockTgBotAPI() *MockTgBotAPI {
|
||||||
|
return &MockTgBotAPI{messages: []tgbotapi.Chattable{}, updates: make(chan tgbotapi.Update)}
|
||||||
|
}
|
||||||
|
|
||||||
func (botMock *MockTgBotAPI) Send(c tgbotapi.Chattable) (tgbotapi.Message, error) {
|
func (botMock *MockTgBotAPI) Send(c tgbotapi.Chattable) (tgbotapi.Message, error) {
|
||||||
botMock.messages = append(botMock.messages, c)
|
botMock.messages = append(botMock.messages, c)
|
||||||
return tgbotapi.Message{}, nil
|
return tgbotapi.Message{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (botMock *MockTgBotAPI) GetUpdatesChan(u tgbotapi.UpdateConfig) tgbotapi.UpdatesChannel {
|
func (botMock *MockTgBotAPI) GetUpdatesChan(u tgbotapi.UpdateConfig) tgbotapi.UpdatesChannel {
|
||||||
if botMock.updates != nil {
|
|
||||||
panic("Called mock GetUpdatesChan more than once")
|
|
||||||
}
|
|
||||||
botMock.updates = make(chan tgbotapi.Update)
|
|
||||||
return botMock.updates
|
return botMock.updates
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue