diff --git a/bot_test.go b/bot_test.go index 18cbfdf..0b8d98d 100644 --- a/bot_test.go +++ b/bot_test.go @@ -215,13 +215,13 @@ func (s *BotTestSuite) TestSetWebhook() { params := url.Values{ "url": {"hookurl"}, "max_connections": {"9"}, - "allowed_updates": {"message"}, + "allowed_updates": {"message", "callback_query"}, } data := "92839727433" options := &SetWebhookOptions{ Certificate: []byte(data), MaxConnections: 9, - AllowedUpdates: []string{"message"}, + AllowedUpdates: []string{"message", "callback_query"}, } file := mhttp.File{ @@ -236,6 +236,13 @@ func (s *BotTestSuite) TestSetWebhook() { s.Nil(err) } +func (s *BotTestSuite) TestDeleteWebhook() { + s.registerRequestCheck("deleteWebhook", "") + + err := s.bot.DeleteWebhook() + s.Nil(err) +} + func (s *BotTestSuite) TestGetChatAdministrators() { s.registerResponse("getChatAdministrators", url.Values{"chat_id": {"123"}}, `{ "ok": true, diff --git a/helpers_test.go b/helpers_test.go new file mode 100644 index 0000000..23141e0 --- /dev/null +++ b/helpers_test.go @@ -0,0 +1,22 @@ +package micha + +import ( + "errors" + "testing" + + "github.com/stretchr/testify/assert" +) + +type testStruct struct{} + +func (s testStruct) MarshalJSON() ([]byte, error) { + return nil, errors.New("Some error") +} + +func TestStructToValues(t *testing.T) { + _, err := structToValues(testStruct{}) + assert.NotNil(t, err) + + _, err = structToValues([]string{"1"}) + assert.NotNil(t, err) +} diff --git a/http/http.go b/http/http.go index 131ccc4..a2a67a2 100644 --- a/http/http.go +++ b/http/http.go @@ -37,8 +37,10 @@ func Get(url string) ([]byte, error) { func Post(url string, data interface{}) ([]byte, error) { body := new(bytes.Buffer) - if err := json.NewEncoder(body).Encode(data); err != nil { - return nil, fmt.Errorf("Encode data error (%s)", err.Error()) + if data != nil { + if err := json.NewEncoder(body).Encode(data); err != nil { + return nil, fmt.Errorf("Encode data error (%s)", err.Error()) + } } request, err := http.NewRequest("POST", url, body) @@ -72,8 +74,8 @@ func PostMultipart(url string, file *File, params url.Values) ([]byte, error) { } for field, values := range params { - if len(values) > 0 { - if err := writer.WriteField(field, values[0]); err != nil { + for i := range values { + if err := writer.WriteField(field, values[i]); err != nil { return nil, err } }