removed test & added ability to connect without credentials

pull/186/head
Maksim Kutin 8 years ago
parent 3f11f21832
commit cb85dc9126
  1. 9
      bot.go
  2. 17
      bot_test.go

@ -67,7 +67,14 @@ func NewBotAPIViaProxy(token string, proxySettings ProxyCredentials) (*BotAPI, e
client := &http.Client{}
if proxySettings.UseProxy {
fixedURL, err := url.Parse(fmt.Sprintf("%s://%s:%s@%s:%s", proxySettings.Protocol, proxySettings.Username, proxySettings.Password, proxySettings.IP, proxySettings.Port))
var fixedURL *url.URL
var err error
if proxySettings.Username != "" && proxySettings.Password != "" {
fixedURL, err = url.Parse(fmt.Sprintf("%s://%s:%s@%s:%s", proxySettings.Protocol, proxySettings.Username, proxySettings.Password, proxySettings.IP, proxySettings.Port))
} else {
fixedURL, err = url.Parse(fmt.Sprintf("%s://%s:%s", proxySettings.Protocol, proxySettings.IP, proxySettings.Port))
}
if err == nil {
tr := &http.Transport{Proxy: http.ProxyURL(fixedURL)}

@ -8,7 +8,7 @@ import (
"testing"
"time"
"github.com/go-telegram-bot-api/telegram-bot-api/"
"github.com/mkutin/telegram-bot-api"
)
const (
@ -23,12 +23,6 @@ const (
ExistingVideoFileID = "BAADAgADZgADjMcoCav432kYe0FRAg"
ExistingVideoNoteFileID = "DQADAgADdQAD70cQSUK41dLsRMqfAg"
ExistingStickerFileID = "BQADAgADcwADjMcoCbdl-6eB--YPAg"
UseProxy = true
ProxyProtocol = "SOCKS5"
ProxyUsername = "YGko8h"
ProxyPassword = "VofoA7"
ProxyIP = "185.179.113.223"
ProxyPort = "8000"
)
func getBot(t *testing.T) (*tgbotapi.BotAPI, error) {
@ -43,15 +37,6 @@ func getBot(t *testing.T) (*tgbotapi.BotAPI, error) {
return bot, err
}
func TestNewBotAPIViaProxy(t *testing.T) {
_, err := tgbotapi.NewBotAPIViaProxy(TestToken, tgbotapi.NewProxyCredentials(UseProxy, ProxyProtocol, ProxyUsername, ProxyPassword, ProxyIP, ProxyPort))
if err != nil {
t.Error(err)
t.Fail()
}
}
func TestNewBotAPI_notoken(t *testing.T) {
_, err := tgbotapi.NewBotAPI("")