test-nginx icon indicating copy to clipboard operation
test-nginx copied to clipboard

How to mock out downstream calls

Open ktalebian opened this issue 6 years ago • 6 comments

How can I mock the downstream services for these Nginx tests?

ktalebian avatar Nov 08 '19 00:11 ktalebian

++

patthiel avatar Oct 01 '20 19:10 patthiel

What protocol? custom TCP? http? It's possible to extend the test scaffold to support very ad-hoc clients. You can check the existing features as examples.

agentzh avatar Oct 01 '20 21:10 agentzh

my intention was to set up nginx virtual servers that would respond with canned mock service responses. Similar set up to the one layed out here: https://underthehood.meltwater.com/blog/2017/12/12/lightweight-tests-for-your-nginx-api-gateway/

i was hoping i could have multiple server blocks defined in one test config.. i haven't quite figured it all out yet, but i found this page helpful: https://openresty.gitbooks.io/programming-openresty/content/testing/testing-erroneous-cases.html

along with a few other open source examples of using the tcp section : https://github.com/dome/lixen_app/blob/2e9d209e1b800caac1f4a4b98352d59f41b903b3/bundle/srcache-nginx-module-0.24/t/timeout.t

Do you have a recommended approach for mocking downstream calls for http?

patthiel avatar Oct 01 '20 21:10 patthiel

@ktalebian Have you tried the --- http_config section? You can define your own server blocks there. It's commonly used in, say, ngx_lua's test suite.

agentzh avatar Oct 01 '20 23:10 agentzh

@ktalebian The title of this ticket says "downstream calls", which means client side, instead of server side. So I don't think your requirements fit in this github issue.

agentzh avatar Oct 01 '20 23:10 agentzh

@agentzh my misunderstanding 😅

patthiel avatar Oct 02 '20 20:10 patthiel