God bless unit tests

This commit is contained in:
Andrey Pokhilko
2022-02-21 21:43:11 +03:00
parent 204ec490ec
commit dbf522253f
3 changed files with 409 additions and 57 deletions

View File

@@ -538,6 +538,252 @@
"wait": -1,
"receive": 1
}
},
{
"startedDateTime": "2019-09-06T06:16:22.000000+00:00",
"time": 1,
"request": {
"method": "GET",
"url": "https://httpbin.org/param-patterns/prefix-fine",
"httpVersion": "",
"cookies": [],
"headers": [
],
"queryString": [],
"headersSize": -1,
"bodySize": -1,
"postData": {
"mimeType": "",
"text": ""
}
},
"response": {
"status": 200,
"statusText": "OK",
"httpVersion": "",
"cookies": [],
"headers": [
],
"content": {
"size": 0,
"mimeType": "",
"text": ""
},
"redirectURL": "",
"headersSize": -1,
"bodySize": 0
},
"cache": {},
"timings": {
"send": -1,
"wait": -1,
"receive": 1
}
},
{
"startedDateTime": "2019-09-06T06:16:22.000001+00:00",
"time": 1,
"request": {
"method": "GET",
"url": "https://httpbin.org/param-patterns/prefix-gibberish-sfdlasdfkadf87sd93284q24r",
"httpVersion": "",
"cookies": [],
"headers": [
],
"queryString": [],
"headersSize": -1,
"bodySize": -1,
"postData": {
"mimeType": "",
"text": ""
}
},
"response": {
"status": 200,
"statusText": "OK",
"httpVersion": "",
"cookies": [],
"headers": [
],
"content": {
"size": 0,
"mimeType": "",
"text": ""
},
"redirectURL": "",
"headersSize": -1,
"bodySize": 0
},
"cache": {},
"timings": {
"send": -1,
"wait": -1,
"receive": 1
}
},
{
"startedDateTime": "2019-09-06T06:16:22.000002+00:00",
"time": 1,
"request": {
"method": "GET",
"url": "https://httpbin.org/param-patterns/prefix-gibberish-adslkfasdf89sa7dfasddafa8a98sd7kansdf",
"httpVersion": "",
"cookies": [],
"headers": [
],
"queryString": [],
"headersSize": -1,
"bodySize": -1,
"postData": {
"mimeType": "",
"text": ""
}
},
"response": {
"status": 200,
"statusText": "OK",
"httpVersion": "",
"cookies": [],
"headers": [
],
"content": {
"size": 0,
"mimeType": "",
"text": ""
},
"redirectURL": "",
"headersSize": -1,
"bodySize": 0
},
"cache": {},
"timings": {
"send": -1,
"wait": -1,
"receive": 1
}
},
{
"startedDateTime": "2019-09-06T06:16:22.000003+00:00",
"time": 1,
"request": {
"method": "GET",
"url": "https://httpbin.org/param-patterns/prefix-gibberish-4jk5l2345h2452l4352435jlk45",
"httpVersion": "",
"cookies": [],
"headers": [
],
"queryString": [],
"headersSize": -1,
"bodySize": -1,
"postData": {
"mimeType": "",
"text": ""
}
},
"response": {
"status": 200,
"statusText": "OK",
"httpVersion": "",
"cookies": [],
"headers": [
],
"content": {
"size": 0,
"mimeType": "",
"text": ""
},
"redirectURL": "",
"headersSize": -1,
"bodySize": 0
},
"cache": {},
"timings": {
"send": -1,
"wait": -1,
"receive": 1
}
},
{
"startedDateTime": "2019-09-06T06:16:22.000004+00:00",
"time": 1,
"request": {
"method": "GET",
"url": "https://httpbin.org/param-patterns/prefix-gibberish-84395h2j4k35hj243j5h2kl34h54k",
"httpVersion": "",
"cookies": [],
"headers": [
],
"queryString": [],
"headersSize": -1,
"bodySize": -1,
"postData": {
"mimeType": "",
"text": ""
}
},
"response": {
"status": 200,
"statusText": "OK",
"httpVersion": "",
"cookies": [],
"headers": [
],
"content": {
"size": 0,
"mimeType": "",
"text": ""
},
"redirectURL": "",
"headersSize": -1,
"bodySize": 0
},
"cache": {},
"timings": {
"send": -1,
"wait": -1,
"receive": 1
}
},
{
"startedDateTime": "2019-09-06T06:16:22.000002+00:00",
"time": 1,
"request": {
"method": "GET",
"url": "https://httpbin.org/param-patterns/prefix-gibberish-afterwards",
"httpVersion": "",
"cookies": [],
"headers": [
],
"queryString": [],
"headersSize": -1,
"bodySize": -1,
"postData": {
"mimeType": "",
"text": ""
}
},
"response": {
"status": 200,
"statusText": "OK",
"httpVersion": "",
"cookies": [],
"headers": [
],
"content": {
"size": 0,
"mimeType": "",
"text": ""
},
"redirectURL": "",
"headersSize": -1,
"bodySize": 0
},
"cache": {},
"timings": {
"send": -1,
"wait": -1,
"receive": 1
}
}
]
}

