Skip to content

Commit

Permalink
fix(ci): newman and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Apr 18, 2024
1 parent 492256e commit 795324a
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 48 deletions.
55 changes: 37 additions & 18 deletions docs/e2e/Souin E2E.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -3339,12 +3339,12 @@
"type": "text/javascript",
"exec": [
"utils = {",
" request: (url, cacheControl = '', body = null, headers = {}) => ({",
" request: (url, cacheControl = '', body = null, headers = {}, method = 'GET') => ({",
" header: {",
" 'Cache-Control': cacheControl,",
" ...headers,",
" },",
" method: 'GET',",
" method,",
" body,",
" url,",
" }),",
Expand Down Expand Up @@ -3579,33 +3579,42 @@
" souinAPI: {",
" listKeys: (pm, baseKey, baseUrl = '', additionalPath = '', cacheControl = '') => {",
" const isCached = cacheControl == ''",
" pm.test(\"Ensure stored keys array is empty\", function () {",
" pm.test(\"Ensure stored keys array contains only one element\", function () {",
" pm.response.to.have.status(200);",
" let jsonData = pm.response.json();",
" pm.expect(jsonData).to.eql([\"IDX_GET-http-localhost:4443-/default\"]);",
" pm.expect(jsonData).to.eql([\"GET-http-localhost:4443-/default\"]);",
" pm.expect(jsonData.length).to.eql(1);",
" });",
" pm.sendRequest(utils.request(baseUrl + additionalPath, cacheControl), function(_, response) {",
" pm.expect(response).to.have.status(200);",
" pm.sendRequest(utils.request(`${baseUrl}${utils.getVar(pm, 'souin_base_api')}${utils.getVar(pm, 'souin_api')}`, cacheControl), function (_, res) {",
" pm.test(`Check Souin API has ${isCached ? 'three' : 'none'} registered key after the first cache set`, function () {",
" pm.test(`Check Souin API has ${isCached ? 'two' : 'none'} registered key after the first cache set`, function () {",
" pm.expect(res).to.have.status(200);",
" let jsonData = res.json();",
" pm.expect(jsonData.length).to.eql(isCached ? 3 : 0);",
" pm.expect(jsonData[0]).to.eql(isCached ? baseKey : undefined);",
" pm.expect(jsonData[1]).to.eql(isCached ? 'IDX_GET-http-localhost:4443-/default' : undefined);",
" pm.expect(jsonData[2]).to.eql(isCached ? 'IDX_GET-http-localhost:4443-/test1' : undefined);",
" pm.expect(jsonData.length).to.eql(isCached ? 2 : 0);",
" pm.expect(jsonData[0]).to.eql(isCached ? 'GET-http-localhost:4443-/default' : undefined);",
" pm.expect(jsonData[1]).to.eql(isCached ? 'GET-http-localhost:4443-/test1' : undefined);",
" }",
" );",
"",
" pm.sendRequest(utils.request(baseUrl + additionalPath + 'testing', cacheControl), function() {",
" pm.sendRequest(utils.request(`${baseUrl}${utils.getVar(pm, 'souin_base_api')}${utils.getVar(pm, 'souin_api')}`, cacheControl), function (_, r) {",
" pm.test(`Check Souin API has ${isCached ? 'five' : 'none'} registered key${isCached ? 's' : ''} after the second cache set`, function () {",
" pm.test(`Check Souin API has ${isCached ? 'three' : 'none'} registered key${isCached ? 's' : ''} after the second cache set`, function () {",
" pm.expect(r).to.have.status(200);",
" pm.expect(r).to.not.have.header(\"Cache-Status\");",
" pm.expect(r).to.not.have.header(\"Age\");",
" let jsonData = r.json();",
" pm.expect(jsonData.length).to.eql(isCached ? 5 : 0);",
" pm.expect(jsonData.length).to.eql(isCached ? 3 : 0);",
" });",
" pm.sendRequest(utils.request(`${baseUrl}${utils.getVar(pm, 'souin_base_api')}${utils.getVar(pm, 'souin_api')}/flush`, cacheControl, null, {}, 'PURGE'), function (_, r) {",
" pm.expect(r).to.have.status(204);",
" pm.sendRequest(utils.request(`${baseUrl}${utils.getVar(pm, 'souin_base_api')}${utils.getVar(pm, 'souin_api')}`, cacheControl), function (_, r) {",
" pm.expect(r).to.have.status(200);",
" pm.expect(r).to.not.have.header(\"Cache-Status\");",
" pm.expect(r).to.not.have.header(\"Age\");",
" let jsonData = r.json();",
" pm.expect(jsonData.length).to.eql(0);",
" });",
" });",
" });",
" });",
Expand All @@ -3623,30 +3632,40 @@
" pm.test(\"Ensure stored keys array is empty\", function () {",
" pm.response.to.have.status(200);",
" let jsonData = pm.response.json();",
" // pm.expect(jsonData).to.eql([]);",
" pm.expect(jsonData.length).to.eql(3);",
" pm.expect(jsonData).to.eql([]);",
" pm.expect(jsonData.length).to.eql(0);",
" });",
" pm.sendRequest(rq, function(_, response) {",
" pm.expect(response).to.have.status(200);",
"",
" pm.sendRequest(utils.request(`${baseUrl}${utils.getVar(pm, 'souin_base_api')}${utils.getVar(pm, 'souin_api')}`, cacheControl), function (_, res) {",
" pm.test(`Check Souin API has ${isCached ? 'two' : 'none'} registered key after the first cache set`, function () {",
" pm.test(`Check Souin API has ${isCached ? 'one' : 'none'} registered key after the first cache set`, function () {",
" pm.expect(res).to.have.status(200);",
" let jsonData = res.json();",
" pm.expect(jsonData.length).to.eql(isCached ? 5 : 0);",
" // pm.expect(jsonData[4]).to.include(isCached ? baseKey : undefined);",
" pm.expect(jsonData.length).to.eql(isCached ? 1 : 0);",
" pm.expect(jsonData[0]).to.include(isCached ? 'POST-http-localhost:4443-/test1-4d08c8e90fed197693d96603c73fa6036e7ce42b8de0149cdd33b34e980631e2' : undefined);",
" }",
" );",
"",
" rq.url = baseUrl + additionalPath + 'testing'",
" pm.sendRequest(rq, function() {",
" pm.sendRequest(utils.request(`${baseUrl}${utils.getVar(pm, 'souin_base_api')}${utils.getVar(pm, 'souin_api')}`, cacheControl), function (_, r) {",
" pm.test(`Check Souin API has ${isCached ? 'four' : 'none'} registered key${isCached ? 's' : ''} after the second cache set`, function () {",
" pm.test(`Check Souin API has ${isCached ? 'two' : 'none'} registered key${isCached ? 's' : ''} after the second cache set`, function () {",
" pm.expect(r).to.have.status(200);",
" pm.expect(r).to.not.have.header(\"Cache-Status\");",
" pm.expect(r).to.not.have.header(\"Age\");",
" let jsonData = r.json();",
" pm.expect(jsonData.length).to.eql(isCached ? 7 : 0);",
" pm.expect(jsonData.length).to.eql(isCached ? 2 : 0);",
" });",
" pm.sendRequest(utils.request(`${baseUrl}${utils.getVar(pm, 'souin_base_api')}${utils.getVar(pm, 'souin_api')}/flush`, cacheControl, null, {}, 'PURGE'), function (_, r) {",
" pm.expect(r).to.have.status(204);",
" pm.sendRequest(utils.request(`${baseUrl}${utils.getVar(pm, 'souin_base_api')}${utils.getVar(pm, 'souin_api')}`, cacheControl), function (_, r) {",
" pm.expect(r).to.have.status(200);",
" pm.expect(r).to.not.have.header(\"Cache-Status\");",
" pm.expect(r).to.not.have.header(\"Age\");",
" let jsonData = r.json();",
" pm.expect(jsonData.length).to.eql(0);",
" });",
" });",
" });",
" });",
Expand Down
6 changes: 3 additions & 3 deletions plugins/beego/souin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ func Test_SouinBeegoPlugin_Middleware_APIHandle(t *testing.T) {
defer res2.Result().Body.Close()
var payload []string
_ = json.Unmarshal(b, &payload)
if len(payload) != 2 {
t.Error("The system must store 2 items, the fresh and the stale one")
if len(payload) != 1 {
t.Error("The system must store 1 item, excluding the mapping")
}
if payload[0] != "GET-http-example.com-/handled" || payload[1] != "IDX_GET-http-example.com-/handled" {
if payload[0] != "GET-http-example.com-/handled" {
t.Error("The payload items mismatch from the expectations.")
}
}
6 changes: 3 additions & 3 deletions plugins/chi/souin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ func Test_SouinChiPlugin_Middleware_APIHandle(t *testing.T) {
res2.Result().Body.Close()
var payload []string
_ = json.Unmarshal(b, &payload)
if len(payload) != 2 {
t.Error("The system must store 2 items, the fresh and the stale one")
if len(payload) != 1 {
t.Error("The system must store 1 item, excluding the mapping")
}
if payload[0] != "GET-http-example.com-/handled" || payload[1] != "IDX_GET-http-example.com-/handled" {
if payload[0] != "GET-http-example.com-/handled" {
t.Error("The payload items mismatch from the expectations.")
}
}
6 changes: 3 additions & 3 deletions plugins/dotweb/souin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ func Test_SouinDotwebPlugin_Middleware_APIHandle(t *testing.T) {
res2.Result().Body.Close()
var payload []string
_ = json.Unmarshal(b, &payload)
if len(payload) != 2 {
t.Error("The system must store 2 items, the fresh and the stale one")
if len(payload) != 1 {
t.Error("The system must store 1 item, excluding the mapping")
}
if payload[0] != "GET-http-example.com-/handled" || payload[1] != "IDX_GET-http-example.com-/handled" {
if payload[0] != "GET-http-example.com-/handled" {
t.Error("The payload items mismatch from the expectations.")
}
}
6 changes: 3 additions & 3 deletions plugins/echo/souin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ func Test_SouinEchoPlugin_Process_APIHandle(t *testing.T) {
defer res.Result().Body.Close()
var payload []string
_ = json.Unmarshal(b, &payload)
if len(payload) != 2 {
t.Error("The system must store 2 items, the fresh and the stale one")
if len(payload) != 1 {
t.Error("The system must store 1 item, excluding the mapping")
}
if payload[0] != "GET-http-example.com-/handled" || payload[1] != "IDX_GET-http-example.com-/handled" {
if payload[0] != "GET-http-example.com-/handled" {
t.Error("The payload items mismatch from the expectations.")
}
}
6 changes: 3 additions & 3 deletions plugins/fiber/souin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ func Test_SouinFiberPlugin_Middleware_APIHandle(t *testing.T) {
res.Body.Close()
var payload []string
_ = json.Unmarshal(b, &payload)
if len(payload) != 2 {
t.Error("The system must store 2 items, the fresh and the stale one")
if len(payload) != 1 {
t.Error("The system must store 1 item, excluding the mapping")
}
if payload[0] != "GET-http-example.com-/handled" || payload[1] != "IDX_GET-http-example.com-/handled" {
if payload[0] != "GET-http-example.com-/handled" {
t.Error("The payload items mismatch from the expectations.")
}
}
6 changes: 3 additions & 3 deletions plugins/go-zero/souin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ func Test_SouinGoZeroPlugin_Middleware_APIHandle(t *testing.T) {
res2.Result().Body.Close()
var payload []string
_ = json.Unmarshal(b, &payload)
if len(payload) != 2 {
t.Error("The system must store 2 items, the fresh and the stale one")
if len(payload) != 1 {
t.Error("The system must store 1 item, excluding the mapping")
}
if payload[0] != "GET-http-example.com-/handled" || payload[1] != "IDX_GET-http-example.com-/handled" {
if payload[0] != "GET-http-example.com-/handled" {
t.Error("The payload items mismatch from the expectations.")
}
}
6 changes: 3 additions & 3 deletions plugins/goa/souin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ func Test_SouinGoaPlugin_Middleware_APIHandle(t *testing.T) {
res2.Result().Body.Close()
var payload []string
_ = json.Unmarshal(b, &payload)
if len(payload) != 3 {
t.Error("The system must store 2 items, the fresh and the stale one")
if len(payload) != 1 {
t.Error("The system must store 1 item, excluding the mapping")
}
if payload[0] != "GET-http-example.com-/handled" || payload[1] != "IDX_GET-http-example.com-/handled" {
if payload[0] != "GET-http-example.com-/handled" {
t.Error("The payload items mismatch from the expectations.")
}
}
6 changes: 3 additions & 3 deletions plugins/goyave/souin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ func (suite *HttpCacheMiddlewareTestSuite) Test_SouinFiberPlugin_Middleware_APIH
res.Body.Close()
var payload []string
_ = json.Unmarshal(b, &payload)
if len(payload) != 2 {
suite.T().Error("The system must store 2 items, the fresh and the stale one")
if len(payload) != 1 {
suite.T().Error("The system must store 1 item, excluding the mapping")
}
if payload[0] != "GET-http-example.com-/handled" || payload[1] != "IDX_GET-http-example.com-/handled" {
if payload[0] != "GET-http-example.com-/handled" {
suite.T().Error("The payload items mismatch from the expectations.")
}
}
6 changes: 3 additions & 3 deletions plugins/roadrunner/httpcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ func Test_Plugin_Middleware_API(t *testing.T) {
}
var payload []string
_ = json.Unmarshal(b, &payload)
if len(payload) != 2 {
t.Error("The system must store 2 items, the fresh and the stale one")
if len(payload) != 1 {
t.Error("The system must store 1 item, excluding the mapping")
}
if payload[0] != "GET-http-example.com-/handled" || payload[1] != "IDX_GET-http-example.com-/handled" {
if payload[0] != "GET-http-example.com-/handled" {
t.Error("The payload items mismatch from the expectations.")
}
}
6 changes: 3 additions & 3 deletions plugins/webgo/souin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ func Test_SouinWebgoPlugin_Middleware_APIHandle(t *testing.T) {
defer res2.Result().Body.Close()
var payload []string
_ = json.Unmarshal(b, &payload)
if len(payload) != 2 {
t.Error("The system must store 2 items, the fresh and the stale one")
if len(payload) != 1 {
t.Error("The system must store 1 item, excluding the mapping")
}
if payload[0] != "GET-http-example.com-/handled" || payload[1] != "IDX_GET-http-example.com-/handled" {
if payload[0] != "GET-http-example.com-/handled" {
t.Error("The payload items mismatch from the expectations.")
}
}

0 comments on commit 795324a

Please sign in to comment.