fix tests, linter errors and fmt

bot-api-6.1
zhuharev 2017-11-09 21:51:50 +03:00
parent 87b8e431a9
commit 2022d04b94
No known key found for this signature in database
GPG Key ID: 4B21EFB85BF9CBF5
3 changed files with 27 additions and 10 deletions

8
bot.go
View File

@ -748,6 +748,7 @@ func (bot *BotAPI) RestrictChatMember(config RestrictChatMemberConfig) (APIRespo
return bot.MakeRequest("restrictChatMember", v) return bot.MakeRequest("restrictChatMember", v)
} }
// PromoteChatMember add admin rights to user
func (bot *BotAPI) PromoteChatMember(config PromoteChatMemberConfig) (APIResponse, error) { func (bot *BotAPI) PromoteChatMember(config PromoteChatMemberConfig) (APIResponse, error) {
v := url.Values{} v := url.Values{}
@ -864,6 +865,9 @@ func (bot *BotAPI) GetInviteLink(config ChatConfig) (string, error) {
} }
resp, err := bot.MakeRequest("exportChatInviteLink", v) resp, err := bot.MakeRequest("exportChatInviteLink", v)
if err != nil {
return "", err
}
var inviteLink string var inviteLink string
err = json.Unmarshal(resp.Result, &inviteLink) err = json.Unmarshal(resp.Result, &inviteLink)
@ -871,7 +875,7 @@ func (bot *BotAPI) GetInviteLink(config ChatConfig) (string, error) {
return inviteLink, err return inviteLink, err
} }
// Pin message in supergroup // PinChatMessage pin message in supergroup
func (bot *BotAPI) PinChatMessage(config PinChatMessageConfig) (APIResponse, error) { func (bot *BotAPI) PinChatMessage(config PinChatMessageConfig) (APIResponse, error) {
v, err := config.values() v, err := config.values()
if err != nil { if err != nil {
@ -883,7 +887,7 @@ func (bot *BotAPI) PinChatMessage(config PinChatMessageConfig) (APIResponse, err
return bot.MakeRequest(config.method(), v) return bot.MakeRequest(config.method(), v)
} }
// Unpin message in supergroup // UnpinChatMessage unpin message in supergroup
func (bot *BotAPI) UnpinChatMessage(config UnpinChatMessageConfig) (APIResponse, error) { func (bot *BotAPI) UnpinChatMessage(config UnpinChatMessageConfig) (APIResponse, error) {
v, err := config.values() v, err := config.values()
if err != nil { if err != nil {

View File

@ -619,8 +619,8 @@ func TestPinChatMessage(t *testing.T) {
message, _ := bot.Send(msg) message, _ := bot.Send(msg)
pinChatMessageConfig := tgbotapi.PinChatMessageConfig{ pinChatMessageConfig := tgbotapi.PinChatMessageConfig{
ChatID: message.Chat.ID, ChatID: message.Chat.ID,
MessageID: message.MessageID, MessageID: message.MessageID,
DisableNotification: false, DisableNotification: false,
} }
_, err := bot.PinChatMessage(pinChatMessageConfig) _, err := bot.PinChatMessage(pinChatMessageConfig)
@ -640,14 +640,14 @@ func TestUnpinChatMessage(t *testing.T) {
// We need pin message to unpin something // We need pin message to unpin something
pinChatMessageConfig := tgbotapi.PinChatMessageConfig{ pinChatMessageConfig := tgbotapi.PinChatMessageConfig{
ChatID: message.Chat.ID, ChatID: message.Chat.ID,
MessageID: message.MessageID, MessageID: message.MessageID,
DisableNotification: false, DisableNotification: false,
} }
_, err := bot.PinChatMessage(pinChatMessageConfig) _, err := bot.PinChatMessage(pinChatMessageConfig)
unpinChatMessageConfig := tgbotapi.UnpinChatMessageConfig{ unpinChatMessageConfig := tgbotapi.UnpinChatMessageConfig{
ChatID: message.Chat.ID, ChatID: message.Chat.ID,
} }
_, err = bot.UnpinChatMessage(unpinChatMessageConfig) _, err = bot.UnpinChatMessage(unpinChatMessageConfig)

View File

@ -8,7 +8,14 @@ import (
) )
func TestUserStringWith(t *testing.T) { func TestUserStringWith(t *testing.T) {
user := tgbotapi.User{0, "Test", "Test", "", "en", false} user := tgbotapi.User{
ID: 0,
FirstName: "Test",
LastName: "Test",
UserName: "",
LanguageCode: "en",
IsBot: false,
}
if user.String() != "Test Test" { if user.String() != "Test Test" {
t.Fail() t.Fail()
@ -16,7 +23,13 @@ func TestUserStringWith(t *testing.T) {
} }
func TestUserStringWithUserName(t *testing.T) { func TestUserStringWithUserName(t *testing.T) {
user := tgbotapi.User{0, "Test", "Test", "@test", "en"} user := tgbotapi.User{
ID: 0,
FirstName: "Test",
LastName: "Test",
UserName: "@test",
LanguageCode: "en",
}
if user.String() != "@test" { if user.String() != "@test" {
t.Fail() t.Fail()