diff --git a/Makefile b/Makefile index f737613..b0d91a4 100644 --- a/Makefile +++ b/Makefile @@ -17,16 +17,16 @@ run: migrate test: deps fmt @echo "==> Running tests" - @cd $(SRC_DIR) && go test ./... -v -cpu 2 + @cd $(ROOT_DIR) && go test ./... -v -cpu 2 jenkins_test: deps @echo "==> Running tests (result in test-report.xml)" @go get -v -u github.com/jstemmer/go-junit-report - @cd $(SRC_DIR) && go test ./... -v -cpu 2 -cover -race | go-junit-report -set-exit-code > $(SRC_DIR)/test-report.xml + @cd $(ROOT_DIR) && go test ./... -v -cpu 2 -cover -race | go-junit-report -set-exit-code > $(ROOT_DIR)/test-report.xml fmt: @echo "==> Running gofmt" - @gofmt -l -s -w $(SRC_DIR) + @gofmt -l -s -w $(ROOT_DIR) deps: @echo "==> Installing dependencies" diff --git a/go.mod b/go.mod index 2b8524c..ea551bb 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/retailcrm/mg-transport-telegram require ( cloud.google.com/go v0.26.0 // indirect github.com/Microsoft/go-winio v0.4.10 // indirect - github.com/aws/aws-sdk-go v1.15.16 + github.com/aws/aws-sdk-go v1.15.18 github.com/certifi/gocertifi v0.0.0-20180118203423-deb3ae2ef261 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/denisenkom/go-mssqldb v0.0.0-20180707235734-242fa5aa1b45 // indirect @@ -16,6 +16,7 @@ require ( github.com/gin-contrib/multitemplate v0.0.0-20180607024123-41d1d62d1df3 github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 // indirect github.com/gin-gonic/gin v1.3.0 + github.com/go-ini/ini v1.38.2 // indirect github.com/go-sql-driver/mysql v1.4.0 // indirect github.com/go-telegram-bot-api/telegram-bot-api v0.0.0-20180602093832-4c16a90966d1 github.com/golang-migrate/migrate v3.4.0+incompatible @@ -32,7 +33,8 @@ require ( github.com/json-iterator/go v0.0.0-20180806060727-1624edc4454b // indirect github.com/jtolds/gls v4.2.1+incompatible // indirect github.com/kr/pretty v0.1.0 // indirect - github.com/lib/pq v0.0.0-20180523175426-90697d60dd84 // indirect + github.com/kr/pty v1.1.2 // indirect + github.com/lib/pq v1.0.0 // indirect github.com/mattn/go-isatty v0.0.3 // indirect github.com/mattn/go-sqlite3 v1.9.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect @@ -53,7 +55,7 @@ require ( golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac // indirect golang.org/x/net v0.0.0-20180821023952-922f4815f713 // indirect golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f // indirect - golang.org/x/sys v0.0.0-20180821044426-4ea2f632f6e9 // indirect + golang.org/x/sys v0.0.0-20180821140842-3b58ed4ad339 // indirect golang.org/x/text v0.3.0 google.golang.org/appengine v1.1.0 // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect diff --git a/go.sum b/go.sum index b48ffa7..26b0136 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,7 @@ github.com/Microsoft/go-winio v0.4.10 h1:NrhPZI+cp3Fjmm5t/PZkVuir43JIRLZG/PSKK7a github.com/Microsoft/go-winio v0.4.10/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= github.com/aws/aws-sdk-go v1.15.16 h1:h3Wt98XmE8BWKZKLNhw1bl+ABVMvdWwetYM/rs88jMY= github.com/aws/aws-sdk-go v1.15.16/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0= +github.com/aws/aws-sdk-go v1.15.18/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0= github.com/certifi/gocertifi v0.0.0-20180118203423-deb3ae2ef261 h1:6/yVvBsKeAw05IUj4AzvrxaCnDjN4nUqKjW9+w5wixg= github.com/certifi/gocertifi v0.0.0-20180118203423-deb3ae2ef261/go.mod h1:GJKEexRPVJrBSOjoqN5VNOIKJ5Q3RViH6eu3puDRwx4= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -32,6 +33,7 @@ github.com/gin-gonic/gin v1.3.0 h1:kCmZyPklC0gVdL728E6Aj20uYBJV93nj/TkwBTKhFbs= github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y= github.com/go-ini/ini v1.25.4 h1:Mujh4R/dH6YL8bxuISne3xX2+qcQ9p0IxKAP6ExWoUo= github.com/go-ini/ini v1.25.4/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= +github.com/go-ini/ini v1.38.2/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-sql-driver/mysql v1.4.0 h1:7LxgVwFb2hIQtMm87NdgAVfXjnt4OePseqT1tKx+opk= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-telegram-bot-api/telegram-bot-api v0.0.0-20180602093832-4c16a90966d1 h1:FlRoyZCY3snE+M9jTruqOzPwZg8KIwQBXr//t215K8E= @@ -67,10 +69,12 @@ github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVY github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/pty v1.1.2/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/lib/pq v0.0.0-20180523175426-90697d60dd84 h1:it29sI2IM490luSc3RAhp5WuCYnc6RtbfLVAB7nmC5M= github.com/lib/pq v0.0.0-20180523175426-90697d60dd84/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-sqlite3 v1.9.0 h1:pDRiWfl+++eC2FEFRy6jXmQlvp4Yh3z1MJKg4UeYM/4= @@ -113,6 +117,7 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6Zh golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180821044426-4ea2f632f6e9 h1:0RHCP7KEw0rDuVXXaT2gfV77uu6lTKa5aItB+EoFbQk= golang.org/x/sys v0.0.0-20180821044426-4ea2f632f6e9/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180821140842-3b58ed4ad339/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/text v0.0.0-20171214130843-f21a4dfb5e38/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/src/routing_test.go b/src/routing_test.go index cb3d279..43f6226 100644 --- a/src/routing_test.go +++ b/src/routing_test.go @@ -7,11 +7,13 @@ import ( "net/http" "net/http/httptest" "net/url" + "os" "strings" "testing" "github.com/gin-gonic/gin" "github.com/h2non/gock" + "github.com/retailcrm/mg-transport-api-client-go/v1" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -19,11 +21,11 @@ import ( var router *gin.Engine func init() { + os.Chdir("../") config = LoadConfig("config_test.yml") orm = NewDb(config) logger = newLogger() router = setup() - c := Connection{ ID: 1, ClientID: "123123", @@ -54,6 +56,24 @@ func TestRouting_connectHandler(t *testing.T) { func TestRouting_addBotHandler(t *testing.T) { defer gock.Off() + ch := v1.Channel{ + Type: "telegram", + Settings: v1.ChannelSettings{ + SpamAllowed: false, + Status: v1.Status{ + Delivered: v1.ChannelFeatureNone, + Read: v1.ChannelFeatureNone, + }, + Text: v1.ChannelSettingsText{ + Creating: v1.ChannelFeatureBoth, + Editing: v1.ChannelFeatureBoth, + Quoting: v1.ChannelFeatureBoth, + Deleting: v1.ChannelFeatureSend, + }, + }, + } + + outgoing, _ := json.Marshal(ch) p := url.Values{"url": {"https://" + config.HTTPServer.Host + "/telegram/123123:Qwerty"}} gock.New("https://api.telegram.org"). @@ -75,7 +95,7 @@ func TestRouting_addBotHandler(t *testing.T) { gock.New("https://test.retailcrm.pro"). Post("/api/transport/v1/channels"). - BodyString(`{"ID":0,"Type":"telegram","Events":["message_sent","message_updated","message_deleted","message_read"]}`). + JSON([]byte(outgoing)). MatchHeader("Content-Type", "application/json"). MatchHeader("X-Transport-Token", "test-token"). Reply(201).