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.
135 lines
3.5 KiB
135 lines
3.5 KiB
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)) |
|
} |
|
} |
|
|
|
func TestCreateFilterString(t *testing.T) { |
|
tables := []struct { |
|
channel chat1.ChatChannel |
|
expected string |
|
}{ |
|
{ |
|
chat1.ChatChannel{}, |
|
``, |
|
}, |
|
{ |
|
chat1.ChatChannel{Name: "faketeam", MembersType: TEAM}, |
|
`{"name":"faketeam","members_type":"team"}`, |
|
}, |
|
{ |
|
chat1.ChatChannel{Name: "user1,user2", MembersType: USER}, |
|
`{"name":"user1,user2","members_type":"impteamnative"}`, |
|
}, |
|
} |
|
|
|
for _, table := range tables { |
|
if result := createFilterString(table.channel); result != table.expected { |
|
t.Errorf(`Expected "%s", got "%s"`, table.expected, result) |
|
} |
|
} |
|
} |
|
|
|
func TestCreateFiltersString(t *testing.T) { |
|
tables := []struct { |
|
channel []chat1.ChatChannel |
|
expected string |
|
}{ |
|
{ |
|
[]chat1.ChatChannel{}, |
|
``, |
|
}, |
|
{ |
|
[]chat1.ChatChannel{ |
|
chat1.ChatChannel{Name: "faketeam1", MembersType: TEAM}, |
|
chat1.ChatChannel{Name: "faketeam2", MembersType: TEAM}, |
|
}, |
|
`[{"name":"faketeam1","members_type":"team"},{"name":"faketeam2","members_type":"team"}]`, |
|
}, |
|
{ |
|
[]chat1.ChatChannel{ |
|
chat1.ChatChannel{Name: "user1,user2", MembersType: USER}, |
|
chat1.ChatChannel{Name: "user3,user4", MembersType: USER}, |
|
}, |
|
`[{"name":"user1,user2","members_type":"impteamnative"},{"name":"user3,user4","members_type":"impteamnative"}]`, |
|
}, |
|
{ |
|
[]chat1.ChatChannel{ |
|
chat1.ChatChannel{Name: "user1,user2", MembersType: USER}, |
|
chat1.ChatChannel{Name: "faketeam1", MembersType: TEAM}, |
|
}, |
|
`[{"name":"user1,user2","members_type":"impteamnative"},{"name":"faketeam1","members_type":"team"}]`, |
|
}, |
|
} |
|
|
|
for _, table := range tables { |
|
if result := createFiltersString(table.channel); result != table.expected { |
|
t.Errorf(`Expected "%s", got "%s"`, table.expected, result) |
|
} |
|
} |
|
}
|
|
|