Skip to content

Commit

Permalink
Update E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Jun 18, 2022
1 parent 6fb8f42 commit 426d87e
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cache/surrogate/providers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func uniqueTag(values []string) []string {
list := []string{}

for _, item := range values {
if item == "" {
continue
}
if _, found := tmp[item]; !found {
tmp[item] = true
list = append(list, item)
Expand Down Expand Up @@ -103,6 +106,7 @@ func (s *baseStorage) storeTag(tag string, cacheKey string, re *regexp.Regexp) {
if currentValue, b := s.Storage[tag]; s.dynamic || b {
if !re.MatchString(currentValue) {
s.Storage[tag] = currentValue + souinStorageSeparator + cacheKey
s.Storage[stalePrefix+tag] = currentValue + souinStorageSeparator + stalePrefix + cacheKey
}
}
}
Expand Down
165 changes: 163 additions & 2 deletions docs/e2e/Souin E2E.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,165 @@
"info": {
"_postman_id": "9f52cee6-d2bb-4c17-8169-1bd7126975f4",
"name": "Souin E2E",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "17806531"
},
"item": [
{
"name": "Beego",
"item": [
{
"name": "Default",
"event": [
{
"listen": "test",
"script": {
"exec": [
"utils.baseEndpoint(pm, `${utils.getVar(pm, 'app_url')}/default`, '', true)"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "Cache-Control",
"value": "",
"type": "text"
}
],
"url": {
"raw": "{{app_url}}/default",
"host": [
"{{app_url}}"
],
"path": [
"default"
]
}
},
"response": []
},
{
"name": "Default no cache",
"event": [
{
"listen": "test",
"script": {
"exec": [
"utils.baseEndpoint(pm, `${utils.getVar(pm, 'app_url')}/default`, 'no-cache')"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{app_url}}/default",
"host": [
"{{app_url}}"
],
"path": [
"default"
]
}
},
"response": []
},
{
"name": "Default no store",
"event": [
{
"listen": "test",
"script": {
"exec": [
"utils.baseEndpoint(pm, `${utils.getVar(pm, 'app_url')}/default`, 'no-store')"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "Cache-Control",
"value": "no-store",
"type": "text"
}
],
"url": {
"raw": "{{app_url}}/default",
"host": [
"{{app_url}}"
],
"path": [
"default"
]
}
},
"response": []
},
{
"name": "Exclude regex",
"event": [
{
"listen": "test",
"script": {
"exec": [
"utils.baseEndpoint(pm, `${utils.getVar(pm, 'app_url')}/test2`, '', false, true)"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "Cache-Control",
"value": "",
"type": "text"
}
],
"url": {
"raw": "{{app_url}}/excluded",
"host": [
"{{app_url}}"
],
"path": [
"excluded"
]
}
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
"pm.collectionVariables.set('app_url', pm.collectionVariables.get('beego_url'))"
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
]
},
{
"name": "Caddy",
"item": [
Expand Down Expand Up @@ -447,7 +603,7 @@
" 'Surrogate-Key': key,",
" },",
" method,",
" url: `${utils.getVar(pm, 'app_url')}${utils.getVar(pm, 'souin_base_api')}${utils.getVar(pm, 'souin_api')}/surrogate_keys`,",
" url: `${utils.getVar(pm, 'app_url')}${utils.getVar(pm, 'souin_base_api')}${utils.getVar(pm, 'souin_api')}${method != 'PURGE' ? '/surrogate_keys' : ''}`,",
"})",
"const KEYS = {",
" PREFIX: {",
Expand Down Expand Up @@ -2620,6 +2776,11 @@
{
"key": "app_url",
"value": ""
},
{
"key": "beego_url",
"value": "http://domain.com",
"type": "string"
}
]
}
5 changes: 2 additions & 3 deletions plugins/caddy/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
}
cdn {
dynamic
strategy hard
}
regex {
exclude /test2.*
Expand Down Expand Up @@ -77,9 +78,7 @@ route /no-reverse-proxy {
}

route /surrogate-keys {
cache {
ttl 1m
}
cache
header Surrogate-Key "KEY-{http.request.header.X-Surrogate-Key-Suffix}"
header Vary X-Surrogate-Key-Suffix
respond "Hello {http.request.header.X-Surrogate-Key-Suffix}"
Expand Down

0 comments on commit 426d87e

Please sign in to comment.