58 lines
926 B
Go
58 lines
926 B
Go
package threema
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"dev.sum7.eu/genofire/golang-lib/database"
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"dev.sum7.eu/genofire/thrempp/models"
|
|
)
|
|
|
|
func TestBot(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
b := Bot{
|
|
jid: &models.JID{},
|
|
threema: &Threema{
|
|
bot: make(map[string]*Bot),
|
|
},
|
|
}
|
|
|
|
msg := b.Handle("help")
|
|
assert.NotEqual("", msg)
|
|
|
|
// getAccount
|
|
a, err := b.getAccount()
|
|
assert.NoError(err)
|
|
assert.Nil(a)
|
|
}
|
|
|
|
func TestGetBot(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
tr := Threema{
|
|
bot: make(map[string]*Bot),
|
|
}
|
|
jid := &models.JID{
|
|
Local: "a",
|
|
Domain: "example.org",
|
|
}
|
|
//
|
|
b := tr.getBot(jid)
|
|
assert.NotNil(b)
|
|
|
|
// getBot from cache
|
|
b = tr.getBot(jid)
|
|
assert.NotNil(b)
|
|
|
|
// reset cache + test jid db
|
|
tr.bot = make(map[string]*Bot)
|
|
database.Open(database.Config{
|
|
Type: "sqlite3",
|
|
Connection: "file::memory:?mode=memory",
|
|
})
|
|
b = tr.getBot(jid)
|
|
assert.NotNil(b)
|
|
}
|