View File

@@ -2,7 +2,7 @@
"openapi": "3.1.0",
"info": {
"title": "https://httpbin.org",
"description": "Mizu observed 13 entries (0 failed), at 0.155 hits/s, average response time is 0.251 seconds",
"description": "Mizu observed 19 entries (0 failed), at 0.106 hits/s, average response time is 0.172 seconds",
"version": "1.0"
},
"servers": [
@@ -15,7 +15,7 @@
"get": {
"summary": "/appears-once",
"description": "Mizu observed 1 entries (0 failed), at 0.000 hits/s, average response time is 0.630 seconds",
"operationId": "89aa39f6-78d0-411b-b701-a33bd77868b0",
"operationId": "eb3ca1f2-366b-4655-ab0f-e2c180e4c5fd",
"responses": {
"200": {
"description": "Successful call with status 200",
@@ -26,7 +26,6 @@
}
}
},
"x-last-seen-ts": 1567750580.0471218,
"x-counters-total": {
"entries": 1,
"failures": 0,
@@ -45,14 +44,15 @@
"sumDuration": 0
}
},
"x-sample-entry": 0
"x-sample-entry": 0,
"x-last-seen-ts": 1567750580.0471218
}
},
"/appears-twice": {
"get": {
"summary": "/appears-twice",
"description": "Mizu observed 2 entries (0 failed), at 0.500 hits/s, average response time is 0.630 seconds",
"operationId": "f5e2b5a2-e01a-45f4-bde1-15a7e7a06d3c",
"operationId": "d7e097be-9c43-4498-a696-1c1f2e1b09bf",
"responses": {
"200": {
"description": "Successful call with status 200",
@@ -63,6 +63,8 @@
}
}
},
"x-sample-entry": 0,
"x-last-seen-ts": 1567750581.7471218,
"x-counters-total": {
"entries": 2,
"failures": 0,
@@ -80,16 +82,14 @@
"sumRT": 1.26,
"sumDuration": 1
}
},
"x-sample-entry": 0,
"x-last-seen-ts": 1567750581.7471218
}
}
},
"/body-optional": {
"post": {
"summary": "/body-optional",
"description": "Mizu observed 3 entries (0 failed), at 0.003 hits/s, average response time is 0.001 seconds",
"operationId": "14d5b1c2-dc03-4ee5-baaa-5c7992acc82e",
"operationId": "69e1d67b-8642-48c9-ab2c-221057718e2d",
"responses": {
"200": {
"description": "Successful call with status 200",
@@ -98,15 +98,6 @@
}
}
},
"x-counters-total": {
"entries": 3,
"failures": 0,
"firstSeen": 1567750581.7471218,
"lastSeen": 1567750581.757122,
"sumRT": 0.003,
"sumDuration": 0.010000228881835938
},
"x-sample-entry": 0,
"x-counters-per-source": {
"": {
"entries": 3,
@@ -118,6 +109,15 @@
}
},
"x-last-seen-ts": 1567750581.757122,
"x-counters-total": {
"entries": 3,
"failures": 0,
"firstSeen": 1567750581.7471218,
"lastSeen": 1567750581.757122,
"sumRT": 0.003,
"sumDuration": 0.010000228881835938
},
"x-sample-entry": 0,
"requestBody": {
"description": "Generic request body",
"content": {
@@ -132,7 +132,7 @@
"post": {
"summary": "/body-required",
"description": "Mizu observed 1 entries (0 failed), at 0.000 hits/s, average response time is 0.001 seconds",
"operationId": "d0958c5a-dce6-4616-99f4-201dbc51457a",
"operationId": "4903b45c-d1d4-43d4-b029-7dde75f14cc6",
"responses": {
"200": {
"description": "Successful call with status 200",
@@ -141,6 +141,16 @@
}
}
},
"x-last-seen-ts": 1567750581.757122,
"x-counters-total": {
"entries": 1,
"failures": 0,
"firstSeen": 1567750581.757122,
"lastSeen": 1567750581.757122,
"sumRT": 0.001,
"sumDuration": 0
},
"x-sample-entry": 0,
"x-counters-per-source": {
"": {
"entries": 1,
@@ -151,16 +161,6 @@
"sumDuration": 0
}
},
"x-sample-entry": 0,
"x-counters-total": {
"entries": 1,
"failures": 0,
"firstSeen": 1567750581.757122,
"lastSeen": 1567750581.757122,
"sumRT": 0.001,
"sumDuration": 0
},
"x-last-seen-ts": 1567750581.757122,
"requestBody": {
"description": "Generic request body",
"content": {
@@ -176,7 +176,7 @@
"post": {
"summary": "/form-multipart",
"description": "Mizu observed 1 entries (0 failed), at 0.000 hits/s, average response time is 0.001 seconds",
"operationId": "cab5a2f3-c18a-4d5a-8f92-e40da4fd6603",
"operationId": "8c19c00b-db51-4eee-bbba-3e15d35ab7b9",
"responses": {
"200": {
"description": "Successful call with status 200",
@@ -187,7 +187,6 @@
}
}
},
"x-sample-entry": 0,
"x-counters-per-source": {
"": {
"entries": 1,
@@ -198,6 +197,7 @@
"sumDuration": 0
}
},
"x-sample-entry": 0,
"x-last-seen-ts": 1567750582.7471218,
"x-counters-total": {
"entries": 1,
@@ -244,7 +244,7 @@
"post": {
"summary": "/form-urlencoded",
"description": "Mizu observed 2 entries (0 failed), at 0.500 hits/s, average response time is 0.001 seconds",
"operationId": "7c373ad7-6ab5-422e-971b-1cf56b18a7a2",
"operationId": "1e270769-e6a6-4e1a-a541-38423b9a2fa4",
"responses": {
"200": {
"description": "Successful call with status 200",
@@ -253,15 +253,6 @@
}
}
},
"x-last-seen-ts": 1567750581.7471218,
"x-counters-total": {
"entries": 2,
"failures": 0,
"firstSeen": 1567750580.7471218,
"lastSeen": 1567750581.7471218,
"sumRT": 0.002,
"sumDuration": 1
},
"x-counters-per-source": {
"": {
"entries": 2,
@@ -273,6 +264,15 @@
}
},
"x-sample-entry": 0,
"x-last-seen-ts": 1567750581.7471218,
"x-counters-total": {
"entries": 2,
"failures": 0,
"firstSeen": 1567750580.7471218,
"lastSeen": 1567750581.7471218,
"sumRT": 0.002,
"sumDuration": 1
},
"requestBody": {
"description": "Generic request body",
"content": {
@@ -319,11 +319,116 @@
}
}
},
"/param-patterns/prefix-fine": {
"get": {
"tags": [
"param-patterns"
],
"summary": "/param-patterns/prefix-fine",
"description": "Mizu observed 1 entries (0 failed), at 0.000 hits/s, average response time is 0.001 seconds",
"operationId": "34b05cea-6bb2-411d-8f9b-f285a2770757",
"responses": {
"200": {
"description": "Successful call with status 200",
"content": {
"": {}
}
}
},
"x-counters-total": {
"entries": 1,
"failures": 0,
"firstSeen": 1567750582,
"lastSeen": 1567750582,
"sumRT": 0.001,
"sumDuration": 0
},
"x-counters-per-source": {
"": {
"entries": 1,
"failures": 0,
"firstSeen": 1567750582,
"lastSeen": 1567750582,
"sumRT": 0.001,
"sumDuration": 0
}
},
"x-last-seen-ts": 1567750582,
"x-sample-entry": 0
}
},
"/param-patterns/{parampatternId}": {
"get": {
"tags": [
"param-patterns"
],
"summary": "/param-patterns/{parampatternId}",
"description": "Mizu observed 5 entries (0 failed), at 0.000 hits/s, average response time is 0.001 seconds",
"operationId": "50a499dc-8fa1-43b2-9db5-ae20405e4e98",
"responses": {
"200": {
"description": "Successful call with status 200",
"content": {
"": {}
}
}
},
"x-sample-entry": 0,
"x-last-seen-ts": 1567750582.000002,
"x-counters-total": {
"entries": 5,
"failures": 0,
"firstSeen": 1567750582.000001,
"lastSeen": 1567750582.000004,
"sumRT": 0.005,
"sumDuration": 0.0000030994415283203125
},
"x-counters-per-source": {
"": {
"entries": 5,
"failures": 0,
"firstSeen": 1567750582.000001,
"lastSeen": 1567750582.000004,
"sumRT": 0.005,
"sumDuration": 0.0000030994415283203125
}
}
},
"parameters": [
{
"name": "parampatternId",
"in": "path",
"required": true,
"style": "simple",
"schema": {
"type": "string",
"pattern": "^prefix-gibberish-.+"
},
"examples": {
"example #0": {
"value": "prefix-gibberish-sfdlasdfkadf87sd93284q24r"
},
"example #1": {
"value": "prefix-gibberish-adslkfasdf89sa7dfasddafa8a98sd7kansdf"
},
"example #2": {
"value": "prefix-gibberish-4jk5l2345h2452l4352435jlk45"
},
"example #3": {
"value": "prefix-gibberish-84395h2j4k35hj243j5h2kl34h54k"
},
"example #4": {
"value": "prefix-gibberish-afterwards"
}
}
}
]
},
"/{Id}": {
"get": {
"summary": "/{Id}",
"description": "Mizu observed 1 entries (0 failed), at 0.000 hits/s, average response time is 0.630 seconds",
"operationId": "99f1d11f-29c0-48f9-8bf0-9f4b407c7c3f",
"operationId": "1f1d5803-b1c9-4732-92ab-ebcc257cd08c",
"responses": {
"200": {
"description": "Successful call with status 200",
@@ -334,7 +439,6 @@
}
}
},
"x-sample-entry": 0,
"x-last-seen-ts": 1567750579.7471218,
"x-counters-total": {
"entries": 1,
@@ -353,7 +457,8 @@
"sumRT": 0.63,
"sumDuration": 0
}
}
},
"x-sample-entry": 0
},
"parameters": [
{
@@ -379,7 +484,7 @@
"get": {
"summary": "/{Id}/sub1",
"description": "Mizu observed 1 entries (0 failed), at 0.000 hits/s, average response time is 0.111 seconds",
"operationId": "f7e299d2-253c-4eef-975c-9a5659a7fc50",
"operationId": "21f3b102-b4c3-472f-b868-038d4a824dac",
"responses": {
"200": {
"description": "Successful call with status 200",
@@ -388,6 +493,7 @@
}
}
},
"x-sample-entry": 0,
"x-last-seen-ts": 1567750483.864529,
"x-counters-total": {
"entries": 1,
@@ -406,8 +512,7 @@
"sumRT": 0.111,
"sumDuration": 0
}
},
"x-sample-entry": 0
}
},
"parameters": [
{
@@ -433,7 +538,7 @@
"get": {
"summary": "/{Id}/sub2",
"description": "Mizu observed 1 entries (0 failed), at 0.000 hits/s, average response time is 0.630 seconds",
"operationId": "23a54e06-4298-4ea5-b1f0-09b0354a0598",
"operationId": "f4fc84f6-d5f1-48a0-b45d-57fb907467c3",
"responses": {
"200": {
"description": "Successful call with status 200",
@@ -444,7 +549,6 @@
}
}
},
"x-last-seen-ts": 1567750578.7471218,
"x-counters-total": {
"entries": 1,
"failures": 0,
@@ -463,7 +567,8 @@
"sumDuration": 0
}
},
"x-sample-entry": 0
"x-sample-entry": 0,
"x-last-seen-ts": 1567750578.7471218
},
"parameters": [
{
@@ -487,21 +592,21 @@
}
},
"x-counters-total": {
"entries": 13,
"entries": 19,
"failures": 0,
"firstSeen": 1567750483.864529,
"lastSeen": 1567750582.7471218,
"sumRT": 3.268,
"sumDuration": 2.010000228881836
"sumRT": 3.274,
"sumDuration": 2.0100033283233643
},
"x-counters-per-source": {
"": {
"entries": 13,
"entries": 19,
"failures": 0,
"firstSeen": 1567750483.864529,
"lastSeen": 1567750582.7471218,
"sumRT": 3.268,
"sumDuration": 2.010000228881836
"sumRT": 3.274,
"sumDuration": 2.0100033283233643
}
}
}

View File

@@ -137,7 +137,7 @@ func getPatternFromExamples(exmp *openapi.Examples) *openapi.Regexp {
if pat != ".+" {
re := new(openapi.Regexp)
re.Regexp = regexp.MustCompile(`\d+`)
re.Regexp = regexp.MustCompile(pat)
return re
}
}
@@ -352,6 +352,7 @@ outer:
matchedConst := oChild.constant != nil && oChild.constant == nChild.constant
matchedParam := oChild.constant == nil && nChild.constant == nil
if matchedConst || matchedParam {
// TODO: if both are params, could have merged their examples
nChild.merge(oChild)
continue outer
}