You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
telebot/util_test.go

29 lines
804 B
Go

package telebot
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestExtractOk(t *testing.T) {
data := []byte(`{"ok":true,"result":{"foo":"bar"}}`)
assert.NoError(t, extractOk(data))
data = []byte(`{"ok":false,"error_code":429,"description":"Too Many Requests: retry after 8","parameters":{"retry_after":8}}`)
assert.Error(t, extractOk(data))
data = []byte(`{"ok":false,"error_code":400,"description":"Bad Request: reply message not found"}`)
assert.EqualError(t, extractOk(data), ErrToReplyNotFound.Error())
}
func TestExtractMessage(t *testing.T) {
data := []byte(`{"ok":true,"result":true}`)
_, err := extractMessage(data)
assert.Equal(t, ErrTrueResult, err)
data = []byte(`{"ok":true,"result":{"foo":"bar"}}`)
_, err = extractMessage(data)
assert.NoError(t, err)
}