[TEST] add some tests
This commit is contained in:
parent
291b2106ac
commit
709ce45e93
|
@ -1 +0,0 @@
|
|||
package cmd
|
48
cmd/serve.go
48
cmd/serve.go
|
@ -50,54 +50,6 @@ var serveCmd = &cobra.Command{
|
|||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||
sig := <-sigs
|
||||
log.Infof("received %s", sig)
|
||||
|
||||
/*
|
||||
server := o3.ThreemaRest{}
|
||||
|
||||
var thrAccount models.AccountThreema
|
||||
if err := database.Read.First(&thrAccount).Error; err != nil {
|
||||
id, _ := server.CreateIdentity()
|
||||
thrAccount.TID = make([]byte, len(id.ID))
|
||||
thrAccount.LSK = make([]byte, len(id.LSK))
|
||||
copy(thrAccount.TID, id.ID[:])
|
||||
copy(thrAccount.LSK, id.LSK[:])
|
||||
database.Write.Create(&thrAccount)
|
||||
}
|
||||
|
||||
log.Warnf("%s", thrAccount.TID)
|
||||
var lsk [32]byte
|
||||
copy(lsk[:], thrAccount.LSK[:])
|
||||
tid, err := o3.NewThreemaID(string(thrAccount.TID), lsk, o3.AddressBook{})
|
||||
tid.Nick = o3.NewPubNick("xmpp:geno@fireorbit.de")
|
||||
|
||||
ctx := o3.NewSessionContext(tid)
|
||||
|
||||
// let the session begin
|
||||
log.Info("Starting session")
|
||||
sendMsgChan, receiveMsgChan, err := ctx.Run()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
// handle incoming messages
|
||||
for receivedMessage := range receiveMsgChan {
|
||||
if receivedMessage.Err != nil {
|
||||
log.Errorf("Error Receiving Message: %s\n", receivedMessage.Err)
|
||||
continue
|
||||
}
|
||||
switch msg := receivedMessage.Msg.(type) {
|
||||
case o3.TextMessage:
|
||||
if tid.String() == msg.Sender().String() {
|
||||
continue
|
||||
}
|
||||
qoute := fmt.Sprintf("> %s: %s\n%s", msg.Sender(), msg.Text(), "Exactly!")
|
||||
err = ctx.SendTextMessage(msg.Sender().String(), qoute, sendMsgChan)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// correct run on root of this project
|
||||
|
||||
func TestServe(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
// fail on open file
|
||||
RootCmd.SetArgs([]string{"serve", "--config", "a"})
|
||||
assert.Panics(func() {
|
||||
Execute()
|
||||
})
|
||||
|
||||
// run
|
||||
RootCmd.SetArgs([]string{"serve", "--config", "../config_example.toml"})
|
||||
|
||||
assert.Panics(func() {
|
||||
Execute()
|
||||
})
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
package all
|
|
@ -139,7 +139,7 @@ func (a *Account) Send(to string, msg xmpp.Message) error {
|
|||
"tid": to,
|
||||
"msg_id": id,
|
||||
"type": msgType,
|
||||
}).Debug("delivered")
|
||||
}).Debug("update status of threema message")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestDummy(t *testing.T) {
|
||||
main()
|
||||
}
|
|
@ -37,7 +37,7 @@ func (jid *JID) String() string {
|
|||
return ""
|
||||
}
|
||||
str := jid.Domain
|
||||
if jid.Local != "" {
|
||||
if str != "" && jid.Local != "" {
|
||||
str = jid.Local + "@" + str
|
||||
}
|
||||
return str
|
||||
|
@ -47,15 +47,6 @@ func (jid *JID) IsDomain() bool {
|
|||
return jid != nil && jid.Local == "" && jid.Domain != ""
|
||||
}
|
||||
|
||||
func GetJID(jidStr string) (jid *JID) {
|
||||
jidS := ParseJID(jidStr)
|
||||
err := database.Read.Where(jidS).First(jid).Error
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var jidRegex *regexp.Regexp
|
||||
|
||||
func init() {
|
||||
|
|
|
@ -0,0 +1,146 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestJIDTableName(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var jid JID
|
||||
assert.Equal("jid", jid.TableName())
|
||||
}
|
||||
|
||||
// Test Values for NewJID from RFC 7622
|
||||
// https://tools.ietf.org/html/rfc7622
|
||||
func TestParseJID(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
checkList := map[string]*JID{
|
||||
"juliet@example.com": {
|
||||
Local: "juliet",
|
||||
Domain: "example.com",
|
||||
},
|
||||
"juliet@example.com/foo": {
|
||||
Local: "juliet",
|
||||
Domain: "example.com",
|
||||
},
|
||||
"juliet@example.com/foo bar": {
|
||||
Local: "juliet",
|
||||
Domain: "example.com",
|
||||
},
|
||||
"juliet@example.com/foo@bar": {
|
||||
Local: "juliet",
|
||||
Domain: "example.com",
|
||||
},
|
||||
"foo\\20bar@example.com": {
|
||||
Local: "foo\\20bar",
|
||||
Domain: "example.com",
|
||||
},
|
||||
"fussball@example.com": {
|
||||
Local: "fussball",
|
||||
Domain: "example.com",
|
||||
},
|
||||
"fußball@example.com": {
|
||||
Local: "fußball",
|
||||
Domain: "example.com",
|
||||
},
|
||||
"π@example.com": {
|
||||
Local: "π",
|
||||
Domain: "example.com",
|
||||
},
|
||||
"Σ@example.com/foo": {
|
||||
Local: "Σ",
|
||||
Domain: "example.com",
|
||||
},
|
||||
"σ@example.com/foo": {
|
||||
Local: "σ",
|
||||
Domain: "example.com",
|
||||
},
|
||||
"ς@example.com/foo": {
|
||||
Local: "ς",
|
||||
Domain: "example.com",
|
||||
},
|
||||
"king@example.com/♚": {
|
||||
Local: "king",
|
||||
Domain: "example.com",
|
||||
},
|
||||
"example.com": {
|
||||
Domain: "example.com",
|
||||
},
|
||||
"example.com/foobar": {
|
||||
Domain: "example.com",
|
||||
},
|
||||
"a.example.com/b@example.net": {
|
||||
Domain: "a.example.com",
|
||||
},
|
||||
"\"juliet\"@example.com": nil,
|
||||
"foo bar@example.com": nil,
|
||||
"juliet@example.com/ foo": nil,
|
||||
"@example.com/": nil,
|
||||
// "henryⅣ@example.com": nil, -- ignore for easier implementation
|
||||
// "♚@example.com": nil,
|
||||
"juliet@": nil,
|
||||
"/foobar": nil,
|
||||
}
|
||||
|
||||
for jidString, jidValid := range checkList {
|
||||
jid := ParseJID(jidString)
|
||||
|
||||
if jidValid != nil {
|
||||
assert.NotNil(jid, "this should be a valid JID:"+jidString)
|
||||
if jid == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
assert.Equal(jidValid.Local, jid.Local, "the local part was not right detectet:"+jidString)
|
||||
assert.Equal(jidValid.Domain, jid.Domain, "the domain part was not right detectet:"+jidString)
|
||||
} else {
|
||||
assert.Nil(jid, "this should not be a valid JID:"+jidString)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func TestJIDString(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var jid *JID
|
||||
assert.Equal("", jid.String())
|
||||
|
||||
jid = &JID{
|
||||
Domain: "example.com",
|
||||
}
|
||||
assert.Equal("example.com", jid.String())
|
||||
|
||||
jid = &JID{
|
||||
Local: "romeo",
|
||||
}
|
||||
assert.Equal("", jid.String())
|
||||
|
||||
jid = &JID{
|
||||
Local: "romeo",
|
||||
Domain: "example.com",
|
||||
}
|
||||
assert.Equal("romeo@example.com", jid.String())
|
||||
}
|
||||
|
||||
func TestJIDIsDomain(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var jid *JID
|
||||
assert.False(jid.IsDomain())
|
||||
|
||||
jid = &JID{}
|
||||
assert.False(jid.IsDomain())
|
||||
|
||||
jid = &JID{Local: "a"}
|
||||
assert.False(jid.IsDomain())
|
||||
|
||||
jid = &JID{Domain: "a"}
|
||||
assert.True(jid.IsDomain())
|
||||
|
||||
jid = &JID{Local: "a", Domain: "b"}
|
||||
assert.False(jid.IsDomain())
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
package models
|
Reference in New Issue