misc_SUITE.erl 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. %% Copyright (c) 2017, Loïc Hoguin <essen@ninenines.eu>
  2. %%
  3. %% Permission to use, copy, modify, and/or distribute this software for any
  4. %% purpose with or without fee is hereby granted, provided that the above
  5. %% copyright notice and this permission notice appear in all copies.
  6. %%
  7. %% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. %% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. %% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. %% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. %% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. %% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. %% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. -module(misc_SUITE).
  15. -compile(export_all).
  16. -import(ct_helper, [config/2]).
  17. -import(ct_helper, [doc/1]).
  18. -import(cowboy_test, [gun_open/1]).
  19. all() ->
  20. cowboy_test:common_all().
  21. groups() ->
  22. cowboy_test:common_groups(ct_helper:all(?MODULE)).
  23. init_per_group(Name, Config) ->
  24. cowboy_test:init_common_groups(Name, Config, ?MODULE).
  25. end_per_group(Name, _) ->
  26. cowboy:stop_listener(Name).
  27. init_dispatch(_) ->
  28. cowboy_router:compile([{"localhost", [
  29. {"/", hello_h, []}
  30. ]}]).
  31. set_env(Config) ->
  32. doc("Live replace a middleware environment value."),
  33. ConnPid1 = gun_open(Config),
  34. Ref1 = gun:get(ConnPid1, "/"),
  35. {response, _, 200, _} = gun:await(ConnPid1, Ref1),
  36. Listener = proplists:get_value(name, config(tc_group_properties, Config)),
  37. cowboy:set_env(Listener, dispatch, []),
  38. %% Only new connections get the updated environment.
  39. ConnPid2 = gun_open(Config),
  40. Ref2 = gun:get(ConnPid2, "/"),
  41. {response, _, 400, _} = gun:await(ConnPid2, Ref2),
  42. ok.