You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.8 KiB
71 lines
1.8 KiB
5 years ago
|
package keybase
|
||
|
|
||
|
import (
|
||
|
"os/exec"
|
||
|
"testing"
|
||
|
|
||
|
"samhofi.us/x/keybase/v2/types/chat1"
|
||
|
)
|
||
|
|
||
|
func TestListConvsOnName(t *testing.T) {
|
||
|
execCommand = createFakeExecCommand("listconvsonname")
|
||
|
defer func() { execCommand = exec.Command }()
|
||
|
|
||
|
channel := chat1.ChatChannel{
|
||
|
Name: "mkbot",
|
||
|
MembersType: TEAM,
|
||
|
}
|
||
|
k := New()
|
||
|
res, err := k.ListConvsOnName(channel)
|
||
|
if err != nil {
|
||
|
t.Errorf("Expected nil error, got %#v", err)
|
||
|
}
|
||
|
|
||
|
channelcount := 10
|
||
|
if len(*res) != channelcount {
|
||
|
t.Errorf("Expected %d channels, got %d channels", channelcount, len(*res))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestSendMessageByChannel(t *testing.T) {
|
||
|
execCommand = createFakeExecCommand("send")
|
||
|
defer func() { execCommand = exec.Command }()
|
||
|
|
||
|
channel := chat1.ChatChannel{
|
||
|
Name: "user1,user2",
|
||
|
MembersType: USER,
|
||
|
}
|
||
|
k := New()
|
||
|
res, err := k.SendMessageByChannel(channel, "Hello!")
|
||
|
if err != nil {
|
||
|
t.Errorf("Expected nil error, got %#v", err)
|
||
|
}
|
||
|
|
||
|
if expected := "message sent"; res.Message != expected {
|
||
|
t.Errorf(`res.Message: expected "%s", got "%v"`, expected, res.Message)
|
||
|
}
|
||
|
|
||
|
if expected := uint(894); uint(*res.MessageID) != expected {
|
||
|
t.Errorf(`res.MessageID: expected %d, got %d`, expected, uint(*res.MessageID))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestSendMessageByConvID(t *testing.T) {
|
||
|
execCommand = createFakeExecCommand("send")
|
||
|
defer func() { execCommand = exec.Command }()
|
||
|
|
||
|
k := New()
|
||
|
res, err := k.SendMessageByConvID(chat1.ConvIDStr("000049d2395435dff0c865c18832d9645eb69fd74a2814ef55310b294092ba6d"), "Hello!")
|
||
|
if err != nil {
|
||
|
t.Errorf("Expected nil error, got %#v", err)
|
||
|
}
|
||
|
|
||
|
if expected := "message sent"; res.Message != expected {
|
||
|
t.Errorf(`res.Message: expected "%s", got "%v"`, expected, res.Message)
|
||
|
}
|
||
|
|
||
|
if expected := uint(894); uint(*res.MessageID) != expected {
|
||
|
t.Errorf(`res.MessageID: expected %d, got %d`, expected, uint(*res.MessageID))
|
||
|
}
|
||
|
}
|