mirror of
https://github.com/retailcrm/mg-bot-api-client-go.git
synced 2025-03-10 06:36:07 +03:00
fix UploadFile dependency on external URL
This commit is contained in:
commit
e2205fb4d9
18
.github/workflows/ci.yml
vendored
18
.github/workflows/ci.yml
vendored
@ -19,33 +19,33 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v2
|
||||
- name: Set up latest Go 1.x version
|
||||
uses: actions/setup-go@v2
|
||||
uses: actions/checkout@v4
|
||||
- name: Set up Go 1.24
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.17'
|
||||
go-version: '1.24'
|
||||
- name: Get dependencies
|
||||
run: |
|
||||
go mod tidy
|
||||
cp .env.dist .env
|
||||
- name: Lint code with golangci-lint
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
version: v1.50.1
|
||||
version: v1.62.2
|
||||
only-new-issues: true
|
||||
tests:
|
||||
name: Tests
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: ['1.13', '1.14', '1.15', '1.16']
|
||||
go-version: ['1.13', '1.14', '1.15', '1.16', '1.17', '1.18', '1.19', '1.20', '1.21', '1.22', '1.23', '1.24']
|
||||
steps:
|
||||
- name: Set up Go ${{ matrix.go-version }}
|
||||
uses: actions/setup-go@v2
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v4
|
||||
- name: Get dependencies
|
||||
run: |
|
||||
go mod tidy
|
||||
|
@ -1,31 +1,15 @@
|
||||
run:
|
||||
skip-dirs-use-default: true
|
||||
allow-parallel-runners: true
|
||||
modules-download-mode: readonly
|
||||
|
||||
output:
|
||||
format: colored-line-number
|
||||
formats:
|
||||
- format: colored-line-number
|
||||
sort-results: true
|
||||
|
||||
# Linters below do not support go1.18 yet because of generics.
|
||||
# See https://github.com/golangci/golangci-lint/issues/2649
|
||||
# - bodyclose
|
||||
# - sqlclosecheck
|
||||
|
||||
linters:
|
||||
disable-all: true
|
||||
enable:
|
||||
- paralleltest
|
||||
- tparallel
|
||||
- asciicheck
|
||||
- asasalint
|
||||
- varnamelen
|
||||
- reassign
|
||||
- nilnil
|
||||
- nilerr
|
||||
- nakedret
|
||||
- goprintffuncname
|
||||
- typecheck
|
||||
- errchkjson
|
||||
- errcheck
|
||||
- gosimple
|
||||
- govet
|
||||
@ -33,11 +17,12 @@ linters:
|
||||
- staticcheck
|
||||
- unused
|
||||
- unparam
|
||||
- bodyclose
|
||||
- dogsled
|
||||
- dupl
|
||||
- errorlint
|
||||
- exhaustive
|
||||
- exportloopref
|
||||
- copyloopvar
|
||||
- funlen
|
||||
- gocognit
|
||||
- goconst
|
||||
@ -46,6 +31,7 @@ linters:
|
||||
- godot
|
||||
- goimports
|
||||
- revive
|
||||
- mnd
|
||||
- gosec
|
||||
- lll
|
||||
- makezero
|
||||
@ -53,22 +39,21 @@ linters:
|
||||
- nestif
|
||||
- prealloc
|
||||
- predeclared
|
||||
- exportloopref
|
||||
- sqlclosecheck
|
||||
- unconvert
|
||||
- whitespace
|
||||
- unused
|
||||
- testifylint
|
||||
|
||||
linters-settings:
|
||||
govet:
|
||||
check-shadowing: false
|
||||
disable-all: true
|
||||
enable:
|
||||
- assign
|
||||
- atomic
|
||||
- atomicalign
|
||||
- bools
|
||||
- buildtag
|
||||
- copylocks
|
||||
- fieldalignment
|
||||
- httpresponse
|
||||
- loopclosure
|
||||
- lostcancel
|
||||
@ -128,8 +113,6 @@ linters-settings:
|
||||
- log.Printf
|
||||
- log.Println
|
||||
- runtime/trace.Logf
|
||||
unused:
|
||||
check-exported: false
|
||||
unparam:
|
||||
check-exported: false
|
||||
dogsled:
|
||||
@ -138,8 +121,8 @@ linters-settings:
|
||||
threshold: 200
|
||||
errorlint:
|
||||
errorf: true
|
||||
asserts: false
|
||||
comparison: false
|
||||
asserts: true
|
||||
comparison: true
|
||||
exhaustive:
|
||||
check-generated: false
|
||||
default-signifies-exhaustive: false
|
||||
@ -161,25 +144,23 @@ linters-settings:
|
||||
whitespace:
|
||||
multi-if: false
|
||||
multi-func: false
|
||||
varnamelen:
|
||||
max-distance: 10
|
||||
ignore-map-index-ok: true
|
||||
ignore-type-assert-ok: true
|
||||
ignore-chan-recv-ok: true
|
||||
ignore-decls:
|
||||
- t *testing.T
|
||||
- e error
|
||||
- i int
|
||||
|
||||
issues:
|
||||
exclude-rules:
|
||||
- path: _test\.go
|
||||
linters:
|
||||
- dupl
|
||||
- mnd
|
||||
- lll
|
||||
- bodyclose
|
||||
- errcheck
|
||||
- sqlclosecheck
|
||||
- misspell
|
||||
- ineffassign
|
||||
- whitespace
|
||||
- makezero
|
||||
- maligned
|
||||
- ifshort
|
||||
- errcheck
|
||||
- funlen
|
||||
- goconst
|
||||
@ -187,8 +168,6 @@ issues:
|
||||
- gocyclo
|
||||
- godot
|
||||
- unused
|
||||
- errchkjson
|
||||
- varnamelen
|
||||
exclude-use-default: true
|
||||
exclude-case-sensitive: false
|
||||
max-issues-per-linter: 0
|
||||
@ -198,6 +177,3 @@ issues:
|
||||
severity:
|
||||
default-severity: error
|
||||
case-sensitive: false
|
||||
|
||||
service:
|
||||
golangci-lint-version: 1.50.x
|
||||
|
@ -16,21 +16,21 @@ import (
|
||||
|
||||
type Option func(*MgClient)
|
||||
|
||||
// OptionHTTPClient set custom http.Client for MgClient
|
||||
// OptionHTTPClient set custom http.Client for MgClient.
|
||||
func OptionHTTPClient(client *http.Client) func(*MgClient) {
|
||||
return func(c *MgClient) {
|
||||
c.httpClient = client
|
||||
}
|
||||
}
|
||||
|
||||
// OptionLogger sets the provided logger instance into the MgClient
|
||||
// OptionLogger sets the provided logger instance into the MgClient.
|
||||
func OptionLogger(logger BasicLogger) func(*MgClient) {
|
||||
return func(c *MgClient) {
|
||||
c.logger = logger
|
||||
}
|
||||
}
|
||||
|
||||
// OptionDebug enables debug mode for MgClient
|
||||
// OptionDebug enables debug mode for MgClient.
|
||||
func OptionDebug() func(*MgClient) {
|
||||
return func(c *MgClient) {
|
||||
c.Debug = true
|
||||
@ -53,7 +53,7 @@ func New(url string, token string, opts ...Option) *MgClient {
|
||||
}
|
||||
|
||||
// WithLogger sets the provided logger instance into the Client.
|
||||
// Deprecated: Use functional option OptionLogger instead
|
||||
// Deprecated: Use functional option OptionLogger instead.
|
||||
func (c *MgClient) WithLogger(logger BasicLogger) *MgClient {
|
||||
c.logger = logger
|
||||
return c
|
||||
|
@ -2,8 +2,12 @@ package v1
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/stretchr/testify/require"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
@ -69,7 +73,7 @@ func TestMgClient_Bots(t *testing.T) {
|
||||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, data)
|
||||
|
||||
for _, bot := range data {
|
||||
@ -148,7 +152,7 @@ func TestMgClient_Channels(t *testing.T) {
|
||||
]`)
|
||||
|
||||
channels, status, err := c.Channels(ChannelsRequest{Active: 1})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 200, status)
|
||||
assert.Len(t, channels, 1)
|
||||
|
||||
@ -221,7 +225,7 @@ func TestMgClient_Users(t *testing.T) {
|
||||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, data)
|
||||
|
||||
for _, user := range data {
|
||||
@ -231,9 +235,9 @@ func TestMgClient_Users(t *testing.T) {
|
||||
assert.Equal(t, "Test", user.FirstName)
|
||||
assert.Equal(t, "Test", user.LastName)
|
||||
assert.Equal(t, "2018-01-01T00:00:00.000000Z", user.CreatedAt)
|
||||
assert.Equal(t, true, user.IsActive)
|
||||
assert.Equal(t, true, user.IsOnline)
|
||||
assert.Equal(t, true, user.IsTechnicalAccount)
|
||||
assert.True(t, user.IsActive)
|
||||
assert.True(t, user.IsOnline)
|
||||
assert.True(t, user.IsTechnicalAccount)
|
||||
}
|
||||
}
|
||||
|
||||
@ -288,7 +292,7 @@ func TestMgClient_Customers(t *testing.T) {
|
||||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, data)
|
||||
|
||||
for _, customer := range data {
|
||||
@ -324,7 +328,7 @@ func TestMgClient_Chats(t *testing.T) {
|
||||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, data)
|
||||
|
||||
for _, chat := range data {
|
||||
@ -349,7 +353,7 @@ func TestMgClient_Members(t *testing.T) {
|
||||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, member := range data {
|
||||
assert.NotEmpty(t, member.ChatID)
|
||||
@ -373,7 +377,7 @@ func TestMgClient_Dialogs(t *testing.T) {
|
||||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, data)
|
||||
|
||||
for _, dialog := range data {
|
||||
@ -415,7 +419,7 @@ func TestMgClient_DialogUnassign(t *testing.T) {
|
||||
|
||||
resp, status, err := c.DialogUnassign(777)
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, status)
|
||||
|
||||
assert.Equal(t, int64(111), resp.PreviousResponsible.ID)
|
||||
@ -500,7 +504,7 @@ func TestMgClient_DialogsTagsAdd(t *testing.T) {
|
||||
|
||||
status, err := c.DialogsTagsAdd(req)
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, status)
|
||||
}
|
||||
|
||||
@ -526,7 +530,7 @@ func TestMgClient_DialogsTagsDelete(t *testing.T) {
|
||||
|
||||
status, err := c.DialogTagsDelete(req)
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, status)
|
||||
}
|
||||
|
||||
@ -547,7 +551,7 @@ func TestMgClient_Messages(t *testing.T) {
|
||||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, data)
|
||||
|
||||
for _, message := range data {
|
||||
@ -623,7 +627,7 @@ func TestMgClient_MessagesDialog(t *testing.T) {
|
||||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, data, 2)
|
||||
|
||||
for _, m := range data {
|
||||
@ -656,7 +660,7 @@ func TestMgClient_MessageSendText(t *testing.T) {
|
||||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, data.MessageID)
|
||||
}
|
||||
|
||||
@ -694,7 +698,7 @@ func TestMgClient_MessageSendTextWithSuggestions(t *testing.T) {
|
||||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, data.MessageID)
|
||||
}
|
||||
|
||||
@ -735,7 +739,7 @@ func TestMgClient_MessageSendProduct(t *testing.T) {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
t.Logf("%v", msg)
|
||||
}
|
||||
|
||||
@ -795,7 +799,7 @@ func TestMgClient_MessageSendOrder(t *testing.T) {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
t.Logf("%v", msg)
|
||||
}
|
||||
|
||||
@ -864,7 +868,7 @@ func TestMgClient_Info(t *testing.T) {
|
||||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestMgClient_Commands(t *testing.T) {
|
||||
@ -884,7 +888,7 @@ func TestMgClient_Commands(t *testing.T) {
|
||||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, data)
|
||||
|
||||
for _, command := range data {
|
||||
@ -912,7 +916,7 @@ func TestMgClient_CommandEditDelete(t *testing.T) {
|
||||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, n.ID)
|
||||
|
||||
gock.New(mgURL).
|
||||
@ -925,7 +929,7 @@ func TestMgClient_CommandEditDelete(t *testing.T) {
|
||||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
t.Logf("%v", d)
|
||||
}
|
||||
|
||||
@ -956,7 +960,7 @@ func TestMgClient_WsMeta(t *testing.T) {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
resURL := fmt.Sprintf("%s%s%s%s", strings.Replace(c.URL, "https", "wss", 1), prefix, "/ws?events=", strings.Join(events[:], ","))
|
||||
resURL := fmt.Sprintf("%s%s%s%s", strings.Replace(c.URL, "https", "wss", 1), prefix, "/ws?events=", strings.Join(events, ","))
|
||||
resToken := c.Token
|
||||
|
||||
assert.Equal(t, resURL, url)
|
||||
@ -966,13 +970,46 @@ func TestMgClient_WsMeta(t *testing.T) {
|
||||
func TestMgClient_UploadFile(t *testing.T) {
|
||||
c := client()
|
||||
|
||||
defer gock.Off()
|
||||
gock.New("https://via.placeholder.com").
|
||||
Get("/300").
|
||||
Reply(http.StatusOK).
|
||||
SetHeader("Content-Type", "image/jpeg").
|
||||
Body(func() io.Reader {
|
||||
res, err := base64.StdEncoding.DecodeString(`
|
||||
H4sIAAAAAAACA/t/4/8DBgEvN083BkZGBgZGIGT4f5vBmYGVmYWFhZkVSLCysrKx83CwAwE/Nzcn
|
||||
jyC/kJAgv6CgsJiMuLCIlKigoISihJSsrLy8vLC4koqSnIqMnLwcyBBGoFZ2NnY+Dg4+ORFBETmS
|
||||
wf8DDIIcDAoMCsyMSgxMgozMgoz/jzDIA93JyggGDFDAyMTMAnQlBycXN1DBVgEGJkZmZiag+4Ee
|
||||
AMrWAuUZWARZhRQNHdmEAxPZlQpFjBonLuRQdtp4UDTo4gcV46SiJk4uMXEJSSlVNXUNTS0TUzNz
|
||||
C0srZxdXN3cPT6/gkNCw8IjIqOSU1LT0jMys4pLSsvKKyqrmlta29o7OrkmTp0ydNn3GzFmLFi9Z
|
||||
umz5ipWrNm3esnXb9h07dx06fOToseMnTp66dPnK1WvXb9y89fDR4ydPnz1/8fLVx0+fv3z99v3H
|
||||
z18gfzEyMDPCAFZ/CQL9xQSMFhZ2kL8YmcpBCgRZWBUN2YQcA9kTC4WVjBo5RJwmLtx4kFPZOOiD
|
||||
aFLRRS4xFZOHqh9BXgP7jDiPNZHlM7jHEP66xcDDzAiMPGZBBnuGH/fuKWs3sItefBlWa7FqV+h8
|
||||
P+01l9b8KnQQ27Labk545NLIL49WZwLl1m322vzyKEPFu6npl7temwAlQ3O1zi8XvQaSXMBtBdcZ
|
||||
itDYYP//JgDowAia0AIAAA==`)
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
t.FailNow()
|
||||
return nil
|
||||
}
|
||||
|
||||
unpacker, err := gzip.NewReader(bytes.NewReader(res))
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
t.FailNow()
|
||||
return nil
|
||||
}
|
||||
|
||||
return unpacker
|
||||
}())
|
||||
|
||||
resp, err := http.Get("https://via.placeholder.com/300")
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
defer gock.Off()
|
||||
|
||||
gock.New(mgURL).
|
||||
Post("/api/bot/v1/files/upload").
|
||||
@ -1010,7 +1047,7 @@ func TestMgClient_UploadFileByUrl(t *testing.T) {
|
||||
|
||||
t.Logf("File %+v is upload", uploadFileResponse.ID)
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func RandStringBytesMaskImprSrc(n int) string {
|
||||
@ -1073,9 +1110,9 @@ func TestMgClient_SuccessChatsByCustomerId(t *testing.T) {
|
||||
}
|
||||
|
||||
resp, statusCode, err := apiClient.Chats(chatsRequest)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, statusCode)
|
||||
assert.Equal(t, 1, len(resp))
|
||||
assert.Len(t, resp, 1)
|
||||
assert.Equal(t, uint64(9000), resp[0].ID)
|
||||
assert.Equal(t, uint64(8000), resp[0].Channel.ID)
|
||||
assert.Equal(t, customerID, resp[0].Customer.ID)
|
||||
|
@ -450,7 +450,7 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
// WS options
|
||||
// WS options.
|
||||
type (
|
||||
WsOption string
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user