From c42aaf18ded4fb95edd683881ef11a16abe6b785 Mon Sep 17 00:00:00 2001 From: Victor Neuret Date: Tue, 2 Feb 2021 16:57:09 +0900 Subject: [PATCH] refactor(tests): Refactor integration tests (#69) * feat(auth): Refactor integration tests * Refactor integration tests main code * feat(user): Refactor integration tests * feat(library): Refactor integration tests --- microservices/auth/app/Dockerfile | 3 + microservices/auth/app/data/go.mod | 10 + microservices/auth/app/data/go.sum | 152 ++++++++++++ microservices/auth/app/go.mod | 9 +- microservices/auth/app/go.sum | 2 + microservices/auth/tests/auth.go | 93 -------- microservices/auth/tests/data.go | 12 +- microservices/auth/tests/go.mod | 9 +- microservices/auth/tests/go.sum | 164 +++++++++++++ microservices/auth/tests/invitation.go | 63 +---- microservices/auth/tests/login.go | 96 ++------ microservices/auth/tests/logout.go | 54 ----- microservices/auth/tests/refresh.go | 66 +----- microservices/auth/tests/register.go | 111 ++------- microservices/auth/tests/resetPassword.go | 86 ------- microservices/auth/tests/suite_bad_request.go | 65 +++++ microservices/auth/tests/suite_basic.go | 88 +++++++ microservices/auth/tests/suite_incorrect.go | 115 +++++++++ microservices/auth/tests/suite_logout.go | 70 ++++++ microservices/auth/tests/suite_working.go | 103 ++++++++ microservices/auth/tests/tests.go | 224 ++++-------------- microservices/library/app/Dockerfile | 1 + microservices/library/app/data/go.mod | 10 + microservices/library/app/data/go.sum | 152 ++++++++++++ microservices/library/tests/book_create.go | 77 ++---- microservices/library/tests/book_delete.go | 60 ----- microservices/library/tests/book_get.go | 77 +----- microservices/library/tests/book_update.go | 51 ---- microservices/library/tests/data.go | 25 -- microservices/library/tests/go.mod | 13 +- microservices/library/tests/go.sum | 156 ++++++++++++ microservices/library/tests/libraries_get.go | 48 ++-- microservices/library/tests/library_create.go | 77 ------ microservices/library/tests/library_delete.go | 60 ----- microservices/library/tests/library_get.go | 76 ------ .../library/tests/suite_bad_request.go | 105 ++++++++ microservices/library/tests/suite_working.go | 163 +++++++++++++ microservices/library/tests/tests.go | 169 ++++--------- microservices/user/tests/data.go | 8 +- microservices/user/tests/delete_user.go | 54 ----- microservices/user/tests/get_user.go | 47 ---- microservices/user/tests/go.mod | 6 +- microservices/user/tests/suite_bad_request.go | 38 +++ microservices/user/tests/suite_delete.go | 79 ++++++ microservices/user/tests/tests.go | 143 ++++------- microservices/user/tests/update_user.go | 81 ------- tests/filter.go | 55 ----- tests/go.mod | 16 -- tests/go.sum | 22 -- tests/{ => integration}/README.md | 0 tests/integration/filter.go | 69 ++++++ tests/integration/go.mod | 22 ++ tests/integration/go.sum | 163 +++++++++++++ tests/integration/main.go | 144 +++++++++++ tests/integration/test_suits.go | 91 +++++++ tests/itgmtod/expected_esponse.go | 35 +++ tests/itgmtod/go.mod | 5 + tests/itgmtod/go.sum | 9 + tests/itgmtod/join_URL.go | 13 + tests/itgmtod/marshall_body.go | 15 ++ tests/itgmtod/messages.go | 49 ++++ tests/itgmtod/random_string.go | 14 ++ tests/itgmtod/struct_contain.go | 49 ++++ tests/itgmtod/test_route.go | 41 ++++ tests/main.go | 107 --------- 65 files changed, 2476 insertions(+), 1814 deletions(-) create mode 100644 microservices/auth/app/data/go.mod create mode 100644 microservices/auth/app/data/go.sum delete mode 100644 microservices/auth/tests/auth.go delete mode 100644 microservices/auth/tests/logout.go delete mode 100644 microservices/auth/tests/resetPassword.go create mode 100644 microservices/auth/tests/suite_bad_request.go create mode 100644 microservices/auth/tests/suite_basic.go create mode 100644 microservices/auth/tests/suite_incorrect.go create mode 100644 microservices/auth/tests/suite_logout.go create mode 100644 microservices/auth/tests/suite_working.go create mode 100644 microservices/library/app/data/go.mod create mode 100644 microservices/library/app/data/go.sum delete mode 100644 microservices/library/tests/book_delete.go delete mode 100644 microservices/library/tests/book_update.go delete mode 100644 microservices/library/tests/data.go delete mode 100644 microservices/library/tests/library_create.go delete mode 100644 microservices/library/tests/library_delete.go delete mode 100644 microservices/library/tests/library_get.go create mode 100644 microservices/library/tests/suite_bad_request.go create mode 100644 microservices/library/tests/suite_working.go delete mode 100644 microservices/user/tests/delete_user.go delete mode 100644 microservices/user/tests/get_user.go create mode 100644 microservices/user/tests/suite_bad_request.go create mode 100644 microservices/user/tests/suite_delete.go delete mode 100644 microservices/user/tests/update_user.go delete mode 100644 tests/filter.go delete mode 100644 tests/go.mod delete mode 100644 tests/go.sum rename tests/{ => integration}/README.md (100%) create mode 100644 tests/integration/filter.go create mode 100644 tests/integration/go.mod create mode 100644 tests/integration/go.sum create mode 100644 tests/integration/main.go create mode 100644 tests/integration/test_suits.go create mode 100644 tests/itgmtod/expected_esponse.go create mode 100644 tests/itgmtod/go.mod create mode 100644 tests/itgmtod/go.sum create mode 100644 tests/itgmtod/join_URL.go create mode 100644 tests/itgmtod/marshall_body.go create mode 100644 tests/itgmtod/messages.go create mode 100644 tests/itgmtod/random_string.go create mode 100644 tests/itgmtod/struct_contain.go create mode 100644 tests/itgmtod/test_route.go delete mode 100644 tests/main.go diff --git a/microservices/auth/app/Dockerfile b/microservices/auth/app/Dockerfile index e8b69fc4..c8f5d1b2 100644 --- a/microservices/auth/app/Dockerfile +++ b/microservices/auth/app/Dockerfile @@ -14,6 +14,7 @@ ENV GO111MODULE=on \ WORKDIR /app COPY go.mod go.sum ./ +COPY data/go.mod data/go.sum ./ RUN go mod download COPY . ./ @@ -24,6 +25,8 @@ RUN go build -a -tags musl -installsuffix cgo -ldflags '-extldflags "-static"' - # Run stage FROM scratch +WORKDIR /app + COPY --from=builder /app/alexandrio-backend-auth ./ ENTRYPOINT ["./alexandrio-backend-auth"] diff --git a/microservices/auth/app/data/go.mod b/microservices/auth/app/data/go.mod new file mode 100644 index 00000000..8b2669ab --- /dev/null +++ b/microservices/auth/app/data/go.mod @@ -0,0 +1,10 @@ +module github.com/alexandr-io/backend/auth/data + +go 1.15 + +require ( + github.com/alexandr-io/berrors v1.2.7 + github.com/confluentinc/confluent-kafka-go v1.5.2 + github.com/gofiber/fiber/v2 v2.3.3 + go.mongodb.org/mongo-driver v1.4.4 +) diff --git a/microservices/auth/app/data/go.sum b/microservices/auth/app/data/go.sum new file mode 100644 index 00000000..c55e4b11 --- /dev/null +++ b/microservices/auth/app/data/go.sum @@ -0,0 +1,152 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/alexandr-io/berrors v1.2.7 h1:xBN0GImN4yfMriJjmW1ux9h86KGdSe06L5jFsMZURqg= +github.com/alexandr-io/berrors v1.2.7/go.mod h1:kZn7MFDwwMJkbRGr+LPyZh2lhg8Tfn+mZLIwC2JknQk= +github.com/andybalholm/brotli v1.0.0 h1:7UCwP93aiSfvWpapti8g88vVVGp2qqtGyePsSuDafo4= +github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= +github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48= +github.com/confluentinc/confluent-kafka-go v1.5.2 h1:l+qt+a0Okmq0Bdr1P55IX4fiwFJyg0lZQmfHkAFkv7E= +github.com/confluentinc/confluent-kafka-go v1.5.2/go.mod h1:u2zNLny2xq+5rWeTQjFHbDzzNuba4P1vo31r9r4uAdg= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= +github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= +github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= +github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= +github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= +github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= +github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY= +github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg= +github.com/gobuffalo/envy v1.6.15/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= +github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= +github.com/gobuffalo/flect v0.1.0/go.mod h1:d2ehjJqGOH/Kjqcoz+F7jHTBbmDb38yXA598Hb50EGs= +github.com/gobuffalo/flect v0.1.1/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI= +github.com/gobuffalo/flect v0.1.3/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI= +github.com/gobuffalo/genny v0.0.0-20190329151137-27723ad26ef9/go.mod h1:rWs4Z12d1Zbf19rlsn0nurr75KqhYp52EAGGxTbBhNk= +github.com/gobuffalo/genny v0.0.0-20190403191548-3ca520ef0d9e/go.mod h1:80lIj3kVJWwOrXWWMRzzdhW3DsrdjILVil/SFKBzF28= +github.com/gobuffalo/genny v0.1.0/go.mod h1:XidbUqzak3lHdS//TPu2OgiFB+51Ur5f7CSnXZ/JDvo= +github.com/gobuffalo/genny v0.1.1/go.mod h1:5TExbEyY48pfunL4QSXxlDOmdsD44RRq4mVZ0Ex28Xk= +github.com/gobuffalo/gitgen v0.0.0-20190315122116-cc086187d211/go.mod h1:vEHJk/E9DmhejeLeNt7UVvlSGv3ziL+djtTr3yyzcOw= +github.com/gobuffalo/gogen v0.0.0-20190315121717-8f38393713f5/go.mod h1:V9QVDIxsgKNZs6L2IYiGR8datgMhB577vzTDqypH360= +github.com/gobuffalo/gogen v0.1.0/go.mod h1:8NTelM5qd8RZ15VjQTFkAW6qOMx5wBbW4dSCS3BY8gg= +github.com/gobuffalo/gogen v0.1.1/go.mod h1:y8iBtmHmGc4qa3urIyo1shvOD8JftTtfcKi+71xfDNE= +github.com/gobuffalo/logger v0.0.0-20190315122211-86e12af44bc2/go.mod h1:QdxcLw541hSGtBnhUc4gaNIXRjiDppFGaDqzbrBd3v8= +github.com/gobuffalo/mapi v1.0.1/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc= +github.com/gobuffalo/mapi v1.0.2/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc= +github.com/gobuffalo/packd v0.0.0-20190315124812-a385830c7fc0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4= +github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4= +github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ= +github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0= +github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw= +github.com/gofiber/fiber/v2 v2.0.6/go.mod h1:VyfrlfcUCW0TcO5uaLHVlxZ8N25BgwnP6YjkzJmJP24= +github.com/gofiber/fiber/v2 v2.3.3 h1:nsjc9TfCl+ojXgEAu+uAT1Le7iQtZJ+Gfb/ox6+BM4w= +github.com/gofiber/fiber/v2 v2.3.3/go.mod h1:f8BRRIMjMdRyt2qmJ/0Sea3j3rwwfufPrh9WNBRiVZ0= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= +github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4= +github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= +github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= +github.com/klauspost/compress v1.10.7 h1:7rix8v8GpI3ZBb0nSozFRgbtXKv+hOe+qfEpZqybrAg= +github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +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/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= +github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE= +github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasthttp v1.16.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA= +github.com/valyala/fasthttp v1.18.0 h1:IV0DdMlatq9QO1Cr6wGJPVW1sV1Q8HvZXAIcjorylyM= +github.com/valyala/fasthttp v1.18.0/go.mod h1:jjraHZVbKOXftJfsOYoAjaeygpj5hr8ermTRJNroD7A= +github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a h1:0R4NLDRDZX6JcmhJgXi5E4b8Wg84ihbmUKp/GvSPEzc= +github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= +github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= +github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= +go.mongodb.org/mongo-driver v1.4.4 h1:bsPHfODES+/yx2PCWzUYMH8xj6PVniPI8DQrsJuSXSs= +go.mongodb.org/mongo-driver v1.4.4/go.mod h1:WcMNYLx/IlOxLe6JRJiv2uXuCz6zBLndR4SoGjYphSc= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= +golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200929083018-4d22bbb62b3c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201210223839-7e3030f88018 h1:XKi8B/gRBuTZN1vU9gFsLMm6zVz5FSCDzm8JYACnjy8= +golang.org/x/sys v0.0.0-20201210223839-7e3030f88018/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= +gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= +gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= +gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/microservices/auth/app/go.mod b/microservices/auth/app/go.mod index f1852746..32f512c1 100644 --- a/microservices/auth/app/go.mod +++ b/microservices/auth/app/go.mod @@ -2,16 +2,19 @@ module github.com/alexandr-io/backend/auth go 1.15 +replace github.com/alexandr-io/backend/auth/data => ./data + require ( - github.com/alexandr-io/berrors v1.2.7 + github.com/alexandr-io/backend/auth/data v0.0.0-00010101000000-000000000000 + github.com/alexandr-io/berrors v1.2.7 // indirect github.com/andybalholm/brotli v1.0.1 // indirect github.com/confluentinc/confluent-kafka-go v1.5.2 github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/structtag v1.2.0 github.com/form3tech-oss/jwt-go v3.2.2+incompatible - github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 + github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 // indirect github.com/go-redis/redis/v8 v8.4.2 - github.com/gofiber/fiber/v2 v2.1.0 + github.com/gofiber/fiber/v2 v2.3.3 github.com/gofiber/jwt/v2 v2.1.0 github.com/google/uuid v1.1.2 github.com/klauspost/compress v1.11.3 // indirect diff --git a/microservices/auth/app/go.sum b/microservices/auth/app/go.sum index cc2801cb..3e994458 100644 --- a/microservices/auth/app/go.sum +++ b/microservices/auth/app/go.sum @@ -65,6 +65,8 @@ github.com/gofiber/fiber/v2 v2.1.0 h1:gvEQJDxVHFLY4bNb4HSu7nqVWeLeXry8P4tA4zPKfh github.com/gofiber/fiber/v2 v2.1.0/go.mod h1:aG+lMkwy3LyVit4CnmYUbUdgjpc3UYOltvlJZ78rgQ0= github.com/gofiber/fiber/v2 v2.2.5 h1:jc/OBxxhHTMNGidsFtLU/k7YEhuXjAlawgrwG5CNuEw= github.com/gofiber/fiber/v2 v2.2.5/go.mod h1:f8BRRIMjMdRyt2qmJ/0Sea3j3rwwfufPrh9WNBRiVZ0= +github.com/gofiber/fiber/v2 v2.3.3 h1:nsjc9TfCl+ojXgEAu+uAT1Le7iQtZJ+Gfb/ox6+BM4w= +github.com/gofiber/fiber/v2 v2.3.3/go.mod h1:f8BRRIMjMdRyt2qmJ/0Sea3j3rwwfufPrh9WNBRiVZ0= github.com/gofiber/jwt/v2 v2.1.0 h1:eTahBQ8vO73fcXjpQjv/xiKZqMjvDtw5QmsvdgWQg6w= github.com/gofiber/jwt/v2 v2.1.0/go.mod h1:sf3l8cbwW93qL0kM9jcX9QTc8VIJgXCO1RWquBJUqTg= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= diff --git a/microservices/auth/tests/auth.go b/microservices/auth/tests/auth.go deleted file mode 100644 index c0e5ae2e..00000000 --- a/microservices/auth/tests/auth.go +++ /dev/null @@ -1,93 +0,0 @@ -package tests - -import ( - "errors" - "fmt" - "io/ioutil" - "log" - "net/http" -) - -func testAuthWorking(baseURL string, userData *user) error { - // Describe expected result - expectedResult := fmt.Sprintf("{\"username\":\"%s\"}", userData.Username) - // Create a new request to auth route - req, err := http.NewRequest(http.MethodGet, baseURL+"auth", nil) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Authorization", "Bearer "+userData.AuthToken) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("GET", "/auth", "Working Suit", "Can't call "+baseURL+"auth") - return err - } - // Check returned http code - if res.StatusCode != http.StatusOK { - newFailureMessage("GET", "/auth", "Working Suit", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusOK, res.StatusCode)) - return errors.New("") - } - // Read returned body - body, err := ioutil.ReadAll(res.Body) - if err != nil { - log.Println(err) - return err - } - // Compare body with expected result - if string(body) != expectedResult { - newFailureMessage("GET", "/auth", "Working Suit", fmt.Sprintf("[Expected: %s,\tGot: %s]", expectedResult, string(body))) - return errors.New("") - } - newSuccessMessage("GET", "/auth", "Working Suit") - return nil -} - -func testAuthInvalidToken(baseURL string) error { - // Create a new request to auth route - req, err := http.NewRequest(http.MethodGet, baseURL+"auth", nil) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Authorization", "Bearer randomString") - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("GET", "/auth", "Invalid Token", "Can't call "+baseURL+"auth") - return err - } - // Check returned http code - if res.StatusCode != http.StatusUnauthorized { - newFailureMessage("GET", "/auth", "Invalid Token", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusUnauthorized, res.StatusCode)) - return errors.New("") - } - - newSuccessMessage("GET", "/auth", "Invalid Token") - return nil -} - -func testAuthLogoutToken(baseURL string, jwt string) error { - // Create a new request to auth route - req, err := http.NewRequest(http.MethodGet, baseURL+"auth", nil) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("GET", "/auth", "Logout Suit", "Can't call "+baseURL+"auth") - return err - } - // Check returned http code - if res.StatusCode != http.StatusUnauthorized { - newFailureMessage("GET", "/auth", "Logout Suit", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusUnauthorized, res.StatusCode)) - return errors.New("") - } - - newSuccessMessage("GET", "/auth", "Logout Suit") - return nil -} diff --git a/microservices/auth/tests/data.go b/microservices/auth/tests/data.go index 7d7df5ef..566a7bbc 100644 --- a/microservices/auth/tests/data.go +++ b/microservices/auth/tests/data.go @@ -1,12 +1,8 @@ package tests type user struct { - Username string `json:"username"` - Email string `json:"email"` - AuthToken string `json:"auth_token"` - RefreshToken string `json:"refresh_token"` -} - -type invitation struct { - Token string `json:"token"` + Username *string `json:"username"` + Email *string `json:"email"` + AuthToken string `json:"auth_token"` + RefreshToken string `json:"refresh_token"` } diff --git a/microservices/auth/tests/go.mod b/microservices/auth/tests/go.mod index f2792d43..8f743cd5 100644 --- a/microservices/auth/tests/go.mod +++ b/microservices/auth/tests/go.mod @@ -2,4 +2,11 @@ module github.com/alexandr-io/backend/auth/tests go 1.15 -require github.com/fatih/color v1.10.0 +replace github.com/alexandr-io/backend/tests/itgmtod => ./../../../tests/itgmtod + +replace github.com/alexandr-io/backend/auth/data => ../app/data + +require ( + github.com/alexandr-io/backend/auth/data v0.0.0-00010101000000-000000000000 + github.com/alexandr-io/backend/tests/itgmtod v0.0.0-00010101000000-000000000000 +) diff --git a/microservices/auth/tests/go.sum b/microservices/auth/tests/go.sum index 9ee68f3d..5d1c6be2 100644 --- a/microservices/auth/tests/go.sum +++ b/microservices/auth/tests/go.sum @@ -1,9 +1,173 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/alexandr-io/berrors v1.2.7 h1:xBN0GImN4yfMriJjmW1ux9h86KGdSe06L5jFsMZURqg= +github.com/alexandr-io/berrors v1.2.7/go.mod h1:kZn7MFDwwMJkbRGr+LPyZh2lhg8Tfn+mZLIwC2JknQk= +github.com/andybalholm/brotli v1.0.0 h1:7UCwP93aiSfvWpapti8g88vVVGp2qqtGyePsSuDafo4= +github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= +github.com/aws/aws-sdk-go v1.34.28 h1:sscPpn/Ns3i0F4HPEWAVcwdIRaZZCuL7llJ2/60yPIk= +github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48= +github.com/confluentinc/confluent-kafka-go v1.5.2 h1:l+qt+a0Okmq0Bdr1P55IX4fiwFJyg0lZQmfHkAFkv7E= +github.com/confluentinc/confluent-kafka-go v1.5.2/go.mod h1:u2zNLny2xq+5rWeTQjFHbDzzNuba4P1vo31r9r4uAdg= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= +github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= +github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= +github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= +github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= +github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= +github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= +github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY= +github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg= +github.com/gobuffalo/envy v1.6.15/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= +github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= +github.com/gobuffalo/flect v0.1.0/go.mod h1:d2ehjJqGOH/Kjqcoz+F7jHTBbmDb38yXA598Hb50EGs= +github.com/gobuffalo/flect v0.1.1/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI= +github.com/gobuffalo/flect v0.1.3/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI= +github.com/gobuffalo/genny v0.0.0-20190329151137-27723ad26ef9/go.mod h1:rWs4Z12d1Zbf19rlsn0nurr75KqhYp52EAGGxTbBhNk= +github.com/gobuffalo/genny v0.0.0-20190403191548-3ca520ef0d9e/go.mod h1:80lIj3kVJWwOrXWWMRzzdhW3DsrdjILVil/SFKBzF28= +github.com/gobuffalo/genny v0.1.0/go.mod h1:XidbUqzak3lHdS//TPu2OgiFB+51Ur5f7CSnXZ/JDvo= +github.com/gobuffalo/genny v0.1.1/go.mod h1:5TExbEyY48pfunL4QSXxlDOmdsD44RRq4mVZ0Ex28Xk= +github.com/gobuffalo/gitgen v0.0.0-20190315122116-cc086187d211/go.mod h1:vEHJk/E9DmhejeLeNt7UVvlSGv3ziL+djtTr3yyzcOw= +github.com/gobuffalo/gogen v0.0.0-20190315121717-8f38393713f5/go.mod h1:V9QVDIxsgKNZs6L2IYiGR8datgMhB577vzTDqypH360= +github.com/gobuffalo/gogen v0.1.0/go.mod h1:8NTelM5qd8RZ15VjQTFkAW6qOMx5wBbW4dSCS3BY8gg= +github.com/gobuffalo/gogen v0.1.1/go.mod h1:y8iBtmHmGc4qa3urIyo1shvOD8JftTtfcKi+71xfDNE= +github.com/gobuffalo/logger v0.0.0-20190315122211-86e12af44bc2/go.mod h1:QdxcLw541hSGtBnhUc4gaNIXRjiDppFGaDqzbrBd3v8= +github.com/gobuffalo/mapi v1.0.1/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc= +github.com/gobuffalo/mapi v1.0.2/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc= +github.com/gobuffalo/packd v0.0.0-20190315124812-a385830c7fc0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4= +github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4= +github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ= +github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0= +github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw= +github.com/gofiber/fiber/v2 v2.0.6/go.mod h1:VyfrlfcUCW0TcO5uaLHVlxZ8N25BgwnP6YjkzJmJP24= +github.com/gofiber/fiber/v2 v2.3.3 h1:nsjc9TfCl+ojXgEAu+uAT1Le7iQtZJ+Gfb/ox6+BM4w= +github.com/gofiber/fiber/v2 v2.3.3/go.mod h1:f8BRRIMjMdRyt2qmJ/0Sea3j3rwwfufPrh9WNBRiVZ0= +github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= +github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4= +github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= +github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= +github.com/klauspost/compress v1.10.7 h1:7rix8v8GpI3ZBb0nSozFRgbtXKv+hOe+qfEpZqybrAg= +github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +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/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= +github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE= +github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= +github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasthttp v1.16.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA= +github.com/valyala/fasthttp v1.18.0 h1:IV0DdMlatq9QO1Cr6wGJPVW1sV1Q8HvZXAIcjorylyM= +github.com/valyala/fasthttp v1.18.0/go.mod h1:jjraHZVbKOXftJfsOYoAjaeygpj5hr8ermTRJNroD7A= +github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a h1:0R4NLDRDZX6JcmhJgXi5E4b8Wg84ihbmUKp/GvSPEzc= +github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= +github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c h1:u40Z8hqBAAQyv+vATcGgV0YCnDjqSL7/q/JyPhhJSPk= +github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= +github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc h1:n+nNi93yXLkJvKwXNP9d55HC7lGK4H/SRcwB5IaUZLo= +github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= +go.mongodb.org/mongo-driver v1.4.4 h1:bsPHfODES+/yx2PCWzUYMH8xj6PVniPI8DQrsJuSXSs= +go.mongodb.org/mongo-driver v1.4.4/go.mod h1:WcMNYLx/IlOxLe6JRJiv2uXuCz6zBLndR4SoGjYphSc= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= +golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0 h1:5kGOVHlq0euqwzgTC9Vu15p6fV1Wi0ArVi8da2urnVg= +golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200929083018-4d22bbb62b3c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201210223839-7e3030f88018 h1:XKi8B/gRBuTZN1vU9gFsLMm6zVz5FSCDzm8JYACnjy8= +golang.org/x/sys v0.0.0-20201210223839-7e3030f88018/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= +gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= +gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= +gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/microservices/auth/tests/invitation.go b/microservices/auth/tests/invitation.go index 6cf162b2..c937661b 100644 --- a/microservices/auth/tests/invitation.go +++ b/microservices/auth/tests/invitation.go @@ -2,67 +2,24 @@ package tests import ( "encoding/json" - "errors" - "fmt" "io/ioutil" - "log" "net/http" -) -func testInvitationWorking(baseURL string, suit string) (*invitation, error) { - // Create a new request to invitation new route - req, err := http.NewRequest(http.MethodGet, JoinURL(baseURL, "/invitation/new"), nil) - if err != nil { - log.Println(err) - return nil, err - } - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("GET", "/invitation/new", suit, "Can't call "+JoinURL(baseURL, "/invitation/new")) - return nil, err - } - // Check returned http code - if res.StatusCode != http.StatusOK { - newFailureMessage("GET", "/invitation/new", suit, fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusOK, res.StatusCode)) - return nil, errors.New("") - } - // Read returned body - body, err := ioutil.ReadAll(res.Body) - if err != nil { - log.Println(err) - return nil, err - } - // Parse body data - var bodyData invitation - if err := json.Unmarshal(body, &bodyData); err != nil { - log.Println(err) - return nil, err - } - newSuccessMessage("GET", "/invitation/new", suit) - return &bodyData, nil -} + "github.com/alexandr-io/backend/auth/data" +) -func testDeleteInvitationWorking(baseURL string, userData *user, inv invitation, suit string) error { - // Create a new request to auth route - req, err := http.NewRequest(http.MethodDelete, JoinURL(baseURL, "/invitation/"+inv.Token), nil) +func invitationEndFunction(res *http.Response) error { + // Read response Body + resBody, err := ioutil.ReadAll(res.Body) if err != nil { - log.Println(err) return err } - req.Header.Set("Authorization", "Bearer "+userData.AuthToken) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("DELETE", "/invitation/"+inv.Token, suit, "Can't call "+JoinURL(baseURL, "/invitation/"+inv.Token)) + // Parse response Body + var invitationData data.Invitation + if err := json.Unmarshal(resBody, &invitationData); err != nil { return err } - // Check returned http code - if res.StatusCode != http.StatusNoContent { - newFailureMessage("DELETE", "/invitation/"+inv.Token, suit, fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusNoContent, res.StatusCode)) - return errors.New("") - } - - newSuccessMessage("DELETE", "/invitation/"+inv.Token, suit) + // Store invitation token + invitationToken = invitationData.Token return nil } diff --git a/microservices/auth/tests/login.go b/microservices/auth/tests/login.go index 3a6f10f4..e13cd4e8 100644 --- a/microservices/auth/tests/login.go +++ b/microservices/auth/tests/login.go @@ -1,100 +1,46 @@ package tests import ( - "bytes" "encoding/json" - "errors" - "fmt" "io/ioutil" - "log" "net/http" ) -func testLoginWorking(baseURL string, userData user) (*user, error) { - // Create payload to send to the route - payload := bytes.NewBuffer([]byte("{\"login\": \"" + userData.Email + "\", \"password\": \"test\"}")) - // Create a new request to login route - req, err := http.NewRequest(http.MethodPost, baseURL+"login", payload) - if err != nil { - log.Println(err) - return nil, err - } - req.Header.Set("Content-Type", "application/json") - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("POST", "/login", "Working Suit", "Can't call "+baseURL+"login") - return nil, err - } - // Check returned http code - if res.StatusCode != http.StatusOK { - newFailureMessage("POST", "/login", "Working Suit", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusOK, res.StatusCode)) - return nil, errors.New("") - } - // Read returned body - body, err := ioutil.ReadAll(res.Body) - if err != nil { - log.Println(err) - return nil, err - } - // Parse body data - var bodyData user - if err := json.Unmarshal(body, &bodyData); err != nil { - log.Println(err) - return nil, err - } - newSuccessMessage("POST", "/login", "Working Suit") - return &bodyData, nil +// userLogin is the body parameter given to login a user for test purpose +type userLogin struct { + Login *string `json:"login" validate:"required"` + Password string `json:"password" validate:"required"` } -func testLoginBadRequest(baseURL string) error { - // Create an incorrect payload to send to the route - payload := bytes.NewBuffer([]byte("{\"logi\": \"random\"}")) - // Create a new request to login route - req, err := http.NewRequest(http.MethodPost, baseURL+"login", payload) +func loginEndFunction(res *http.Response) error { + // Read response Body + resBody, err := ioutil.ReadAll(res.Body) if err != nil { - log.Println(err) return err } - req.Header.Set("Content-Type", "application/json") - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("POST", "/login", "Bad Request", "Can't call "+baseURL+"login") + // Parse response Body + var loginData user + if err := json.Unmarshal(resBody, &loginData); err != nil { return err } - // Check returned http code - if res.StatusCode != http.StatusBadRequest { - newFailureMessage("POST", "/login", "Bad Request", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusBadRequest, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("POST", "/login", "Bad Request") + // Store tokens for future uses + authTokenLogin = loginData.AuthToken + refreshTokenLogin = loginData.RefreshToken return nil } -func testLoginNoMatch(baseURL string) error { - // Generate random string for username and email usage - randomName := randStringRunes(12) - // Create payload to send to the route - payload := bytes.NewBuffer([]byte("{\"login\": \"" + randomName + "\", \"password\": \"" + randomName + "\"}")) - // Create a new request to login route - req, err := http.NewRequest(http.MethodPost, baseURL+"login", payload) +func loginLogoutSuiteEndFunction(res *http.Response) error { + // Read response Body + resBody, err := ioutil.ReadAll(res.Body) if err != nil { - log.Println(err) return err } - req.Header.Set("Content-Type", "application/json") - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("POST", "/login", "No Match", "Can't call "+baseURL+"login") + // Parse response Body + var loginData user + if err := json.Unmarshal(resBody, &loginData); err != nil { return err } - // Check returned http code - if res.StatusCode != http.StatusBadRequest { - newFailureMessage("POST", "/login", "No Match", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusBadRequest, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("POST", "/login", "No Match") + // Store tokens for future uses + authTokenLogout = loginData.AuthToken return nil } diff --git a/microservices/auth/tests/logout.go b/microservices/auth/tests/logout.go deleted file mode 100644 index b1d63f90..00000000 --- a/microservices/auth/tests/logout.go +++ /dev/null @@ -1,54 +0,0 @@ -package tests - -import ( - "errors" - "fmt" - "log" - "net/http" -) - -func testLogoutWorking(baseURL string, jwt string) error { - // Create a new request to auth route - req, err := http.NewRequest(http.MethodPost, baseURL+"logout", nil) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("POST", "/logout", "Logout Suit", "Can't call "+baseURL+"logout") - return err - } - // Check returned http code - if res.StatusCode != http.StatusNoContent { - newFailureMessage("POST", "/logout", "Logout Suit", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusNoContent, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("POST", "/logout", "Logout Suit") - return nil -} - -func testAlreadyLogout(baseURL string, jwt string) error { - // Create a new request to auth route - req, err := http.NewRequest(http.MethodPost, baseURL+"logout", nil) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("POST", "/logout", "Logout Suit", "Can't call "+baseURL+"logout") - return err - } - // Check returned http code - if res.StatusCode != http.StatusUnauthorized { - newFailureMessage("POST", "/logout", "Logout Suit", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusUnauthorized, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("POST", "/logout", "Logout Suit") - return nil -} diff --git a/microservices/auth/tests/refresh.go b/microservices/auth/tests/refresh.go index dc954140..6d38588f 100644 --- a/microservices/auth/tests/refresh.go +++ b/microservices/auth/tests/refresh.go @@ -1,73 +1,23 @@ package tests import ( - "bytes" "encoding/json" - "errors" - "fmt" "io/ioutil" - "log" "net/http" ) -func testRefreshWorking(baseURL string, userData *user) (*user, error) { - // Create payload to send to the route - payload := bytes.NewBuffer([]byte("{\"refresh_token\": \"" + userData.RefreshToken + "\"}")) - // Create a new request to refresh route - req, err := http.NewRequest(http.MethodPost, baseURL+"refresh", payload) +func refreshEndFunction(res *http.Response) error { + // Read response Body + resBody, err := ioutil.ReadAll(res.Body) if err != nil { - log.Println(err) - return nil, err - } - req.Header.Set("Content-Type", "application/json") - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("POST", "/refresh", "Working Suit", "Can't call "+baseURL+"refresh") - return nil, err - } - // Check returned http code - if res.StatusCode != http.StatusOK { - newFailureMessage("POST", "/refresh", "Working Suit", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusOK, res.StatusCode)) - return nil, errors.New("") - } - // Read returned body - body, err := ioutil.ReadAll(res.Body) - if err != nil { - log.Println(err) - return nil, err - } - // Parse body data - var bodyData user - if err := json.Unmarshal(body, &bodyData); err != nil { - log.Println(err) - return nil, err - } - newSuccessMessage("POST", "/refresh", "Working Suit") - return &bodyData, nil -} - -func testRefreshInvalidToken(baseURL string) error { - // Create payload to send to the route - payload := bytes.NewBuffer([]byte("{\"refresh_token\": \"randomString\"}")) - // Create a new request to refresh route - req, err := http.NewRequest(http.MethodPost, baseURL+"refresh", payload) - if err != nil { - log.Println(err) return err } - req.Header.Set("Content-Type", "application/json") - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("POST", "/refresh", "Invalid Token", "Can't call "+baseURL+"refresh") + // Parse response Body + var refreshData user + if err := json.Unmarshal(resBody, &refreshData); err != nil { return err } - // Check returned http code - if res.StatusCode != http.StatusUnauthorized { - newFailureMessage("POST", "/refresh", "Invalid Token", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusUnauthorized, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("POST", "/refresh", "Invalid Token") + // Store tokens for future uses + authTokenRefresh = refreshData.AuthToken return nil } diff --git a/microservices/auth/tests/register.go b/microservices/auth/tests/register.go index 83a32bff..d8967f41 100644 --- a/microservices/auth/tests/register.go +++ b/microservices/auth/tests/register.go @@ -1,112 +1,33 @@ package tests import ( - "bytes" "encoding/json" - "errors" - "fmt" "io/ioutil" - "log" - "math/rand" "net/http" ) -var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") - -// randStringRunes generate a random string of specified length -func randStringRunes(length int) string { - b := make([]rune, length) - for i := range b { - b[i] = letterRunes[rand.Intn(len(letterRunes))] - } - return "test-" + string(b) -} - -func testRegisterWorking(baseURL string, inv invitation) (*user, error) { - // Generate random string for username and email usage - randomName := randStringRunes(12) - // Create payload to send to the route - payload := bytes.NewBuffer([]byte("{\"username\": \"" + randomName + "\", \"email\": \"" + randomName + "@test.test\", \"password\": \"test\", \"confirm_password\": \"test\", \"invitation_token\": \"" + inv.Token + "\"}")) - // Create a new request to register route - req, err := http.NewRequest(http.MethodPost, baseURL+"register", payload) - if err != nil { - log.Println(err) - return nil, err - } - req.Header.Set("Content-Type", "application/json") - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("POST", "/register", "Working Suit", "Can't call "+baseURL+"register") - return nil, err - } - // Check returned http code - if res.StatusCode != http.StatusCreated { - newFailureMessage("POST", "/register", "Working Suit", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusCreated, res.StatusCode)) - return nil, errors.New("") - } - // Read returned body - body, err := ioutil.ReadAll(res.Body) - if err != nil { - log.Println(err) - return nil, err - } - // Parse body data - var bodyData user - if err := json.Unmarshal(body, &bodyData); err != nil { - log.Println(err) - return nil, err - } - newSuccessMessage("POST", "/register", "Working Suit") - return &bodyData, nil +// userRegister is the Body parameter given to register a new userOld to the database. +// test copy with email and username set to pointers. +type userRegister struct { + Email *string `json:"email" validate:"required,email"` + Username *string `json:"username" validate:"required"` + Password string `json:"password" validate:"required"` + ConfirmPassword string `json:"confirm_password" validate:"required"` + InvitationToken *string `json:"invitation_token,omitempty" validate:"required,len=10"` } -func testRegisterBadRequest(baseURL string) error { - // Create an incorrect payload to send to the route - payload := bytes.NewBuffer([]byte("{\"userna\": \"random\", \"password\": \"test\"}")) - // Create a new request to register route - req, err := http.NewRequest(http.MethodPost, baseURL+"register", payload) +func registerEndFunction(res *http.Response) error { + // Read response Body + resBody, err := ioutil.ReadAll(res.Body) if err != nil { - log.Println(err) return err } - req.Header.Set("Content-Type", "application/json") - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("POST", "/register", "Bad Request", "Can't call "+baseURL+"register") - return err - } - // Check returned http code - if res.StatusCode != http.StatusBadRequest { - newFailureMessage("POST", "/register", "Bad Request", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusBadRequest, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("POST", "/register", "Bad Request") - return nil -} - -func testRegisterDuplicate(baseURL string, userData user, inv invitation) error { - // Create payload to send to the route - payload := bytes.NewBuffer([]byte("{\"username\": \"" + userData.Username + "\", \"email\": \"" + userData.Email + "\", \"password\": \"test\", \"confirm_password\": \"test\", \"invitation_token\": \"" + inv.Token + "\"}")) - // Create a new request to register route - req, err := http.NewRequest(http.MethodPost, baseURL+"register", payload) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Content-Type", "application/json") - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("POST", "/register", "Duplicate", "Can't call "+baseURL+"register") + // Parse response Body + var registerData user + if err := json.Unmarshal(resBody, ®isterData); err != nil { return err } - // Check returned http code - if res.StatusCode != http.StatusBadRequest { - newFailureMessage("POST", "/register", "Duplicate", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusBadRequest, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("POST", "/register", "Duplicate") + // Store tokens for future uses + authToken = registerData.AuthToken return nil } diff --git a/microservices/auth/tests/resetPassword.go b/microservices/auth/tests/resetPassword.go deleted file mode 100644 index d7294609..00000000 --- a/microservices/auth/tests/resetPassword.go +++ /dev/null @@ -1,86 +0,0 @@ -package tests - -import ( - "bytes" - "errors" - "fmt" - "log" - "net/http" -) - -func testResetPasswordWorking(baseURL string, userData user) error { - // Create payload to send to the route - payload := bytes.NewBuffer([]byte("{\"email\": \"" + userData.Email + "\"}")) - // Create a new request to password reset route - req, err := http.NewRequest(http.MethodPost, JoinURL(baseURL, "password/reset"), payload) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Content-Type", "application/json") - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("POST", "/password/reset", "Working Suit", "Can't call "+JoinURL(baseURL, "password/reset")) - return err - } - // Check returned http code - if res.StatusCode != http.StatusNoContent { - newFailureMessage("POST", "/password/reset", "Working Suit", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusNoContent, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("POST", "/password/reset", "Working Suit") - return nil -} - -func testResetPasswordBadRequest(baseURL string) error { - // Create an incorrect payload to send to the route - payload := bytes.NewBuffer([]byte("{\"email\": \"wrong-email\"}")) - // Create a new request to login route - req, err := http.NewRequest(http.MethodPost, JoinURL(baseURL, "password/reset"), payload) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Content-Type", "application/json") - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("POST", "/password/reset", "Bad Request", "Can't call "+JoinURL(baseURL, "password/reset")) - return err - } - // Check returned http code - if res.StatusCode != http.StatusBadRequest { - newFailureMessage("POST", "/password/reset", "Bad Request", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusBadRequest, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("POST", "/password/reset", "Bad Request") - return nil -} - -func testResetPasswordNoMatch(baseURL string) error { - // Generate random string for username and email usage - randomName := randStringRunes(12) - // Create payload to send to the route - payload := bytes.NewBuffer([]byte("{\"email\": \"" + randomName + "@test.test\"}")) - // Create a new request to login route - req, err := http.NewRequest(http.MethodPost, JoinURL(baseURL, "password/reset"), payload) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Content-Type", "application/json") - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("POST", "/password/reset", "No Match", "Can't call "+JoinURL(baseURL, "password/reset")) - return err - } - // Check returned http code - if res.StatusCode != http.StatusUnauthorized { - newFailureMessage("POST", "/password/reset", "No Match", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusUnauthorized, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("POST", "/password/reset", "No Match") - return nil -} diff --git a/microservices/auth/tests/suite_bad_request.go b/microservices/auth/tests/suite_bad_request.go new file mode 100644 index 00000000..6728f3dd --- /dev/null +++ b/microservices/auth/tests/suite_bad_request.go @@ -0,0 +1,65 @@ +package tests + +import ( + "net/http" + + "github.com/alexandr-io/backend/auth/data" +) + +const badRequestSuite = "Bad Request" + +var badRequestTests = []test{ + { + TestSuite: badRequestSuite, + HTTPMethod: http.MethodPost, + URL: func() string { return "/register" }, + AuthJWT: nil, + Body: userLogin{ + Login: &randomName, + Password: "test", + }, + ExpectedHTTPCode: http.StatusBadRequest, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, + { + TestSuite: badRequestSuite, + HTTPMethod: http.MethodPost, + URL: func() string { return "/login" }, + AuthJWT: nil, + Body: userRegister{ + Username: &randomName, + Email: &randomEmail, + Password: "test", + }, + ExpectedHTTPCode: http.StatusBadRequest, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, + { + TestSuite: badRequestSuite, + HTTPMethod: http.MethodPost, + URL: func() string { return "/password/reset" }, + AuthJWT: &authToken, + Body: data.UserSendResetPasswordEmail{ + Email: "wrong-email", + }, + ExpectedHTTPCode: http.StatusBadRequest, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, +} + +// ExecAuthBadRequestTests execute bad request auth tests. +func ExecAuthBadRequestTests(environment string, jwt string) error { + baseURL, err := getBaseURL(environment) + if err != nil { + return err + } + authToken = jwt + + if err := execTestSuite(baseURL, badRequestTests); err != nil { + return err + } + return nil +} diff --git a/microservices/auth/tests/suite_basic.go b/microservices/auth/tests/suite_basic.go new file mode 100644 index 00000000..878fe265 --- /dev/null +++ b/microservices/auth/tests/suite_basic.go @@ -0,0 +1,88 @@ +package tests + +import ( + "math/rand" + "net/http" + "time" + + "github.com/alexandr-io/backend/tests/itgmtod" +) + +const basicSuite = "Basic" + +var ( + randomName string + randomEmail string + invitationToken string + authToken string +) + +var basicTests = []test{ + { + TestSuite: basicSuite, + HTTPMethod: http.MethodGet, + URL: func() string { return "/invitation/new" }, + AuthJWT: nil, + Body: nil, + ExpectedHTTPCode: http.StatusOK, + ExpectedResponse: nil, + CustomEndFunc: invitationEndFunction, + }, + { + TestSuite: basicSuite, + HTTPMethod: http.MethodPost, + URL: func() string { return "/register" }, + AuthJWT: nil, + Body: userRegister{ + Email: &randomEmail, + Username: &randomName, + Password: "test", + ConfirmPassword: "test", + InvitationToken: &invitationToken, + }, + ExpectedHTTPCode: http.StatusCreated, + ExpectedResponse: user{ + Username: &randomName, + Email: &randomEmail, + }, + CustomEndFunc: registerEndFunction, + }, + { + TestSuite: basicSuite, + HTTPMethod: http.MethodDelete, + URL: func() string { return "/invitation/" + invitationToken }, + AuthJWT: &authToken, + Body: nil, + ExpectedHTTPCode: http.StatusNoContent, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, + { + TestSuite: basicSuite, + HTTPMethod: http.MethodGet, + URL: func() string { return "/auth" }, + AuthJWT: &authToken, + Body: nil, + ExpectedHTTPCode: http.StatusOK, + ExpectedResponse: struct { + Username *string `json:"username"` + }{Username: &randomName}, + CustomEndFunc: nil, + }, +} + +// ExecAuthBasicTests execute basic auth tests. Must be called first every time +func ExecAuthBasicTests(environment string) (string, error) { + rand.Seed(time.Now().UnixNano()) + + baseURL, err := getBaseURL(environment) + if err != nil { + return "", err + } + randomName = itgmtod.RandStringRunes(12) + randomEmail = randomName + "@test.test" + if err := execTestSuite(baseURL, basicTests); err != nil { + return "", err + } + return authToken, nil +} diff --git a/microservices/auth/tests/suite_incorrect.go b/microservices/auth/tests/suite_incorrect.go new file mode 100644 index 00000000..6993b91e --- /dev/null +++ b/microservices/auth/tests/suite_incorrect.go @@ -0,0 +1,115 @@ +package tests + +import "net/http" + +const ( + duplicateSuite = "Duplicate" + noMatchSuite = "No Match" + invalidTokenSuite = "Invalid Token" +) + +var wrongToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" + +var incorrectTests = []test{ + { + TestSuite: duplicateSuite, + HTTPMethod: http.MethodGet, + URL: func() string { return "/invitation/new" }, + AuthJWT: nil, + Body: nil, + ExpectedHTTPCode: http.StatusOK, + ExpectedResponse: nil, + CustomEndFunc: invitationEndFunction, + }, + { + TestSuite: duplicateSuite, + HTTPMethod: http.MethodPost, + URL: func() string { return "/register" }, + AuthJWT: nil, + Body: userRegister{ + Email: &randomEmail, + Username: &randomName, + Password: "test", + ConfirmPassword: "test", + InvitationToken: &invitationToken, + }, + ExpectedHTTPCode: http.StatusBadRequest, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, + { + TestSuite: duplicateSuite, + HTTPMethod: http.MethodDelete, + URL: func() string { return "/invitation/" + invitationToken }, + AuthJWT: &authToken, + Body: nil, + ExpectedHTTPCode: http.StatusNoContent, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, + { + TestSuite: noMatchSuite, + HTTPMethod: http.MethodPost, + URL: func() string { return "/login" }, + AuthJWT: nil, + Body: userLogin{ + Login: &randomName, + Password: "wrong-password", + }, + ExpectedHTTPCode: http.StatusBadRequest, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, + { + TestSuite: noMatchSuite, + HTTPMethod: http.MethodPost, + URL: func() string { return "/password/reset" }, + AuthJWT: &authToken, + Body: struct { + Email string `json:"email"` + }{ + Email: "wrong-email@test.test", + }, + ExpectedHTTPCode: http.StatusUnauthorized, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, + { + TestSuite: invalidTokenSuite, + HTTPMethod: http.MethodGet, + URL: func() string { return "/auth" }, + AuthJWT: &wrongToken, + Body: nil, + ExpectedHTTPCode: http.StatusUnauthorized, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, + { + TestSuite: invalidTokenSuite, + HTTPMethod: http.MethodPost, + URL: func() string { return "/refresh" }, + AuthJWT: &wrongToken, + Body: struct { + RefreshToken string `json:"refresh_token"` + }{ + RefreshToken: "wrong-token", + }, + ExpectedHTTPCode: http.StatusUnauthorized, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, +} + +// ExecAuthIncorrectTests execute incorrect auth tests. +func ExecAuthIncorrectTests(environment string, jwt string) error { + baseURL, err := getBaseURL(environment) + if err != nil { + return err + } + authToken = jwt + + if err := execTestSuite(baseURL, incorrectTests); err != nil { + return err + } + return nil +} diff --git a/microservices/auth/tests/suite_logout.go b/microservices/auth/tests/suite_logout.go new file mode 100644 index 00000000..de83d737 --- /dev/null +++ b/microservices/auth/tests/suite_logout.go @@ -0,0 +1,70 @@ +package tests + +import "net/http" + +const logoutSuite = "Logout" + +var authTokenLogout string + +var logoutTests = []test{ + { + TestSuite: logoutSuite, + HTTPMethod: http.MethodPost, + URL: func() string { return "/login" }, + AuthJWT: nil, + Body: userLogin{ + Login: &randomName, + Password: "test", + }, + ExpectedHTTPCode: http.StatusOK, + ExpectedResponse: user{ + Username: &randomName, + Email: &randomEmail, + }, + CustomEndFunc: loginLogoutSuiteEndFunction, + }, + { + TestSuite: logoutSuite, + HTTPMethod: http.MethodPost, + URL: func() string { return "/logout" }, + AuthJWT: &authTokenLogout, + Body: nil, + ExpectedHTTPCode: http.StatusNoContent, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, + { + TestSuite: logoutSuite, + HTTPMethod: http.MethodPost, + URL: func() string { return "/logout" }, + AuthJWT: &authTokenLogout, + Body: nil, + ExpectedHTTPCode: http.StatusUnauthorized, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, + { + TestSuite: logoutSuite, + HTTPMethod: http.MethodGet, + URL: func() string { return "/auth" }, + AuthJWT: &authTokenLogout, + Body: nil, + ExpectedHTTPCode: http.StatusUnauthorized, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, +} + +// ExecAuthLogoutTests execute logout auth tests. +func ExecAuthLogoutTests(environment string, jwt string) error { + baseURL, err := getBaseURL(environment) + if err != nil { + return err + } + authToken = jwt + + if err := execTestSuite(baseURL, logoutTests); err != nil { + return err + } + return nil +} diff --git a/microservices/auth/tests/suite_working.go b/microservices/auth/tests/suite_working.go new file mode 100644 index 00000000..2e700348 --- /dev/null +++ b/microservices/auth/tests/suite_working.go @@ -0,0 +1,103 @@ +package tests + +import ( + "net/http" +) + +const workingSuite = "Working" + +var ( + authTokenLogin string + refreshTokenLogin string + authTokenRefresh string +) + +var workingTests = []test{ + { + TestSuite: workingSuite, + HTTPMethod: http.MethodPost, + URL: func() string { return "/login" }, + AuthJWT: nil, + Body: userLogin{ + Login: &randomName, + Password: "test", + }, + ExpectedHTTPCode: http.StatusOK, + ExpectedResponse: user{ + Username: &randomName, + Email: &randomEmail, + }, + CustomEndFunc: loginEndFunction, + }, + { + TestSuite: workingSuite, + HTTPMethod: http.MethodGet, + URL: func() string { return "/auth" }, + AuthJWT: &authTokenLogin, + Body: nil, + ExpectedHTTPCode: http.StatusOK, + ExpectedResponse: struct { + Username *string `json:"username"` + }{Username: &randomName}, + CustomEndFunc: nil, + }, + { + TestSuite: workingSuite, + HTTPMethod: http.MethodPost, + URL: func() string { return "/refresh" }, + AuthJWT: &authTokenLogin, + Body: struct { + RefreshToken *string `json:"refresh_token"` + }{ + RefreshToken: &refreshTokenLogin, + }, + ExpectedHTTPCode: http.StatusOK, + ExpectedResponse: user{ + Username: &randomName, + Email: &randomEmail, + }, + CustomEndFunc: refreshEndFunction, + }, + { + TestSuite: workingSuite, + HTTPMethod: http.MethodGet, + URL: func() string { return "/auth" }, + AuthJWT: &authTokenRefresh, + Body: nil, + ExpectedHTTPCode: http.StatusOK, + ExpectedResponse: struct { + Username *string `json:"username"` + }{ + Username: &randomName, + }, + CustomEndFunc: nil, + }, + { + TestSuite: workingSuite, + HTTPMethod: http.MethodPost, + URL: func() string { return "/password/reset" }, + AuthJWT: &authToken, + Body: struct { + Email *string `json:"email"` + }{ + Email: &randomEmail, + }, + ExpectedHTTPCode: http.StatusNoContent, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, +} + +// ExecAuthWorkingTests execute working auth tests. +func ExecAuthWorkingTests(environment string, jwt string) error { + baseURL, err := getBaseURL(environment) + if err != nil { + return err + } + authToken = jwt + + if err := execTestSuite(baseURL, workingTests); err != nil { + return err + } + return nil +} diff --git a/microservices/auth/tests/tests.go b/microservices/auth/tests/tests.go index 27cd0eb7..41cd6aae 100644 --- a/microservices/auth/tests/tests.go +++ b/microservices/auth/tests/tests.go @@ -1,53 +1,62 @@ package tests import ( + "bytes" "errors" "fmt" - "math/rand" - "path" - "strings" - "time" + "net/http" - "github.com/fatih/color" + "github.com/alexandr-io/backend/tests/itgmtod" ) -var ( - green = color.New(color.FgGreen).SprintFunc() - red = color.New(color.FgRed).SprintFunc() - cyan = color.New(color.FgCyan).SprintfFunc() - magenta = color.New(color.FgHiMagenta).SprintfFunc() - backCyan = color.New(color.BgCyan).Add(color.FgBlack).SprintfFunc() -) - -// ExecAuthTests execute integration tests of auth MS routes -func ExecAuthTests(environment string) (string, error) { - rand.Seed(time.Now().UnixNano()) - var errorHappened = false - - baseURL, err := getBaseURL(environment) - if err != nil { - return "", err - } - - userData, err := workingTestSuit(baseURL) - if err != nil { - errorHappened = true - } - if err = badRequestTests(baseURL); err != nil { - errorHappened = true - } - if err = incorrectTests(baseURL, *userData); err != nil { - errorHappened = true - } - userData, err = logoutTests(baseURL, userData) - if err != nil { - errorHappened = true - } +type test struct { + TestSuite string + HTTPMethod string + URL func() string + AuthJWT *string + Body interface{} + ExpectedHTTPCode int + ExpectedResponse interface{} + CustomEndFunc func(*http.Response) error +} - if errorHappened { - return "", errors.New("error in auth tests") +func execTestSuite(baseURL string, testSuite []test) error { + for _, currentTest := range testSuite { + url := itgmtod.JoinURL(baseURL, currentTest.URL()) + body, err := itgmtod.MarshallBody(currentTest.Body) + if err != nil { + newFailureMessage(currentTest.HTTPMethod, url, currentTest.TestSuite, err.Error()) + return fmt.Errorf("error in " + currentTest.TestSuite + " test suite") + } + + // Test the route + res, err := itgmtod.TestRoute( + currentTest.HTTPMethod, + url, + currentTest.AuthJWT, + bytes.NewReader(body), + currentTest.ExpectedHTTPCode) + if err != nil { + newFailureMessage(currentTest.HTTPMethod, currentTest.URL(), currentTest.TestSuite, err.Error()) + return fmt.Errorf("error in " + currentTest.TestSuite + " test suite") + } + // Check expected response Body + if currentTest.ExpectedResponse != nil { + if err := itgmtod.CheckExpectedResponse(res, currentTest.ExpectedResponse); err != nil { + newFailureMessage(currentTest.HTTPMethod, currentTest.URL(), currentTest.TestSuite, err.Error()) + return fmt.Errorf("error in " + currentTest.TestSuite + " test suite") + } + } + // Call end function + if currentTest.CustomEndFunc != nil { + if err := currentTest.CustomEndFunc(res); err != nil { + newFailureMessage(currentTest.HTTPMethod, currentTest.URL(), currentTest.TestSuite, err.Error()) + return fmt.Errorf("error in " + currentTest.TestSuite + " test suite") + } + } + newSuccessMessage(currentTest.HTTPMethod, currentTest.URL(), currentTest.TestSuite) } - return userData.AuthToken, nil + return nil } func getBaseURL(environment string) (string, error) { @@ -63,141 +72,10 @@ func getBaseURL(environment string) (string, error) { } } -func workingTestSuit(baseURL string) (*user, error) { - inv, err := testInvitationWorking(baseURL, "Working Suit") - if err != nil { - return nil, err - } - userData, err := testRegisterWorking(baseURL, *inv) - if err != nil { - return nil, err - } - if err := testDeleteInvitationWorking(baseURL, userData, *inv, "Working Suit"); err != nil { - return nil, err - } - if err := testAuthWorking(baseURL, userData); err != nil { - return nil, err - } - - userDataLogin, err := testLoginWorking(baseURL, *userData) - if err != nil { - return nil, err - } - if err := testAuthWorking(baseURL, userDataLogin); err != nil { - return nil, err - } - userDataRefresh, err := testRefreshWorking(baseURL, userDataLogin) - if err != nil { - return nil, err - } - if err := testAuthWorking(baseURL, userDataRefresh); err != nil { - return nil, err - } - if err := testResetPasswordWorking(baseURL, *userData); err != nil { - return nil, err - } - - return userData, nil -} - -func logoutTests(baseURL string, userData *user) (*user, error) { - if err := testLogoutWorking(baseURL, userData.AuthToken); err != nil { - return nil, err - } - if err := testAlreadyLogout(baseURL, userData.AuthToken); err != nil { - return nil, err - } - if err := testAuthLogoutToken(baseURL, userData.AuthToken); err != nil { - return nil, err - } - userData, err := testLoginWorking(baseURL, *userData) - if err != nil { - return nil, err - } - return userData, nil -} - -func badRequestTests(baseURL string) error { - if err := testRegisterBadRequest(baseURL); err != nil { - return err - } - if err := testLoginBadRequest(baseURL); err != nil { - return err - } - if err := testResetPasswordBadRequest(baseURL); err != nil { - return err - } - return nil -} - -func incorrectTests(baseURL string, userData user) error { - inv, err := testInvitationWorking(baseURL, "Duplicate") - if err != nil { - return err - } - if err := testRegisterDuplicate(baseURL, userData, *inv); err != nil { - return err - } - if err := testDeleteInvitationWorking(baseURL, &userData, *inv, "Duplicate"); err != nil { - return err - } - if err := testLoginNoMatch(baseURL); err != nil { - return err - } - if err := testResetPasswordNoMatch(baseURL); err != nil { - return err - } - if err := testAuthInvalidToken(baseURL); err != nil { - return err - } - if err := testRefreshInvalidToken(baseURL); err != nil { - return err - } - return nil -} - func newSuccessMessage(verb string, route string, test string) { - coloredVerb := verb - switch verb { - case "GET": - coloredVerb = green(verb) - break - case "POST": - coloredVerb = cyan(verb) - break - case "PUT": - coloredVerb = magenta(verb) - break - case "DELETE": - coloredVerb = red(verb) - break - } - - fmt.Printf("%s\t %s\t%-35s%-14s%-5s\n", backCyan("[AUTH]"), coloredVerb, route, test, green("✓")) + itgmtod.NewSuccessMessage(itgmtod.BackCyan("[AUTH]"), verb, route, test) } func newFailureMessage(verb string, route string, test string, message string) { - coloredVerb := verb - switch verb { - case "GET": - coloredVerb = green(verb) - break - case "POST": - coloredVerb = cyan(verb) - break - case "PUT": - coloredVerb = magenta(verb) - break - case "DELETE": - coloredVerb = red(verb) - break - } - - fmt.Printf("%s\t %s\t%-35s%-14s%-5s\t%s\n", backCyan("[AUTH]"), coloredVerb, route, test, red("✗"), message) -} - -// JoinURL Join a base url with a route path -func JoinURL(base string, paths ...string) string { - p := path.Join(paths...) - return fmt.Sprintf("%s/%s", strings.TrimRight(base, "/"), strings.TrimLeft(p, "/")) + itgmtod.NewFailureMessage(itgmtod.BackCyan("[AUTH]"), verb, route, test, message) } diff --git a/microservices/library/app/Dockerfile b/microservices/library/app/Dockerfile index 511871b1..657efed8 100644 --- a/microservices/library/app/Dockerfile +++ b/microservices/library/app/Dockerfile @@ -14,6 +14,7 @@ ENV GO111MODULE=on \ WORKDIR /app COPY go.mod go.sum ./ +COPY data/go.mod data/go.sum ./ RUN go mod download COPY . ./ diff --git a/microservices/library/app/data/go.mod b/microservices/library/app/data/go.mod new file mode 100644 index 00000000..f9cfa2ca --- /dev/null +++ b/microservices/library/app/data/go.mod @@ -0,0 +1,10 @@ +module github.com/alexandr-io/backend/library/data + +go 1.15 + +require ( + github.com/alexandr-io/berrors v1.2.7 + github.com/confluentinc/confluent-kafka-go v1.5.2 + github.com/gofiber/fiber/v2 v2.3.3 + go.mongodb.org/mongo-driver v1.4.5 +) diff --git a/microservices/library/app/data/go.sum b/microservices/library/app/data/go.sum new file mode 100644 index 00000000..b6e8d6ee --- /dev/null +++ b/microservices/library/app/data/go.sum @@ -0,0 +1,152 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/alexandr-io/berrors v1.2.7 h1:xBN0GImN4yfMriJjmW1ux9h86KGdSe06L5jFsMZURqg= +github.com/alexandr-io/berrors v1.2.7/go.mod h1:kZn7MFDwwMJkbRGr+LPyZh2lhg8Tfn+mZLIwC2JknQk= +github.com/andybalholm/brotli v1.0.0 h1:7UCwP93aiSfvWpapti8g88vVVGp2qqtGyePsSuDafo4= +github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= +github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48= +github.com/confluentinc/confluent-kafka-go v1.5.2 h1:l+qt+a0Okmq0Bdr1P55IX4fiwFJyg0lZQmfHkAFkv7E= +github.com/confluentinc/confluent-kafka-go v1.5.2/go.mod h1:u2zNLny2xq+5rWeTQjFHbDzzNuba4P1vo31r9r4uAdg= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= +github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= +github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= +github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= +github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= +github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= +github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY= +github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg= +github.com/gobuffalo/envy v1.6.15/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= +github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= +github.com/gobuffalo/flect v0.1.0/go.mod h1:d2ehjJqGOH/Kjqcoz+F7jHTBbmDb38yXA598Hb50EGs= +github.com/gobuffalo/flect v0.1.1/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI= +github.com/gobuffalo/flect v0.1.3/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI= +github.com/gobuffalo/genny v0.0.0-20190329151137-27723ad26ef9/go.mod h1:rWs4Z12d1Zbf19rlsn0nurr75KqhYp52EAGGxTbBhNk= +github.com/gobuffalo/genny v0.0.0-20190403191548-3ca520ef0d9e/go.mod h1:80lIj3kVJWwOrXWWMRzzdhW3DsrdjILVil/SFKBzF28= +github.com/gobuffalo/genny v0.1.0/go.mod h1:XidbUqzak3lHdS//TPu2OgiFB+51Ur5f7CSnXZ/JDvo= +github.com/gobuffalo/genny v0.1.1/go.mod h1:5TExbEyY48pfunL4QSXxlDOmdsD44RRq4mVZ0Ex28Xk= +github.com/gobuffalo/gitgen v0.0.0-20190315122116-cc086187d211/go.mod h1:vEHJk/E9DmhejeLeNt7UVvlSGv3ziL+djtTr3yyzcOw= +github.com/gobuffalo/gogen v0.0.0-20190315121717-8f38393713f5/go.mod h1:V9QVDIxsgKNZs6L2IYiGR8datgMhB577vzTDqypH360= +github.com/gobuffalo/gogen v0.1.0/go.mod h1:8NTelM5qd8RZ15VjQTFkAW6qOMx5wBbW4dSCS3BY8gg= +github.com/gobuffalo/gogen v0.1.1/go.mod h1:y8iBtmHmGc4qa3urIyo1shvOD8JftTtfcKi+71xfDNE= +github.com/gobuffalo/logger v0.0.0-20190315122211-86e12af44bc2/go.mod h1:QdxcLw541hSGtBnhUc4gaNIXRjiDppFGaDqzbrBd3v8= +github.com/gobuffalo/mapi v1.0.1/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc= +github.com/gobuffalo/mapi v1.0.2/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc= +github.com/gobuffalo/packd v0.0.0-20190315124812-a385830c7fc0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4= +github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4= +github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ= +github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0= +github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw= +github.com/gofiber/fiber/v2 v2.0.6/go.mod h1:VyfrlfcUCW0TcO5uaLHVlxZ8N25BgwnP6YjkzJmJP24= +github.com/gofiber/fiber/v2 v2.3.3 h1:nsjc9TfCl+ojXgEAu+uAT1Le7iQtZJ+Gfb/ox6+BM4w= +github.com/gofiber/fiber/v2 v2.3.3/go.mod h1:f8BRRIMjMdRyt2qmJ/0Sea3j3rwwfufPrh9WNBRiVZ0= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= +github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4= +github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= +github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= +github.com/klauspost/compress v1.10.7 h1:7rix8v8GpI3ZBb0nSozFRgbtXKv+hOe+qfEpZqybrAg= +github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +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/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= +github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE= +github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasthttp v1.16.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA= +github.com/valyala/fasthttp v1.18.0 h1:IV0DdMlatq9QO1Cr6wGJPVW1sV1Q8HvZXAIcjorylyM= +github.com/valyala/fasthttp v1.18.0/go.mod h1:jjraHZVbKOXftJfsOYoAjaeygpj5hr8ermTRJNroD7A= +github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a h1:0R4NLDRDZX6JcmhJgXi5E4b8Wg84ihbmUKp/GvSPEzc= +github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= +github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= +github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= +go.mongodb.org/mongo-driver v1.4.5 h1:TLtO+iD8krabXxvY1F1qpBOHgOxhLWR7XsT7kQeRmMY= +go.mongodb.org/mongo-driver v1.4.5/go.mod h1:WcMNYLx/IlOxLe6JRJiv2uXuCz6zBLndR4SoGjYphSc= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= +golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200929083018-4d22bbb62b3c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201210223839-7e3030f88018 h1:XKi8B/gRBuTZN1vU9gFsLMm6zVz5FSCDzm8JYACnjy8= +golang.org/x/sys v0.0.0-20201210223839-7e3030f88018/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= +gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= +gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= +gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/microservices/library/tests/book_create.go b/microservices/library/tests/book_create.go index aaa06265..7db2421b 100644 --- a/microservices/library/tests/book_create.go +++ b/microservices/library/tests/book_create.go @@ -1,76 +1,35 @@ package tests import ( - "bytes" "encoding/json" - "errors" - "fmt" "io/ioutil" - "log" "net/http" + + "github.com/alexandr-io/backend/library/data" ) -func testBookCreateWorking(baseURL string, jwt string, libraryResponse libraryList) (*book, error) { - // Create a new request to book post route - payload := bytes.NewBuffer([]byte("{\"title\": \"The book\", \"author\": \"The author\", \"description\": \"The description\", \"tags\": [\"The 1st tag\", \"the 2nd tag\"], \"library_id\": \"" + libraryResponse.ID + "\"}")) - req, err := http.NewRequest(http.MethodPost, baseURL+"book", payload) - if err != nil { - log.Println(err) - return nil, err - } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("POST", "/book", "Working Suit", "Can't call "+baseURL+"book") - return nil, err - } - // Check returned http code - if res.StatusCode != http.StatusCreated { - newFailureMessage("POST", "/book", "Working Suit", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusCreated, res.StatusCode)) - return nil, errors.New("") - } - // Read returned body - body, err := ioutil.ReadAll(res.Body) - if err != nil { - log.Println(err) - newFailureMessage("POST", "/book", "Working Suit", "Can't read response body") - return nil, err - } - // Parse body data - var bodyData book - if err := json.Unmarshal(body, &bodyData); err != nil { - log.Println(err) - newFailureMessage("POST", "/book", "Working Suit", "Can't unmarshal json") - return nil, err - } - newSuccessMessage("POST", "/book", "Working Suit") - return &bodyData, nil +// bookCreation defines the structure of an API book for creation. copy for test +type bookCreation struct { + Title string `json:"title,omitempty"` + Author string `json:"author,omitempty"` + Publisher string `json:"publisher,omitempty"` + Description string `json:"description,omitempty"` + Tags []string `json:"tags,omitempty"` + LibraryID *string `json:"library_id,omitempty"` } -func testBookCreateBadRequest(baseURL string, jwt string) error { - // Create payload to send to the route - payload := bytes.NewBuffer([]byte("{\"title\": 42, \"library_id\": \"library_does_not_exist\"}")) - // Create a new request to user update route - req, err := http.NewRequest(http.MethodPost, baseURL+"book", payload) +// BookCreateEndFunction is a function called at the end of a book creation test +func BookCreateEndFunction(res *http.Response) error { + // Read response Body + resBody, err := ioutil.ReadAll(res.Body) if err != nil { - log.Println(err) return err } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("POST", "/book", "Bad Request", "Can't call "+baseURL+"book") + // Parse response Body + var bookData data.Book + if err := json.Unmarshal(resBody, &bookData); err != nil { return err } - // Check returned http code - if res.StatusCode != http.StatusBadRequest { - newFailureMessage("POST", "/book", "Bad Request", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusBadRequest, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("POST", "/book", "Bad Request") + bookID = bookData.ID.String() return nil } diff --git a/microservices/library/tests/book_delete.go b/microservices/library/tests/book_delete.go deleted file mode 100644 index bab9a28e..00000000 --- a/microservices/library/tests/book_delete.go +++ /dev/null @@ -1,60 +0,0 @@ -package tests - -import ( - "bytes" - "errors" - "fmt" - "log" - "net/http" -) - -func testBookDeleteWorking(baseURL string, jwt string, libraryResponse libraryList, bookResponse *book) error { - // Create a new request to book delete route - payload := bytes.NewBuffer([]byte("{\"book_id\": \"" + bookResponse.ID + "\", \"library_id\": \"" + libraryResponse.ID + "\"}")) - req, err := http.NewRequest(http.MethodDelete, baseURL+"book", payload) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("DELETE", "/book", "Working Suit", "Can't call "+baseURL+"book") - return err - } - // Check returned http code - if res.StatusCode != http.StatusNoContent { - newFailureMessage("DELETE", "/book", "Working Suit", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusNoContent, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("DELETE", "/book", "Working Suit") - return nil -} - -func testBookDeleteBadRequest(baseURL string, jwt string) error { - // Create payload to send to the route - payload := bytes.NewBuffer([]byte("{\"book_id\": 42, \"library_id\": 42}")) - // Create a new request to user update route - req, err := http.NewRequest(http.MethodDelete, baseURL+"book", payload) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("DELETE", "/book", "Bad Request", "Can't call "+baseURL+"book") - return err - } - // Check returned http code - if res.StatusCode != http.StatusBadRequest { - newFailureMessage("DELETE", "/book", "Bad Request", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusBadRequest, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("DELETE", "/book", "Bad Request") - return nil -} diff --git a/microservices/library/tests/book_get.go b/microservices/library/tests/book_get.go index 6f74ae3c..b3c9ab6e 100644 --- a/microservices/library/tests/book_get.go +++ b/microservices/library/tests/book_get.go @@ -1,76 +1,7 @@ package tests -import ( - "bytes" - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "log" - "net/http" -) - -func testBookGetWorking(baseURL string, jwt string, libraryResponse libraryList, bookResponse *book) (*book, error) { - // Create a new request to book get route - payload := bytes.NewBuffer([]byte("{\"book_id\": \"" + bookResponse.ID + "\", \"library_id\": \"" + libraryResponse.ID + "\"}")) - req, err := http.NewRequest(http.MethodPut, baseURL+"book", payload) - if err != nil { - log.Println(err) - return nil, err - } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("PUT", "/book", "Working Suit", "Can't call "+baseURL+"book") - return nil, err - } - // Check returned http code - if res.StatusCode != http.StatusOK { - newFailureMessage("PUT", "/book", "Working Suit", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusOK, res.StatusCode)) - return nil, errors.New("") - } - // Read returned body - body, err := ioutil.ReadAll(res.Body) - if err != nil { - log.Println(err) - newFailureMessage("PUT", "/book", "Working Suit", "Can't read response body") - return nil, err - } - // Parse body data - var bodyData book - if err := json.Unmarshal(body, &bodyData); err != nil { - log.Println(err) - newFailureMessage("PUT", "/book", "Working Suit", "Can't unmarshal json") - return nil, err - } - newSuccessMessage("PUT", "/book", "Working Suit") - return &bodyData, nil -} - -func testBookGetBadRequest(baseURL string, jwt string) error { - // Create payload to send to the route - payload := bytes.NewBuffer([]byte("{\"book_id\": 42, \"library_id\": 42}")) - // Create a new request to user update route - req, err := http.NewRequest(http.MethodPut, baseURL+"book", payload) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("PUT", "/book", "Bad Request", "Can't call "+baseURL+"book") - return err - } - // Check returned http code - if res.StatusCode != http.StatusBadRequest { - newFailureMessage("PUT", "/book", "Bad Request", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusBadRequest, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("PUT", "/book", "Bad Request") - return nil +// bookRetrieve defines the structure of an API book retrieval. Copy for test +type bookRetrieve struct { + ID *string `json:"book_id,omitempty"` + LibraryID *string `json:"library_id,omitempty"` } diff --git a/microservices/library/tests/book_update.go b/microservices/library/tests/book_update.go deleted file mode 100644 index 363bfab9..00000000 --- a/microservices/library/tests/book_update.go +++ /dev/null @@ -1,51 +0,0 @@ -package tests - -import ( - "bytes" - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "log" - "net/http" -) - -func testBookUpdateWorking(baseURL string, jwt string, libraryResponse libraryList, bookResponse *book) (*book, error) { - // Create a new request to book post route - payload := bytes.NewBuffer([]byte("{\"title\": \"The book was updated\"}")) - req, err := http.NewRequest(http.MethodPost, baseURL+"library/"+libraryResponse.ID+"/book/"+bookResponse.ID, payload) - if err != nil { - log.Println(err) - return nil, err - } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("POST", "/library/:library_id/book/:book_id", "Working Suit", "Can't call "+baseURL+"/library/"+libraryResponse.ID+"/book/"+bookResponse.ID) - return nil, err - } - // Check returned http code - if res.StatusCode != http.StatusOK { - newFailureMessage("POST", "/library/:library_id/book/:book_id", "Working Suit", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusOK, res.StatusCode)) - return nil, errors.New("") - } - // Read returned body - body, err := ioutil.ReadAll(res.Body) - if err != nil { - log.Println(err) - newFailureMessage("POST", "/library/:library_id/book/:book_id", "Working Suit", "Can't read response body") - return nil, err - } - // Parse body data - var bodyData book - if err := json.Unmarshal(body, &bodyData); err != nil { - log.Println(err) - log.Println(body) - newFailureMessage("POST", "/library/:library_id/book/:book_id", "Working Suit", "Can't unmarshal json") - return nil, err - } - newSuccessMessage("POST", "/library/:library_id/book/:book_id", "Working Suit") - return &bodyData, nil -} diff --git a/microservices/library/tests/data.go b/microservices/library/tests/data.go deleted file mode 100644 index 4e38f276..00000000 --- a/microservices/library/tests/data.go +++ /dev/null @@ -1,25 +0,0 @@ -package tests - -type book struct { - ID string `json:"id"` - Description string `json:"description"` - Title string `json:"title"` - Author string `json:"author"` - Publisher string `json:"publisher"` - Tags []string `json:"tags"` -} - -type library struct { - Name string `json:"name"` - Description string `json:"description"` - Books []book `json:"books"` -} - -type libraryList struct { - Name string `json:"name"` - ID string `json:"id"` -} - -type libraries struct { - Libraries []libraryList `json:"libraries"` -} diff --git a/microservices/library/tests/go.mod b/microservices/library/tests/go.mod index ff372bfe..5343b7ca 100644 --- a/microservices/library/tests/go.mod +++ b/microservices/library/tests/go.mod @@ -2,4 +2,15 @@ module github.com/alexandr-io/backend/library/tests go 1.15 -require github.com/fatih/color v1.10.0 +replace github.com/alexandr-io/backend/tests/itgmtod => ./../../../tests/itgmtod + +replace github.com/alexandr-io/backend/library/data => ../app/data + +require ( + github.com/alexandr-io/backend/library/data v0.0.0-00010101000000-000000000000 + github.com/alexandr-io/backend/tests/itgmtod v0.0.0-00010101000000-000000000000 + github.com/alexandr-io/berrors v1.2.7 // indirect + github.com/confluentinc/confluent-kafka-go v1.5.2 // indirect + github.com/gofiber/fiber/v2 v2.3.3 // indirect + go.mongodb.org/mongo-driver v1.4.5 // indirect +) diff --git a/microservices/library/tests/go.sum b/microservices/library/tests/go.sum index 07dbfb52..f022958e 100644 --- a/microservices/library/tests/go.sum +++ b/microservices/library/tests/go.sum @@ -1,5 +1,161 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/alexandr-io/berrors v1.2.7 h1:xBN0GImN4yfMriJjmW1ux9h86KGdSe06L5jFsMZURqg= +github.com/alexandr-io/berrors v1.2.7/go.mod h1:kZn7MFDwwMJkbRGr+LPyZh2lhg8Tfn+mZLIwC2JknQk= +github.com/andybalholm/brotli v1.0.0 h1:7UCwP93aiSfvWpapti8g88vVVGp2qqtGyePsSuDafo4= +github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= +github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48= +github.com/confluentinc/confluent-kafka-go v1.5.2 h1:l+qt+a0Okmq0Bdr1P55IX4fiwFJyg0lZQmfHkAFkv7E= +github.com/confluentinc/confluent-kafka-go v1.5.2/go.mod h1:u2zNLny2xq+5rWeTQjFHbDzzNuba4P1vo31r9r4uAdg= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= +github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= +github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= +github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= +github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= +github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= +github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= +github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY= +github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg= +github.com/gobuffalo/envy v1.6.15/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= +github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= +github.com/gobuffalo/flect v0.1.0/go.mod h1:d2ehjJqGOH/Kjqcoz+F7jHTBbmDb38yXA598Hb50EGs= +github.com/gobuffalo/flect v0.1.1/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI= +github.com/gobuffalo/flect v0.1.3/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI= +github.com/gobuffalo/genny v0.0.0-20190329151137-27723ad26ef9/go.mod h1:rWs4Z12d1Zbf19rlsn0nurr75KqhYp52EAGGxTbBhNk= +github.com/gobuffalo/genny v0.0.0-20190403191548-3ca520ef0d9e/go.mod h1:80lIj3kVJWwOrXWWMRzzdhW3DsrdjILVil/SFKBzF28= +github.com/gobuffalo/genny v0.1.0/go.mod h1:XidbUqzak3lHdS//TPu2OgiFB+51Ur5f7CSnXZ/JDvo= +github.com/gobuffalo/genny v0.1.1/go.mod h1:5TExbEyY48pfunL4QSXxlDOmdsD44RRq4mVZ0Ex28Xk= +github.com/gobuffalo/gitgen v0.0.0-20190315122116-cc086187d211/go.mod h1:vEHJk/E9DmhejeLeNt7UVvlSGv3ziL+djtTr3yyzcOw= +github.com/gobuffalo/gogen v0.0.0-20190315121717-8f38393713f5/go.mod h1:V9QVDIxsgKNZs6L2IYiGR8datgMhB577vzTDqypH360= +github.com/gobuffalo/gogen v0.1.0/go.mod h1:8NTelM5qd8RZ15VjQTFkAW6qOMx5wBbW4dSCS3BY8gg= +github.com/gobuffalo/gogen v0.1.1/go.mod h1:y8iBtmHmGc4qa3urIyo1shvOD8JftTtfcKi+71xfDNE= +github.com/gobuffalo/logger v0.0.0-20190315122211-86e12af44bc2/go.mod h1:QdxcLw541hSGtBnhUc4gaNIXRjiDppFGaDqzbrBd3v8= +github.com/gobuffalo/mapi v1.0.1/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc= +github.com/gobuffalo/mapi v1.0.2/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc= +github.com/gobuffalo/packd v0.0.0-20190315124812-a385830c7fc0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4= +github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4= +github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ= +github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0= +github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw= +github.com/gofiber/fiber/v2 v2.0.6/go.mod h1:VyfrlfcUCW0TcO5uaLHVlxZ8N25BgwnP6YjkzJmJP24= +github.com/gofiber/fiber/v2 v2.3.3 h1:nsjc9TfCl+ojXgEAu+uAT1Le7iQtZJ+Gfb/ox6+BM4w= +github.com/gofiber/fiber/v2 v2.3.3/go.mod h1:f8BRRIMjMdRyt2qmJ/0Sea3j3rwwfufPrh9WNBRiVZ0= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= +github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4= +github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= +github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= +github.com/klauspost/compress v1.10.7 h1:7rix8v8GpI3ZBb0nSozFRgbtXKv+hOe+qfEpZqybrAg= +github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +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/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= +github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE= +github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= +github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasthttp v1.16.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA= +github.com/valyala/fasthttp v1.18.0 h1:IV0DdMlatq9QO1Cr6wGJPVW1sV1Q8HvZXAIcjorylyM= +github.com/valyala/fasthttp v1.18.0/go.mod h1:jjraHZVbKOXftJfsOYoAjaeygpj5hr8ermTRJNroD7A= +github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a h1:0R4NLDRDZX6JcmhJgXi5E4b8Wg84ihbmUKp/GvSPEzc= +github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= +github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= +github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= +go.mongodb.org/mongo-driver v1.4.5 h1:TLtO+iD8krabXxvY1F1qpBOHgOxhLWR7XsT7kQeRmMY= +go.mongodb.org/mongo-driver v1.4.5/go.mod h1:WcMNYLx/IlOxLe6JRJiv2uXuCz6zBLndR4SoGjYphSc= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= +golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200929083018-4d22bbb62b3c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201210223839-7e3030f88018 h1:XKi8B/gRBuTZN1vU9gFsLMm6zVz5FSCDzm8JYACnjy8= +golang.org/x/sys v0.0.0-20201210223839-7e3030f88018/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= +gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= +gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= +gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/microservices/library/tests/libraries_get.go b/microservices/library/tests/libraries_get.go index 499ce47e..edfbf9b0 100644 --- a/microservices/library/tests/libraries_get.go +++ b/microservices/library/tests/libraries_get.go @@ -2,46 +2,28 @@ package tests import ( "encoding/json" - "errors" "fmt" "io/ioutil" - "log" "net/http" + + "github.com/alexandr-io/backend/library/data" ) -func testLibrariesGetWorking(baseURL string, jwt string) (*libraries, error) { - // Create a new request to libraries get route - req, err := http.NewRequest(http.MethodGet, baseURL+"libraries", nil) - if err != nil { - log.Println(err) - return nil, err - } - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) +// LibrariesGetEndFunction is a function called at the end of a library get test +func LibrariesGetEndFunction(res *http.Response) error { + // Read response Body + resBody, err := ioutil.ReadAll(res.Body) if err != nil { - newFailureMessage("GET", "/libraries", "Working Suit", "Can't call "+baseURL+"libraries") - return nil, err + return err } - // Check returned http code - if res.StatusCode != http.StatusOK { - newFailureMessage("GET", "/libraries", "Working Suit", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusOK, res.StatusCode)) - return nil, errors.New("") - } - // Read returned body - body, err := ioutil.ReadAll(res.Body) - if err != nil { - log.Println(err) - newFailureMessage("GET", "/libraries", "Working Suit", "Can't read response body") - return nil, err + // Parse response Body + var librariesData data.LibrariesNames + if err := json.Unmarshal(resBody, &librariesData); err != nil { + return err } - // Parse body data - var bodyData libraries - if err := json.Unmarshal(body, &bodyData); err != nil { - log.Println(err) - newFailureMessage("GET", "/libraries", "Working Suit", "Can't unmarshal json") - return nil, err + if librariesData.Libraries[0].Name != libraryName { + return fmt.Errorf("expected: %s\t got: %s", libraryName, librariesData.Libraries[0].Name) } - newSuccessMessage("GET", "/libraries", "Working Suit") - return &bodyData, nil + libraryID = librariesData.Libraries[0].ID + return nil } diff --git a/microservices/library/tests/library_create.go b/microservices/library/tests/library_create.go deleted file mode 100644 index 3b748b32..00000000 --- a/microservices/library/tests/library_create.go +++ /dev/null @@ -1,77 +0,0 @@ -package tests - -import ( - "bytes" - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "log" - "net/http" -) - -func testLibraryCreateWorking(baseURL string, jwt string) (*library, error) { - // Create a new request to library post route - - payload := bytes.NewBuffer([]byte("{\"name\": \"Bookshelf\", \"description\": \"Here is the description\"}")) - req, err := http.NewRequest(http.MethodPost, baseURL+"library", payload) - if err != nil { - log.Println(err) - return nil, err - } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("POST", "/library", "Working Suit", "Can't call "+baseURL+"library") - return nil, err - } - // Check returned http code - if res.StatusCode != http.StatusCreated { - newFailureMessage("POST", "/library", "Working Suit", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusCreated, res.StatusCode)) - return nil, errors.New("") - } - // Read returned body - body, err := ioutil.ReadAll(res.Body) - if err != nil { - log.Println(err) - newFailureMessage("POST", "/library", "Working Suit", "Can't read response body") - return nil, err - } - // Parse body data - var bodyData library - if err := json.Unmarshal(body, &bodyData); err != nil { - log.Println(err) - newFailureMessage("POST", "/library", "Working Suit", "Can't unmarshal json") - return nil, err - } - newSuccessMessage("POST", "/library", "Working Suit") - return &bodyData, nil -} - -func testLibraryCreateBadRequest(baseURL string, jwt string) error { - // Create payload to send to the route - payload := bytes.NewBuffer([]byte("{\"name\": 42}")) - // Create a new request to user update route - req, err := http.NewRequest(http.MethodPost, baseURL+"library", payload) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("PUT", "/library", "Bad Request", "Can't call "+baseURL+"library") - return err - } - // Check returned http code - if res.StatusCode != http.StatusBadRequest { - newFailureMessage("PUT", "/library", "Bad Request", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusBadRequest, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("PUT", "/library", "Bad Request") - return nil -} diff --git a/microservices/library/tests/library_delete.go b/microservices/library/tests/library_delete.go deleted file mode 100644 index 6e1552e5..00000000 --- a/microservices/library/tests/library_delete.go +++ /dev/null @@ -1,60 +0,0 @@ -package tests - -import ( - "bytes" - "errors" - "fmt" - "log" - "net/http" -) - -func testLibraryDeleteWorking(baseURL string, jwt string, libraryResponse libraryList) error { - // Create a new request to library delete route - payload := bytes.NewBuffer([]byte("{\"name\": \"" + libraryResponse.Name + "\"}")) - req, err := http.NewRequest(http.MethodDelete, baseURL+"library", payload) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("DELETE", "/library", "Working Suit", "Can't call "+baseURL+"library") - return err - } - // Check returned http code - if res.StatusCode != http.StatusNoContent { - newFailureMessage("DELETE", "/library", "Working Suit", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusNoContent, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("DELETE", "/library", "Working Suit") - return nil -} - -func testLibraryDeleteBadRequest(baseURL string, jwt string) error { - // Create payload to send to the route - payload := bytes.NewBuffer([]byte("{\"name\": 42}")) - // Create a new request to user update route - req, err := http.NewRequest(http.MethodDelete, baseURL+"library", payload) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("DELETE", "/library", "Bad Request", "Can't call "+baseURL+"library") - return err - } - // Check returned http code - if res.StatusCode != http.StatusBadRequest { - newFailureMessage("DELETE", "/library", "Bad Request", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusBadRequest, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("DELETE", "/library", "Bad Request") - return nil -} diff --git a/microservices/library/tests/library_get.go b/microservices/library/tests/library_get.go deleted file mode 100644 index 573a9b46..00000000 --- a/microservices/library/tests/library_get.go +++ /dev/null @@ -1,76 +0,0 @@ -package tests - -import ( - "bytes" - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "log" - "net/http" -) - -func testLibraryGetWorking(baseURL string, jwt string, libraryResponse libraryList) (*library, error) { - // Create a new request to library put route - payload := bytes.NewBuffer([]byte("{\"name\": \"" + libraryResponse.Name + "\"}")) - req, err := http.NewRequest(http.MethodPut, baseURL+"library", payload) - if err != nil { - log.Println(err) - return nil, err - } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("PUT", "/library", "Working Suit", "Can't call "+baseURL+"library") - return nil, err - } - // Check returned http code - if res.StatusCode != http.StatusOK { - newFailureMessage("PUT", "/library", "Working Suit", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusOK, res.StatusCode)) - return nil, errors.New("") - } - // Read returned body - body, err := ioutil.ReadAll(res.Body) - if err != nil { - log.Println(err) - newFailureMessage("PUT", "/library", "Working Suit", "Can't read response body") - return nil, err - } - // Parse body data - var bodyData library - if err := json.Unmarshal(body, &bodyData); err != nil { - log.Println(err) - newFailureMessage("PUT", "/library", "Working Suit", "Can't unmarshal json") - return nil, err - } - newSuccessMessage("PUT", "/library", "Working Suit") - return &bodyData, nil -} - -func testLibraryRetrieveBadRequest(baseURL string, jwt string) error { - // Create payload to send to the route - payload := bytes.NewBuffer([]byte("{\"name\": 42}")) - // Create a new request to user update route - req, err := http.NewRequest(http.MethodPut, baseURL+"library", payload) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("PUT", "/library", "Bad Request", "Can't call "+baseURL+"library") - return err - } - // Check returned http code - if res.StatusCode != http.StatusBadRequest { - newFailureMessage("PUT", "/library", "Bad Request", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusBadRequest, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("PUT", "/library", "Bad Request") - return nil -} diff --git a/microservices/library/tests/suite_bad_request.go b/microservices/library/tests/suite_bad_request.go new file mode 100644 index 00000000..5b031a6d --- /dev/null +++ b/microservices/library/tests/suite_bad_request.go @@ -0,0 +1,105 @@ +package tests + +import ( + "net/http" + + "github.com/alexandr-io/backend/library/data" +) + +const badRequestSuite = "Bad Request" + +var badRequestTests = []test{ + { + TestSuite: badRequestSuite, + HTTPMethod: http.MethodPost, + URL: func() string { return "/library" }, + AuthJWT: &authToken, + Body: data.Library{ + Description: libraryDescription, + }, + ExpectedHTTPCode: http.StatusBadRequest, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, + { + TestSuite: badRequestSuite, + HTTPMethod: http.MethodPut, + URL: func() string { return "/library" }, + AuthJWT: &authToken, + Body: struct { + Name int `json:"name"` + }{ + Name: 42, + }, + ExpectedHTTPCode: http.StatusBadRequest, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, + { + TestSuite: badRequestSuite, + HTTPMethod: http.MethodDelete, + URL: func() string { return "/library" }, + AuthJWT: &authToken, + Body: data.Book{ + Title: libraryName, + }, + ExpectedHTTPCode: http.StatusBadRequest, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, + { + TestSuite: badRequestSuite, + HTTPMethod: http.MethodPost, + URL: func() string { return "/book" }, + AuthJWT: &authToken, + Body: data.BookRetrieve{ + ID: "42", + LibraryID: "42", + }, + ExpectedHTTPCode: http.StatusBadRequest, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, + { + TestSuite: badRequestSuite, + HTTPMethod: http.MethodPut, + URL: func() string { return "/book" }, + AuthJWT: &authToken, + Body: struct { + ID int `json:"id"` + LibraryID string `json:"libID"` + }{ + ID: 42, + LibraryID: "42", + }, + ExpectedHTTPCode: http.StatusBadRequest, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, + { + TestSuite: badRequestSuite, + HTTPMethod: http.MethodDelete, + URL: func() string { return "/book" }, + AuthJWT: &authToken, + Body: bookCreation{ + Title: "Book name", + }, + ExpectedHTTPCode: http.StatusBadRequest, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, +} + +// ExecLibraryBadRequestTests execute bad request library tests. +func ExecLibraryBadRequestTests(environment string, jwt string) error { + baseURL, err := getBaseURL(environment) + if err != nil { + return err + } + authToken = jwt + + if err := execTestSuite(baseURL, badRequestTests); err != nil { + return err + } + return nil +} diff --git a/microservices/library/tests/suite_working.go b/microservices/library/tests/suite_working.go new file mode 100644 index 00000000..f626fe12 --- /dev/null +++ b/microservices/library/tests/suite_working.go @@ -0,0 +1,163 @@ +package tests + +import ( + "net/http" + + "github.com/alexandr-io/backend/library/data" +) + +const ( + workingSuite = "Working" + libraryName = "Library-test" + libraryDescription = "My bookshelf" + bookTitle = "Memoirs of Napoleon Bonaparte" + bookAuthor = "Louis Antoine Fauvelet de Bourrienne" + bookPublisher = "Public domain in the USA" + bookDescription = "Translated from: Mémoires sur Napoléon, le Directoire le Consulat, l'Empire et la Restauration." + bookDescriptionUpdated = "Biographie de Napoleon Bonaparte" +) + +var ( + authToken string + libraryID string + bookID string +) + +var workingTests = []test{ + { + TestSuite: workingSuite, + HTTPMethod: http.MethodPost, + URL: func() string { return "/library" }, + AuthJWT: &authToken, + Body: data.Library{ + Name: libraryName, + Description: libraryDescription, + }, + ExpectedHTTPCode: http.StatusCreated, + ExpectedResponse: data.Library{ + Name: libraryName, + Description: libraryDescription, + }, + CustomEndFunc: nil, + }, + { + TestSuite: workingSuite, + HTTPMethod: http.MethodGet, + URL: func() string { return "/libraries" }, + AuthJWT: &authToken, + Body: nil, + ExpectedHTTPCode: http.StatusOK, + ExpectedResponse: nil, + CustomEndFunc: LibrariesGetEndFunction, + }, + { + TestSuite: workingSuite, + HTTPMethod: http.MethodPut, + URL: func() string { return "/library" }, + AuthJWT: &authToken, + Body: data.LibraryName{ + Name: libraryName, + }, + ExpectedHTTPCode: http.StatusOK, + ExpectedResponse: data.Library{ + Name: libraryName, + Description: libraryDescription, + }, + CustomEndFunc: nil, + }, + { + TestSuite: workingSuite, + HTTPMethod: http.MethodPost, + URL: func() string { return "/book" }, + AuthJWT: &authToken, + Body: bookCreation{ + Title: bookTitle, + Author: bookAuthor, + Publisher: bookPublisher, + Description: bookDescription, + LibraryID: &libraryID, + }, + ExpectedHTTPCode: http.StatusCreated, + ExpectedResponse: data.Book{ + Title: bookTitle, + Author: bookAuthor, + Publisher: bookPublisher, + Description: bookDescription, + }, + CustomEndFunc: BookCreateEndFunction, + }, + { + TestSuite: workingSuite, + HTTPMethod: http.MethodPut, + URL: func() string { return "/book" }, + AuthJWT: &authToken, + Body: bookRetrieve{ + ID: &bookID, + LibraryID: &libraryID, + }, + ExpectedHTTPCode: http.StatusOK, + ExpectedResponse: data.Book{ + Title: bookTitle, + Author: bookAuthor, + Publisher: bookPublisher, + Description: bookDescription, + }, + CustomEndFunc: nil, + }, + { + TestSuite: workingSuite, + HTTPMethod: http.MethodPost, + URL: func() string { return "/library/" + libraryID + "/book/" + bookID }, + AuthJWT: &authToken, + Body: data.Book{ + Description: bookDescriptionUpdated, + }, + ExpectedHTTPCode: http.StatusOK, + ExpectedResponse: data.Book{ + Title: bookTitle, + Author: bookAuthor, + Publisher: bookPublisher, + Description: bookDescriptionUpdated, + }, + CustomEndFunc: nil, + }, + { + TestSuite: workingSuite, + HTTPMethod: http.MethodDelete, + URL: func() string { return "/book" }, + AuthJWT: &authToken, + Body: bookRetrieve{ + ID: &bookID, + LibraryID: &libraryID, + }, + ExpectedHTTPCode: http.StatusNoContent, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, + { + TestSuite: workingSuite, + HTTPMethod: http.MethodDelete, + URL: func() string { return "/library" }, + AuthJWT: &authToken, + Body: data.LibraryName{ + Name: libraryName, + }, + ExpectedHTTPCode: http.StatusNoContent, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, +} + +// ExecLibraryWorkingTests execute working library tests. +func ExecLibraryWorkingTests(environment string, jwt string) error { + baseURL, err := getBaseURL(environment) + if err != nil { + return err + } + authToken = jwt + + if err := execTestSuite(baseURL, workingTests); err != nil { + return err + } + return nil +} diff --git a/microservices/library/tests/tests.go b/microservices/library/tests/tests.go index 2a406fb7..bbcc330d 100644 --- a/microservices/library/tests/tests.go +++ b/microservices/library/tests/tests.go @@ -1,41 +1,60 @@ package tests import ( + "bytes" "errors" "fmt" - "math/rand" - "time" + "net/http" - "github.com/fatih/color" + "github.com/alexandr-io/backend/tests/itgmtod" ) -var ( - green = color.New(color.FgGreen).SprintFunc() - red = color.New(color.FgRed).SprintFunc() - cyan = color.New(color.FgCyan).SprintfFunc() - magenta = color.New(color.FgHiMagenta).SprintfFunc() - backMagenta = color.New(color.BgMagenta).Add(color.FgWhite).SprintfFunc() -) - -// ExecLibraryTests execute integration tests of library MS routes -func ExecLibraryTests(environment string, jwt string) error { - rand.Seed(time.Now().UnixNano()) - var errorHappened = false - - baseURL, err := getBaseURL(environment) - if err != nil { - return err - } +type test struct { + TestSuite string + HTTPMethod string + URL func() string + AuthJWT *string + Body interface{} + ExpectedHTTPCode int + ExpectedResponse interface{} + CustomEndFunc func(*http.Response) error +} - if err = workingTestSuit(baseURL, jwt); err != nil { - errorHappened = true - } - if err = badInputTestSuit(baseURL, jwt); err != nil { - errorHappened = true - } +func execTestSuite(baseURL string, testSuite []test) error { + for _, currentTest := range testSuite { + url := itgmtod.JoinURL(baseURL, currentTest.URL()) + body, err := itgmtod.MarshallBody(currentTest.Body) + if err != nil { + newFailureMessage(currentTest.HTTPMethod, url, currentTest.TestSuite, err.Error()) + return fmt.Errorf("error in " + currentTest.TestSuite + " test suite") + } - if errorHappened { - return errors.New("error in library tests") + // Test the route + res, err := itgmtod.TestRoute( + currentTest.HTTPMethod, + url, + currentTest.AuthJWT, + bytes.NewReader(body), + currentTest.ExpectedHTTPCode) + if err != nil { + newFailureMessage(currentTest.HTTPMethod, currentTest.URL(), currentTest.TestSuite, err.Error()) + return fmt.Errorf("error in " + currentTest.TestSuite + " test suite") + } + // Check expected response Body + if currentTest.ExpectedResponse != nil { + if err := itgmtod.CheckExpectedResponse(res, currentTest.ExpectedResponse); err != nil { + newFailureMessage(currentTest.HTTPMethod, currentTest.URL(), currentTest.TestSuite, err.Error()) + return fmt.Errorf("error in " + currentTest.TestSuite + " test suite") + } + } + // Call end function + if currentTest.CustomEndFunc != nil { + if err := currentTest.CustomEndFunc(res); err != nil { + newFailureMessage(currentTest.HTTPMethod, currentTest.URL(), currentTest.TestSuite, err.Error()) + return fmt.Errorf("error in " + currentTest.TestSuite + " test suite") + } + } + newSuccessMessage(currentTest.HTTPMethod, currentTest.URL(), currentTest.TestSuite) } return nil } @@ -53,100 +72,10 @@ func getBaseURL(environment string) (string, error) { } } -func workingTestSuit(baseURL string, jwt string) error { - _, err := testLibraryCreateWorking(baseURL, jwt) - if err != nil { - return err - } - libraries, err := testLibrariesGetWorking(baseURL, jwt) - if err != nil { - return err - } - _, err = testLibraryGetWorking(baseURL, jwt, libraries.Libraries[0]) - if err != nil { - return err - } - book, err := testBookCreateWorking(baseURL, jwt, libraries.Libraries[0]) - if err != nil { - return err - } - _, err = testBookGetWorking(baseURL, jwt, libraries.Libraries[0], book) - if err != nil { - return err - } - _, err = testBookUpdateWorking(baseURL, jwt, libraries.Libraries[0], book) - if err != nil { - return err - } - err = testBookDeleteWorking(baseURL, jwt, libraries.Libraries[0], book) - if err != nil { - return err - } - err = testLibraryDeleteWorking(baseURL, jwt, libraries.Libraries[0]) - if err != nil { - return err - } - return nil -} - -func badInputTestSuit(baseURL string, jwt string) error { - if err := testLibraryCreateBadRequest(baseURL, jwt); err != nil { - return err - } - if err := testLibraryRetrieveBadRequest(baseURL, jwt); err != nil { - return err - } - if err := testLibraryDeleteBadRequest(baseURL, jwt); err != nil { - return err - } - if err := testBookCreateBadRequest(baseURL, jwt); err != nil { - return err - } - if err := testBookGetBadRequest(baseURL, jwt); err != nil { - return err - } - if err := testBookDeleteBadRequest(baseURL, jwt); err != nil { - return err - } - return nil -} - func newSuccessMessage(verb string, route string, test string) { - coloredVerb := verb - switch verb { - case "GET": - coloredVerb = green(verb) - break - case "POST": - coloredVerb = cyan(verb) - break - case "PUT": - coloredVerb = magenta(verb) - break - case "DELETE": - coloredVerb = red(verb) - break - } - - fmt.Printf("%s\t %s\t%-35s%-14s%-5s\n", backMagenta("[LIBRARY]"), coloredVerb, route, test, green("✓")) + itgmtod.NewSuccessMessage(itgmtod.BackMagenta("[LIBRARY]"), verb, route, test) } func newFailureMessage(verb string, route string, test string, message string) { - coloredVerb := verb - switch verb { - case "GET": - coloredVerb = green(verb) - break - case "POST": - coloredVerb = cyan(verb) - break - case "PUT": - coloredVerb = magenta(verb) - break - case "DELETE": - coloredVerb = red(verb) - break - } - - fmt.Printf("%s\t %s\t%-35s%-14s%-5s\t%s\n", backMagenta("[LIBRARY]"), coloredVerb, route, test, red("✗"), message) + itgmtod.NewFailureMessage(itgmtod.BackMagenta("[LIBRARY]"), verb, route, test, message) } diff --git a/microservices/user/tests/data.go b/microservices/user/tests/data.go index 437d5c07..566a7bbc 100644 --- a/microservices/user/tests/data.go +++ b/microservices/user/tests/data.go @@ -1,8 +1,8 @@ package tests type user struct { - Username string `json:"username"` - Email string `json:"email"` - AuthToken string `json:"auth_token"` - RefreshToken string `json:"refresh_token"` + Username *string `json:"username"` + Email *string `json:"email"` + AuthToken string `json:"auth_token"` + RefreshToken string `json:"refresh_token"` } diff --git a/microservices/user/tests/delete_user.go b/microservices/user/tests/delete_user.go deleted file mode 100644 index 655648a7..00000000 --- a/microservices/user/tests/delete_user.go +++ /dev/null @@ -1,54 +0,0 @@ -package tests - -import ( - "errors" - "fmt" - "log" - "net/http" -) - -func testUserDeleteWorking(baseURL string, jwt string) error { - // Create a new request to user delete route - req, err := http.NewRequest(http.MethodDelete, baseURL+"user", nil) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("DELETE", "/user", "Working Suit", "Can't call "+baseURL+"user") - return err - } - // Check returned http code - if res.StatusCode != http.StatusNoContent { - newFailureMessage("DELETE", "/user", "Working Suit", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusNoContent, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("DELETE", "/user", "Working Suit") - return nil -} - -func testUserAlreadyDelete(baseURL string, jwt string) error { - // Create a new request to user delete route - req, err := http.NewRequest(http.MethodDelete, baseURL+"user", nil) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("DELETE", "/user", "Bad Request", "Can't call "+baseURL+"user") - return err - } - // Check returned http code - if res.StatusCode != http.StatusUnauthorized { - newFailureMessage("DELETE", "/user", "Bad Request", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusUnauthorized, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("DELETE", "/user", "Bad Request") - return nil -} diff --git a/microservices/user/tests/get_user.go b/microservices/user/tests/get_user.go deleted file mode 100644 index 447a55b7..00000000 --- a/microservices/user/tests/get_user.go +++ /dev/null @@ -1,47 +0,0 @@ -package tests - -import ( - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "log" - "net/http" -) - -func testUserGetWorking(baseURL string, jwt string) (*user, error) { - // Create a new request to user get route - req, err := http.NewRequest(http.MethodGet, baseURL+"user", nil) - if err != nil { - log.Println(err) - return nil, err - } - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("GET", "/user", "Working Suit", "Can't call "+baseURL+"user") - return nil, err - } - // Check returned http code - if res.StatusCode != http.StatusOK { - newFailureMessage("GET", "/user", "Working Suit", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusOK, res.StatusCode)) - return nil, errors.New("") - } - // Read returned body - body, err := ioutil.ReadAll(res.Body) - if err != nil { - log.Println(err) - newFailureMessage("GET", "/user", "Working Suit", "Can't read response body") - return nil, err - } - // Parse body data - var bodyData user - if err := json.Unmarshal(body, &bodyData); err != nil { - log.Println(err) - newFailureMessage("GET", "/user", "Working Suit", "Can't unmarshal json") - return nil, err - } - newSuccessMessage("GET", "/user", "Working Suit") - return &bodyData, nil -} diff --git a/microservices/user/tests/go.mod b/microservices/user/tests/go.mod index 6cbf700e..924c7e63 100644 --- a/microservices/user/tests/go.mod +++ b/microservices/user/tests/go.mod @@ -2,4 +2,8 @@ module github.com/alexandr-io/backend/user/tests go 1.15 -require github.com/fatih/color v1.10.0 +replace github.com/alexandr-io/backend/tests/itgmtod => ./../../../tests/itgmtod + +require ( + github.com/alexandr-io/backend/tests/itgmtod v0.0.0-00010101000000-000000000000 +) diff --git a/microservices/user/tests/suite_bad_request.go b/microservices/user/tests/suite_bad_request.go new file mode 100644 index 00000000..730bf695 --- /dev/null +++ b/microservices/user/tests/suite_bad_request.go @@ -0,0 +1,38 @@ +package tests + +import ( + "net/http" +) + +const badRequestSuite = "Bad Request" + +var badRequestTests = []test{ + { + TestSuite: badRequestSuite, + HTTPMethod: http.MethodPut, + URL: func() string { return "/user" }, + AuthJWT: &authToken, + Body: struct { + Username int `json:"username"` + }{ + Username: 42, + }, + ExpectedHTTPCode: http.StatusBadRequest, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, +} + +// ExecUserBadRequestTests execute bad request user tests. +func ExecUserBadRequestTests(environment string, jwt string) error { + baseURL, err := getBaseURL(environment) + if err != nil { + return err + } + authToken = jwt + + if err := execTestSuite(baseURL, badRequestTests); err != nil { + return err + } + return nil +} diff --git a/microservices/user/tests/suite_delete.go b/microservices/user/tests/suite_delete.go new file mode 100644 index 00000000..b18fc3e5 --- /dev/null +++ b/microservices/user/tests/suite_delete.go @@ -0,0 +1,79 @@ +package tests + +import ( + "net/http" + + "github.com/alexandr-io/backend/tests/itgmtod" +) + +const deleteSuite = "Delete" + +var ( + randomName string + randomEmail string +) + +var deleteTests = []test{ + { + TestSuite: deleteSuite, + HTTPMethod: http.MethodGet, + URL: func() string { return "/user" }, + AuthJWT: &authToken, + Body: nil, + ExpectedHTTPCode: http.StatusOK, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, + { + TestSuite: deleteSuite, + HTTPMethod: http.MethodPut, + URL: func() string { return "/user" }, + AuthJWT: &authToken, + Body: user{ + Username: &randomName, + Email: &randomEmail, + }, + ExpectedHTTPCode: http.StatusOK, + ExpectedResponse: user{ + Username: &randomName, + Email: &randomEmail, + }, + CustomEndFunc: nil, + }, + { + TestSuite: deleteSuite, + HTTPMethod: http.MethodDelete, + URL: func() string { return "/user" }, + AuthJWT: &authToken, + Body: nil, + ExpectedHTTPCode: http.StatusNoContent, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, + { + TestSuite: deleteSuite, + HTTPMethod: http.MethodDelete, + URL: func() string { return "/user" }, + AuthJWT: &authToken, + Body: nil, + ExpectedHTTPCode: http.StatusUnauthorized, + ExpectedResponse: nil, + CustomEndFunc: nil, + }, +} + +// ExecUserDeleteTests execute delete user tests. +func ExecUserDeleteTests(environment string, jwt string) error { + baseURL, err := getBaseURL(environment) + if err != nil { + return err + } + authToken = jwt + + randomName = itgmtod.RandStringRunes(12) + randomEmail = randomName + "@test.test" + if err := execTestSuite(baseURL, deleteTests); err != nil { + return err + } + return nil +} diff --git a/microservices/user/tests/tests.go b/microservices/user/tests/tests.go index e3fa768a..5fa513de 100644 --- a/microservices/user/tests/tests.go +++ b/microservices/user/tests/tests.go @@ -1,44 +1,62 @@ package tests import ( + "bytes" "errors" "fmt" - "math/rand" - "time" + "net/http" - "github.com/fatih/color" + "github.com/alexandr-io/backend/tests/itgmtod" ) -var ( - green = color.New(color.FgGreen).SprintFunc() - red = color.New(color.FgRed).SprintFunc() - cyan = color.New(color.FgCyan).SprintfFunc() - magenta = color.New(color.FgHiMagenta).SprintfFunc() - backBlue = color.New(color.BgBlue).Add(color.FgWhite).SprintfFunc() -) - -// ExecUserTests execute integration tests of user MS routes -func ExecUserTests(environment string, jwt string) error { - rand.Seed(time.Now().UnixNano()) - var errorHappened = false +var authToken string - baseURL, err := getBaseURL(environment) - if err != nil { - return err - } +type test struct { + TestSuite string + HTTPMethod string + URL func() string + AuthJWT *string + Body interface{} + ExpectedHTTPCode int + ExpectedResponse interface{} + CustomEndFunc func(*http.Response) error +} - if err = workingTestSuit(baseURL, jwt); err != nil { - errorHappened = true - } - if err = badInputTestSuit(baseURL, jwt); err != nil { - errorHappened = true - } - if err = deleteUser(baseURL, jwt); err != nil { - errorHappened = true - } +func execTestSuite(baseURL string, testSuite []test) error { + for _, currentTest := range testSuite { + url := itgmtod.JoinURL(baseURL, currentTest.URL()) + body, err := itgmtod.MarshallBody(currentTest.Body) + if err != nil { + newFailureMessage(currentTest.HTTPMethod, url, currentTest.TestSuite, err.Error()) + return fmt.Errorf("error in " + currentTest.TestSuite + " test suite") + } - if errorHappened { - return errors.New("error in user tests") + // Test the route + res, err := itgmtod.TestRoute( + currentTest.HTTPMethod, + url, + currentTest.AuthJWT, + bytes.NewReader(body), + currentTest.ExpectedHTTPCode) + if err != nil { + newFailureMessage(currentTest.HTTPMethod, currentTest.URL(), currentTest.TestSuite, err.Error()) + return fmt.Errorf("error in " + currentTest.TestSuite + " test suite") + } + // Check expected response Body + if currentTest.ExpectedResponse != nil { + if err := itgmtod.CheckExpectedResponse(res, currentTest.ExpectedResponse); err != nil { + newFailureMessage(currentTest.HTTPMethod, currentTest.URL(), currentTest.TestSuite, err.Error()) + return fmt.Errorf("error in " + currentTest.TestSuite + " test suite") + } + } + // Call end function + if currentTest.CustomEndFunc != nil { + if err := currentTest.CustomEndFunc(res); err != nil { + newFailureMessage(currentTest.HTTPMethod, currentTest.URL(), currentTest.TestSuite, err.Error()) + return fmt.Errorf("error in " + currentTest.TestSuite + " test suite") + } + } + newSuccessMessage(currentTest.HTTPMethod, currentTest.URL(), currentTest.TestSuite) } return nil } @@ -56,71 +74,10 @@ func getBaseURL(environment string) (string, error) { } } -func workingTestSuit(baseURL string, jwt string) error { - userData, err := testUserGetWorking(baseURL, jwt) - if err != nil { - return err - } - userData.AuthToken = jwt - if err := testUserUpdateWorking(baseURL, userData); err != nil { - return err - } - return nil -} - -func badInputTestSuit(baseURL string, jwt string) error { - if err := testUserUpdateBadRequest(baseURL, jwt); err != nil { - return err - } - return nil -} - -func deleteUser(baseURL string, jwt string) error { - if err := testUserDeleteWorking(baseURL, jwt); err != nil { - return err - } - if err := testUserAlreadyDelete(baseURL, jwt); err != nil { - return err - } - return nil -} - func newSuccessMessage(verb string, route string, test string) { - coloredVerb := verb - switch verb { - case "GET": - coloredVerb = green(verb) - break - case "POST": - coloredVerb = cyan(verb) - break - case "PUT": - coloredVerb = magenta(verb) - break - case "DELETE": - coloredVerb = red(verb) - break - } - - fmt.Printf("%s\t %s\t%-35s%-14s%-5s\n", backBlue("[USER]"), coloredVerb, route, test, green("✓")) + itgmtod.NewSuccessMessage(itgmtod.BackBlue("[USER]"), verb, route, test) } func newFailureMessage(verb string, route string, test string, message string) { - coloredVerb := verb - switch verb { - case "GET": - coloredVerb = green(verb) - break - case "POST": - coloredVerb = cyan(verb) - break - case "PUT": - coloredVerb = magenta(verb) - break - case "DELETE": - coloredVerb = red(verb) - break - } - - fmt.Printf("%s\t %s\t%-35s%-14s%-5s\t%s\n", backBlue("[USER]"), coloredVerb, route, test, red("✗"), message) + itgmtod.NewFailureMessage(itgmtod.BackBlue("[USER]"), verb, route, test, message) } diff --git a/microservices/user/tests/update_user.go b/microservices/user/tests/update_user.go deleted file mode 100644 index 72fbb2b5..00000000 --- a/microservices/user/tests/update_user.go +++ /dev/null @@ -1,81 +0,0 @@ -package tests - -import ( - "bytes" - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "log" - "net/http" -) - -func testUserUpdateWorking(baseURL string, userData *user) error { - newUsername := userData.Username[:len(userData.Username)-1] - // Create payload to send to the route - payload := bytes.NewBuffer([]byte("{\"username\": \"" + newUsername + "\"}")) - // Create a new request to user update route - req, err := http.NewRequest(http.MethodPut, baseURL+"user", payload) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+userData.AuthToken) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("PUT", "/user", "Working Suit", "Can't call "+baseURL+"user") - return err - } - // Check returned http code - if res.StatusCode != http.StatusOK { - newFailureMessage("PUT", "/user", "Working Suit", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusOK, res.StatusCode)) - return errors.New("") - } - // Read returned body - body, err := ioutil.ReadAll(res.Body) - if err != nil { - log.Println(err) - return err - } - // Parse body data - var bodyData user - if err := json.Unmarshal(body, &bodyData); err != nil { - log.Println(err) - return err - } - if bodyData.Username != newUsername && - bodyData.Email != userData.Email { - newFailureMessage("PUT", "/user", "Working Suit", "Data != expected data") - return errors.New("") - } - newSuccessMessage("PUT", "/user", "Working Suit") - return nil -} - -func testUserUpdateBadRequest(baseURL string, jwt string) error { - // Create payload to send to the route - payload := bytes.NewBuffer([]byte("{\"username\": 42}")) - // Create a new request to user update route - req, err := http.NewRequest(http.MethodPut, baseURL+"user", payload) - if err != nil { - log.Println(err) - return err - } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+jwt) - // Exec request - res, err := http.DefaultClient.Do(req) - if err != nil { - newFailureMessage("PUT", "/user", "Bad Request", "Can't call "+baseURL+"user") - return err - } - // Check returned http code - if res.StatusCode != http.StatusBadRequest { - newFailureMessage("PUT", "/user", "Bad Request", fmt.Sprintf("[Expected: %d,\tGot: %d]", http.StatusBadRequest, res.StatusCode)) - return errors.New("") - } - newSuccessMessage("PUT", "/user", "Bad Request") - return nil -} diff --git a/tests/filter.go b/tests/filter.go deleted file mode 100644 index 4952c65c..00000000 --- a/tests/filter.go +++ /dev/null @@ -1,55 +0,0 @@ -package main - -import "github.com/urfave/cli/v2" - -type microservices string -type microservicesFunc func(string) error - -const ( - auth microservices = "auth" - library microservices = "library" - user microservices = "user" -) - -func (ms microservices) string() string { - return string(ms) -} - -var microservicesIncludeMap = map[microservices]microservicesFunc{ - auth: execAuth, - library: execLibrary, - user: execUser, -} - -func filters(c *cli.Context) ([]microservicesFunc, error) { - var includeFuncs []microservicesFunc - - if len(c.StringSlice("include")) != 0 { - args := c.StringSlice("include") - for _, arg := range args { - if function, ok := microservicesIncludeMap[microservices(arg)]; ok { - includeFuncs = append(includeFuncs, function) - } else { - return nil, cli.Exit(arg+" not recognized", 1) - } - } - } else if len(c.StringSlice("exclude")) != 0 { - args := c.StringSlice("exclude") - excludeMap := microservicesIncludeMap - for _, arg := range args { - if _, ok := excludeMap[microservices(arg)]; ok { - delete(excludeMap, microservices(arg)) - } else { - return nil, cli.Exit(arg+" not recognized", 1) - } - } - for _, element := range excludeMap { - includeFuncs = append(includeFuncs, element) - } - } else { - for _, element := range microservicesIncludeMap { - includeFuncs = append(includeFuncs, element) - } - } - return includeFuncs, nil -} diff --git a/tests/go.mod b/tests/go.mod deleted file mode 100644 index 6f829ca6..00000000 --- a/tests/go.mod +++ /dev/null @@ -1,16 +0,0 @@ -module github.com/alexandr-io/backend/tests - -go 1.15 - -replace github.com/alexandr-io/backend/auth/tests => ../microservices/auth/tests - -replace github.com/alexandr-io/backend/user/tests => ../microservices/user/tests - -replace github.com/alexandr-io/backend/library/tests => ../microservices/library/tests - -require ( - github.com/alexandr-io/backend/auth/tests v0.0.0-00010101000000-000000000000 - github.com/alexandr-io/backend/library/tests v0.0.0-00010101000000-000000000000 - github.com/alexandr-io/backend/user/tests v0.0.0-00010101000000-000000000000 - github.com/urfave/cli/v2 v2.3.0 -) diff --git a/tests/go.sum b/tests/go.sum deleted file mode 100644 index 45869047..00000000 --- a/tests/go.sum +++ /dev/null @@ -1,22 +0,0 @@ -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= -github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= -github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= -github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= -github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= -github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/tests/README.md b/tests/integration/README.md similarity index 100% rename from tests/README.md rename to tests/integration/README.md diff --git a/tests/integration/filter.go b/tests/integration/filter.go new file mode 100644 index 00000000..25310e8d --- /dev/null +++ b/tests/integration/filter.go @@ -0,0 +1,69 @@ +package main + +import ( + "fmt" + + "github.com/urfave/cli/v2" +) + +func getTestsByName(name string) map[string]funcChannel { + var m = make(map[string]funcChannel) + for _, ms := range testSuites { + if ms.Microservice == name { + for _, suite := range ms.Suites { + m[suite.Name] = suite.FuncChan + } + return m + } + for _, suite := range ms.Suites { + if suite.Name == name { + m[suite.Name] = suite.FuncChan + return m + } + } + } + fmt.Println(name + " not found. Run tests to see the list of test suites and microservices") + return m +} + +func allTests() map[string]funcChannel { + var m = make(map[string]funcChannel) + for _, ms := range testSuites { + for _, suite := range ms.Suites { + m[suite.Name] = suite.FuncChan + } + } + return m +} + +func joinMaps(m1 map[string]funcChannel, m2 map[string]funcChannel) map[string]funcChannel { + for key, value := range m2 { + m1[key] = value + } + return m1 +} + +func filters(c *cli.Context) map[string]funcChannel { + var includeFuncsMap = allTests() + + if c.Bool("asynchronous") { + asynchronous = true + } + if len(c.StringSlice("include")) != 0 { + args := c.StringSlice("include") + includeFuncsMap = make(map[string]funcChannel) + for _, arg := range args { + joinMaps(includeFuncsMap, getTestsByName(arg)) + } + } + if len(c.StringSlice("exclude")) != 0 { + args := c.StringSlice("exclude") + for _, arg := range args { + tests := getTestsByName(arg) + for key := range tests { + delete(includeFuncsMap, key) + } + } + } + return includeFuncsMap +} diff --git a/tests/integration/go.mod b/tests/integration/go.mod new file mode 100644 index 00000000..a08a9059 --- /dev/null +++ b/tests/integration/go.mod @@ -0,0 +1,22 @@ +module github.com/alexandr-io/backend/tests/integration + +go 1.15 + +replace github.com/alexandr-io/backend/tests/itgmtod => ./../itgmtod + +replace github.com/alexandr-io/backend/auth/tests => ../../microservices/auth/tests + +replace github.com/alexandr-io/backend/user/tests => ../../microservices/user/tests + +replace github.com/alexandr-io/backend/library/tests => ../../microservices/library/tests + +replace github.com/alexandr-io/backend/auth/data => ../../microservices/auth/app/data + +replace github.com/alexandr-io/backend/library/data => ../../microservices/library/app/data + +require ( + github.com/alexandr-io/backend/auth/tests v0.0.0-00010101000000-000000000000 + github.com/alexandr-io/backend/library/tests v0.0.0-00010101000000-000000000000 + github.com/alexandr-io/backend/user/tests v0.0.0-00010101000000-000000000000 + github.com/urfave/cli/v2 v2.3.0 +) diff --git a/tests/integration/go.sum b/tests/integration/go.sum new file mode 100644 index 00000000..48c7fcf5 --- /dev/null +++ b/tests/integration/go.sum @@ -0,0 +1,163 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/alexandr-io/berrors v1.2.7 h1:xBN0GImN4yfMriJjmW1ux9h86KGdSe06L5jFsMZURqg= +github.com/alexandr-io/berrors v1.2.7/go.mod h1:kZn7MFDwwMJkbRGr+LPyZh2lhg8Tfn+mZLIwC2JknQk= +github.com/andybalholm/brotli v1.0.0 h1:7UCwP93aiSfvWpapti8g88vVVGp2qqtGyePsSuDafo4= +github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= +github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48= +github.com/confluentinc/confluent-kafka-go v1.5.2 h1:l+qt+a0Okmq0Bdr1P55IX4fiwFJyg0lZQmfHkAFkv7E= +github.com/confluentinc/confluent-kafka-go v1.5.2/go.mod h1:u2zNLny2xq+5rWeTQjFHbDzzNuba4P1vo31r9r4uAdg= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= +github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= +github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= +github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= +github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= +github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= +github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= +github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= +github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY= +github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg= +github.com/gobuffalo/envy v1.6.15/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= +github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= +github.com/gobuffalo/flect v0.1.0/go.mod h1:d2ehjJqGOH/Kjqcoz+F7jHTBbmDb38yXA598Hb50EGs= +github.com/gobuffalo/flect v0.1.1/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI= +github.com/gobuffalo/flect v0.1.3/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI= +github.com/gobuffalo/genny v0.0.0-20190329151137-27723ad26ef9/go.mod h1:rWs4Z12d1Zbf19rlsn0nurr75KqhYp52EAGGxTbBhNk= +github.com/gobuffalo/genny v0.0.0-20190403191548-3ca520ef0d9e/go.mod h1:80lIj3kVJWwOrXWWMRzzdhW3DsrdjILVil/SFKBzF28= +github.com/gobuffalo/genny v0.1.0/go.mod h1:XidbUqzak3lHdS//TPu2OgiFB+51Ur5f7CSnXZ/JDvo= +github.com/gobuffalo/genny v0.1.1/go.mod h1:5TExbEyY48pfunL4QSXxlDOmdsD44RRq4mVZ0Ex28Xk= +github.com/gobuffalo/gitgen v0.0.0-20190315122116-cc086187d211/go.mod h1:vEHJk/E9DmhejeLeNt7UVvlSGv3ziL+djtTr3yyzcOw= +github.com/gobuffalo/gogen v0.0.0-20190315121717-8f38393713f5/go.mod h1:V9QVDIxsgKNZs6L2IYiGR8datgMhB577vzTDqypH360= +github.com/gobuffalo/gogen v0.1.0/go.mod h1:8NTelM5qd8RZ15VjQTFkAW6qOMx5wBbW4dSCS3BY8gg= +github.com/gobuffalo/gogen v0.1.1/go.mod h1:y8iBtmHmGc4qa3urIyo1shvOD8JftTtfcKi+71xfDNE= +github.com/gobuffalo/logger v0.0.0-20190315122211-86e12af44bc2/go.mod h1:QdxcLw541hSGtBnhUc4gaNIXRjiDppFGaDqzbrBd3v8= +github.com/gobuffalo/mapi v1.0.1/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc= +github.com/gobuffalo/mapi v1.0.2/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc= +github.com/gobuffalo/packd v0.0.0-20190315124812-a385830c7fc0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4= +github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4= +github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ= +github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0= +github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw= +github.com/gofiber/fiber/v2 v2.0.6/go.mod h1:VyfrlfcUCW0TcO5uaLHVlxZ8N25BgwnP6YjkzJmJP24= +github.com/gofiber/fiber/v2 v2.3.3 h1:nsjc9TfCl+ojXgEAu+uAT1Le7iQtZJ+Gfb/ox6+BM4w= +github.com/gofiber/fiber/v2 v2.3.3/go.mod h1:f8BRRIMjMdRyt2qmJ/0Sea3j3rwwfufPrh9WNBRiVZ0= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= +github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4= +github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= +github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= +github.com/klauspost/compress v1.10.7 h1:7rix8v8GpI3ZBb0nSozFRgbtXKv+hOe+qfEpZqybrAg= +github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +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/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= +github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE= +github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= +github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= +github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= +github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasthttp v1.16.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA= +github.com/valyala/fasthttp v1.18.0 h1:IV0DdMlatq9QO1Cr6wGJPVW1sV1Q8HvZXAIcjorylyM= +github.com/valyala/fasthttp v1.18.0/go.mod h1:jjraHZVbKOXftJfsOYoAjaeygpj5hr8ermTRJNroD7A= +github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a h1:0R4NLDRDZX6JcmhJgXi5E4b8Wg84ihbmUKp/GvSPEzc= +github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= +github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= +github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= +go.mongodb.org/mongo-driver v1.4.4 h1:bsPHfODES+/yx2PCWzUYMH8xj6PVniPI8DQrsJuSXSs= +go.mongodb.org/mongo-driver v1.4.4/go.mod h1:WcMNYLx/IlOxLe6JRJiv2uXuCz6zBLndR4SoGjYphSc= +go.mongodb.org/mongo-driver v1.4.5 h1:TLtO+iD8krabXxvY1F1qpBOHgOxhLWR7XsT7kQeRmMY= +go.mongodb.org/mongo-driver v1.4.5/go.mod h1:WcMNYLx/IlOxLe6JRJiv2uXuCz6zBLndR4SoGjYphSc= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= +golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200929083018-4d22bbb62b3c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201210223839-7e3030f88018 h1:XKi8B/gRBuTZN1vU9gFsLMm6zVz5FSCDzm8JYACnjy8= +golang.org/x/sys v0.0.0-20201210223839-7e3030f88018/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= +gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= +gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/tests/integration/main.go b/tests/integration/main.go new file mode 100644 index 00000000..cf556a6f --- /dev/null +++ b/tests/integration/main.go @@ -0,0 +1,144 @@ +package main + +import ( + "fmt" + "log" + "os" + + authTests "github.com/alexandr-io/backend/auth/tests" + userTests "github.com/alexandr-io/backend/user/tests" + + "github.com/urfave/cli/v2" +) + +var authToken string +var asynchronous = false + +var flags = []cli.Flag{ + &cli.StringSliceFlag{ + Name: "include", + Aliases: []string{"i"}, + Usage: "include tests for `TEST_SUITE`", + }, + &cli.StringSliceFlag{ + Name: "exclude", + Aliases: []string{"e"}, + Usage: "exclude tests for `TEST_SUITE`", + }, +} + +func main() { + log.SetFlags(log.LstdFlags | log.Lshortfile) + app := &cli.App{ + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "asynchronous", + Aliases: []string{"a"}, + Usage: "run the tests asynchronously", + }, + }, + Commands: []*cli.Command{ + { + Name: "tests", + Usage: "print all test suite names", + Action: func(_ *cli.Context) error { + printTestSuites() + return nil + }, + }, + { + Name: "local", + Usage: "run tests in local", + Flags: flags, + Action: func(c *cli.Context) error { + return parseAndExecTests(c, "local") + }, + }, + { + Name: "preprod", + Usage: "run tests in preprod", + Flags: flags, + Action: func(c *cli.Context) error { + return parseAndExecTests(c, "preprod") + }, + }, + { + Name: "prod", + Usage: "run tests in prod", + Flags: flags, + Action: func(c *cli.Context) error { + return parseAndExecTests(c, "prod") + }, + }, + }, + } + app.UseShortOptionHandling = true + app.EnableBashCompletion = true + + err := app.Run(os.Args) + if err != nil { + log.Fatal(err) + } +} + +func parseAndExecTests(c *cli.Context, environment string) error { + var errorHappened = false + testsToExec := filters(c) + + if err := execBasicAuth(environment); err != nil { + return cli.Exit("", 1) + } + + for _, value := range testsToExec { + value := value + if asynchronous { + go func() { + if err := value.Func(environment, authToken); err != nil { + errorHappened = true + } + value.Channel <- true + }() + } else { + if err := value.Func(environment, authToken); err != nil { + errorHappened = true + } + } + } + + // Wait for goroutines to finish is test are run asynchronously + if asynchronous { + for _, value := range testsToExec { + <-value.Channel + } + } + + if err := userTests.ExecUserDeleteTests(environment, authToken); err != nil { + return cli.Exit("", 1) + } + + if errorHappened { + return cli.Exit("", 1) + } + return nil +} + +func printTestSuites() { + fmt.Println("USAGE:\n Using the MICROSERVICE_NAME will include or exclude all of the TEST_SUITES\n") + fmt.Println("FORMAT:\n • MICROSERVICE_NAME\n · TEST_SUITES\n") + fmt.Println("TEST SUITES LIST:") + for _, service := range testSuites { + fmt.Printf(" • %s\n", service.Microservice) + for _, suite := range service.Suites { + fmt.Printf(" · %s\n", suite.Name) + } + } +} + +func execBasicAuth(environment string) error { + jwt, err := authTests.ExecAuthBasicTests(environment) + if err != nil { + return err + } + authToken = jwt + return nil +} diff --git a/tests/integration/test_suits.go b/tests/integration/test_suits.go new file mode 100644 index 00000000..d3a480f4 --- /dev/null +++ b/tests/integration/test_suits.go @@ -0,0 +1,91 @@ +package main + +import ( + authTests "github.com/alexandr-io/backend/auth/tests" + libraryTests "github.com/alexandr-io/backend/library/tests" + userTests "github.com/alexandr-io/backend/user/tests" +) + +type testFunc func(string, string) error + +type funcChannel struct { + Func testFunc + Channel chan bool +} + +type suiteStruct struct { + Name string + FuncChan funcChannel +} + +type testSuitesStruct struct { + Microservice string + Suites []suiteStruct +} + +var testSuites = []testSuitesStruct{ + { + Microservice: "AUTH", + Suites: []suiteStruct{ + { + Name: "AUTH_WORKING", + FuncChan: funcChannel{ + Func: authTests.ExecAuthWorkingTests, + Channel: make(chan bool, 1), + }, + }, + { + Name: "AUTH_BAD_REQUEST", + FuncChan: funcChannel{ + Func: authTests.ExecAuthBadRequestTests, + Channel: make(chan bool, 1), + }, + }, + { + Name: "AUTH_INCORRECT", + FuncChan: funcChannel{ + Func: authTests.ExecAuthIncorrectTests, + Channel: make(chan bool, 1), + }, + }, + { + Name: "AUTH_LOGOUT", + FuncChan: funcChannel{ + Func: authTests.ExecAuthLogoutTests, + Channel: make(chan bool, 1), + }, + }, + }, + }, + { + Microservice: "LIBRARY", + Suites: []suiteStruct{ + { + Name: "LIBRARY_WORKING", + FuncChan: funcChannel{ + Func: libraryTests.ExecLibraryWorkingTests, + Channel: make(chan bool, 1), + }, + }, + { + Name: "LIBRARY_BAD_REQUEST", + FuncChan: funcChannel{ + Func: libraryTests.ExecLibraryBadRequestTests, + Channel: make(chan bool, 1), + }, + }, + }, + }, + { + Microservice: "USER", + Suites: []suiteStruct{ + { + Name: "USER_BAD_REQUEST", + FuncChan: funcChannel{ + Func: userTests.ExecUserBadRequestTests, + Channel: make(chan bool, 1), + }, + }, + }, + }, +} diff --git a/tests/itgmtod/expected_esponse.go b/tests/itgmtod/expected_esponse.go new file mode 100644 index 00000000..5f6c81ed --- /dev/null +++ b/tests/itgmtod/expected_esponse.go @@ -0,0 +1,35 @@ +package itgmtod + +import ( + "bytes" + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + "reflect" +) + +// CheckExpectedResponse will read and unmarshall the response body and then call StructContain +func CheckExpectedResponse(res *http.Response, expected interface{}) error { + // Read response body + resBody, err := ioutil.ReadAll(res.Body) + if err != nil { + return err + } + res.Body = ioutil.NopCloser(bytes.NewReader(resBody)) + + // Get expected type and create new interface to unmarshall response body + expectedType := reflect.TypeOf(expected) + responseDataValue := reflect.New(expectedType) + responseData := responseDataValue.Interface() + + // Parse response body + if err := json.Unmarshal(resBody, responseData); err != nil { + return err + } + + if !StructContain(responseData, expected) { + return fmt.Errorf("response struct does not correspond to expected response") + } + return nil +} diff --git a/tests/itgmtod/go.mod b/tests/itgmtod/go.mod new file mode 100644 index 00000000..97944830 --- /dev/null +++ b/tests/itgmtod/go.mod @@ -0,0 +1,5 @@ +module github.com/alexandr-io/backend/tests/itgmtod + +go 1.15 + +require github.com/fatih/color v1.10.0 diff --git a/tests/itgmtod/go.sum b/tests/itgmtod/go.sum new file mode 100644 index 00000000..9ee68f3d --- /dev/null +++ b/tests/itgmtod/go.sum @@ -0,0 +1,9 @@ +github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= +github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= +github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= +github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/tests/itgmtod/join_URL.go b/tests/itgmtod/join_URL.go new file mode 100644 index 00000000..8132b1fa --- /dev/null +++ b/tests/itgmtod/join_URL.go @@ -0,0 +1,13 @@ +package itgmtod + +import ( + "fmt" + "path" + "strings" +) + +// JoinURL Join a base url with a route path +func JoinURL(base string, paths ...string) string { + p := path.Join(paths...) + return fmt.Sprintf("%s/%s", strings.TrimRight(base, "/"), strings.TrimLeft(p, "/")) +} diff --git a/tests/itgmtod/marshall_body.go b/tests/itgmtod/marshall_body.go new file mode 100644 index 00000000..a1420693 --- /dev/null +++ b/tests/itgmtod/marshall_body.go @@ -0,0 +1,15 @@ +package itgmtod + +import "encoding/json" + +// MarshallBody is used to get the JSON bytes out of a struct +func MarshallBody(body interface{}) ([]byte, error) { + if body == nil { + return nil, nil + } + bodyBytes, err := json.Marshal(body) + if err != nil { + return nil, err + } + return bodyBytes, nil +} diff --git a/tests/itgmtod/messages.go b/tests/itgmtod/messages.go new file mode 100644 index 00000000..34b800da --- /dev/null +++ b/tests/itgmtod/messages.go @@ -0,0 +1,49 @@ +package itgmtod + +import ( + "fmt" + + "github.com/fatih/color" +) + +var ( + green = color.New(color.FgGreen).SprintFunc() + red = color.New(color.FgRed).SprintFunc() + cyan = color.New(color.FgCyan).SprintfFunc() + magenta = color.New(color.FgHiMagenta).SprintfFunc() + // BackCyan is used by AUTH + BackCyan = color.New(color.BgCyan).Add(color.FgBlack).SprintfFunc() + // BackBlue is used by USER + BackBlue = color.New(color.BgBlue).Add(color.FgWhite).SprintfFunc() + // BackMagenta is used by LIBRARY + BackMagenta = color.New(color.BgMagenta).Add(color.FgWhite).SprintfFunc() +) + +func getHTTPVerbColor(verb string) string { + coloredVerb := verb + switch verb { + case "GET": + coloredVerb = green(verb) + break + case "POST": + coloredVerb = cyan(verb) + break + case "PUT": + coloredVerb = magenta(verb) + break + case "DELETE": + coloredVerb = red(verb) + break + } + return coloredVerb +} + +// NewSuccessMessage print a success message for an integration Test +func NewSuccessMessage(MS string, verb string, route string, testSuite string) { + fmt.Printf("%-25s%-20s%-55s%-15s%5s\n", MS, getHTTPVerbColor(verb), route, testSuite, green("✓")) +} + +// NewFailureMessage print a failure message for an integration Test +func NewFailureMessage(MS string, verb string, route string, testSuite string, errMessage string) { + fmt.Printf("%-25s%-20s%-55s%-15s%5s\t%s\n", MS, getHTTPVerbColor(verb), route, testSuite, red("✗"), errMessage) +} diff --git a/tests/itgmtod/random_string.go b/tests/itgmtod/random_string.go new file mode 100644 index 00000000..1d1de3c2 --- /dev/null +++ b/tests/itgmtod/random_string.go @@ -0,0 +1,14 @@ +package itgmtod + +import "math/rand" + +var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") + +// RandStringRunes generate a random string of specified length +func RandStringRunes(length int) string { + b := make([]rune, length) + for i := range b { + b[i] = letterRunes[rand.Intn(len(letterRunes))] + } + return "test-" + string(b) +} diff --git a/tests/itgmtod/struct_contain.go b/tests/itgmtod/struct_contain.go new file mode 100644 index 00000000..7bdc70de --- /dev/null +++ b/tests/itgmtod/struct_contain.go @@ -0,0 +1,49 @@ +package itgmtod + +import ( + "fmt" + "reflect" +) + +func isZeroOfUnderlyingType(x interface{}) bool { + return reflect.DeepEqual(x, reflect.Zero(reflect.TypeOf(x)).Interface()) +} + +// StructContain compare 2 struct interfaces. If the non-empty data of the y interface are the same as the one in +// the x interface, true is returned. Otherwise false +func StructContain(x, y interface{}) bool { + if x == nil || y == nil { + return x == y + } + v1 := reflect.ValueOf(x) + v2 := reflect.ValueOf(y) + + if v1.Kind() == reflect.Ptr { + v1 = v1.Elem() + } + if v2.Kind() == reflect.Ptr { + v2 = v2.Elem() + } + + for i := 0; i < v1.NumField(); i++ { // Go through all the fields of the struct + val1 := v1.Field(i).Interface() + val2 := v2.Field(i).Interface() + if v1.Field(i).Kind() == reflect.Ptr { + val1 = v1.Field(i).Elem().Interface() + } + if v2.Field(i).Kind() == reflect.Ptr { + val2 = v2.Field(i).Elem().Interface() + } + if !isZeroOfUnderlyingType(val2) { // Check that the second struct field is not empty + if val1 != val2 { // Check if field is equal in two structs + fmt.Printf("Field %s with value %v is not eqal to field %s with value %v\n", + v1.Type().Field(i).Name, + val1, + v2.Type().Field(i).Name, + val2) + return false + } + } + } + return true +} diff --git a/tests/itgmtod/test_route.go b/tests/itgmtod/test_route.go new file mode 100644 index 00000000..ce585786 --- /dev/null +++ b/tests/itgmtod/test_route.go @@ -0,0 +1,41 @@ +package itgmtod + +import ( + "fmt" + "io" + "net/http" +) + +// TestRoute create and call an HTTP route with the given parameters. In case of error, an error is returned. +// The response object is returned in case of success. +func TestRoute(HTTPMethod string, URL string, authJWT *string, body io.Reader, expectedHTTPCode int) (*http.Response, error) { + // Create request with body if given + var req *http.Request + var err error + if body != nil { + req, err = http.NewRequest(HTTPMethod, URL, body) + } else { + req, err = http.NewRequest(HTTPMethod, URL, nil) + } + if err != nil { + return nil, err + } + req.Header.Set("Content-Type", "application/json") + + // Add Bearer authentication token if given + if authJWT != nil { + req.Header.Set("Authorization", "Bearer "+*authJWT) + } + + // Execute request + res, err := http.DefaultClient.Do(req) + if err != nil { + return nil, err + } + + // Check returned http code + if res.StatusCode != expectedHTTPCode { + return nil, fmt.Errorf("[Expected: %d,\tGot: %d]", expectedHTTPCode, res.StatusCode) + } + return res, nil +} diff --git a/tests/main.go b/tests/main.go deleted file mode 100644 index df621214..00000000 --- a/tests/main.go +++ /dev/null @@ -1,107 +0,0 @@ -package main - -import ( - "log" - "os" - - authTests "github.com/alexandr-io/backend/auth/tests" - libraryTests "github.com/alexandr-io/backend/library/tests" - userTests "github.com/alexandr-io/backend/user/tests" - - "github.com/urfave/cli/v2" -) - -var authToken string - -var flags = []cli.Flag{ - &cli.StringSliceFlag{ - Name: "include", - Aliases: []string{"i"}, - Usage: "Include tests for `MICRO_SERVICE`", - }, - &cli.StringSliceFlag{ - Name: "exclude", - Aliases: []string{"e"}, - Usage: "Exclude tests for `MICRO_SERVICE`", - }, -} - -func main() { - log.SetFlags(log.LstdFlags | log.Lshortfile) - app := &cli.App{ - Commands: []*cli.Command{ - { - Name: "test", - Usage: "options for running tests", - Subcommands: []*cli.Command{ - { - Name: "local", - Usage: "run tests in local", - Flags: flags, - Action: func(c *cli.Context) error { - return parseAndExecTests(c, "local") - }, - }, - { - Name: "preprod", - Usage: "run tests in preprod", - Flags: flags, - Action: func(c *cli.Context) error { - return parseAndExecTests(c, "preprod") - }, - }, - { - Name: "prod", - Usage: "run tests in prod", - Flags: flags, - Action: func(c *cli.Context) error { - return parseAndExecTests(c, "prod") - }, - }, - }, - }, - }, - } - app.EnableBashCompletion = true - - err := app.Run(os.Args) - if err != nil { - log.Fatal(err) - } -} - -func parseAndExecTests(c *cli.Context, environment string) error { - testsToExec, err := filters(c) - if err != nil { - return err - } - for _, elem := range testsToExec { - if err := elem(environment); err != nil { - return cli.Exit("", 1) - } - } - return nil -} - -func execLibrary(environment string) error { - if err := libraryTests.ExecLibraryTests(environment, authToken); err != nil { - return err - } - return nil -} - -func execUser(environment string) error { - if err := userTests.ExecUserTests(environment, authToken); err != nil { - return err - } - return nil -} - -func execAuth(environment string) error { - jwt, err := authTests.ExecAuthTests(environment) - if err != nil { - return err - } - authToken = jwt - return nil -}