Skip to content

Commit

Permalink
Update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
onrik committed Dec 11, 2016
1 parent ea88437 commit 221add7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
11 changes: 9 additions & 2 deletions bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
Expand Down
22 changes: 22 additions & 0 deletions helpers_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
10 changes: 6 additions & 4 deletions http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit 221add7

Please sign in to comment.