aboutsummaryrefslogtreecommitdiffstats
path: root/src/util_tests.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/util_tests.erl')
-rw-r--r--src/util_tests.erl60
1 files changed, 59 insertions, 1 deletions
diff --git a/src/util_tests.erl b/src/util_tests.erl
index 78ca851..1774fb5 100644
--- a/src/util_tests.erl
+++ b/src/util_tests.erl
@@ -25,7 +25,9 @@
ip_to_str/1,
update_with_new_config_map/2,
ejson_to_map/1,
- to_str/1
+ to_str/1,
+ get_platform_envs_and_config/0,
+ resolve_cbs/2
]).
to_str_test() ->
@@ -57,3 +59,59 @@ ejson_to_map_test() ->
?assert(EJ1 /= EJ2), %HERE LIES THE PROBLEM HUDSON
?assert(M1 == M2). %GREAT SUCCESS!
+get_platform_envs_and_config_test() ->
+ try meck:new(util, [passthrough]) catch _:_ -> ok end,
+ try meck:new(consul_interface, [passthrough]) catch _:_ -> ok end,
+
+ %test no envs
+ meck:expect(util, get_envs, fun() -> {"", false, <<"cdap_test">>} end),
+ ?assert(get_platform_envs_and_config() == []),
+
+ %test good case where the env variable is passed
+ %needed monkeypatching
+ FakeConfig = {[
+ {<<"autoderegisterafter">>, <<"10m">>},
+ {<<"bindingttw">>,5},
+ {<<"pipelinehealthlimit">>, 2},
+ {<<"hcinterval">>, <<"60s">>}
+ ]},
+ FakeBrokerName = "cdap_broker_test",
+ FakeConsulName = "myconsuldotcom",
+ meck:expect(util, get_envs, fun() -> {FakeBrokerName, FakeConsulName, <<"cdap_test">>} end),
+ meck:expect(consul_interface, consul_bind_config, fun(_XER, _MyName, _ConsulURL) -> {200, FakeConfig} end),
+ meck:expect(consul_interface, consul_get_service_ip_port, fun(_XER, Appname, _ConsulURL) ->
+ case Appname of
+ <<"cdap_test">> -> {"666.666.666.666", 666}
+ end
+ end),
+
+ ?assert(get_platform_envs_and_config() == [FakeBrokerName, "http://myconsuldotcom:8500", <<"http://666.666.666.666:666">>, jiffy:decode(jiffy:encode(FakeConfig), [return_maps])]),
+
+ %test bad case where env is not passed
+ meck:expect(util, get_envs, fun() -> {FakeBrokerName, FakeConsulName, false} end),
+ FakeConfigwCDAP = {[
+ {<<"autoderegisterafter">>, <<"10m">>},
+ {<<"bindingttw">>,5},
+ {<<"pipelinehealthlimit">>, 2},
+ {<<"hcinterval">>, <<"60s">>},
+ {<<"cdap_cluster_to_manage">>, [<<"666.666.666.666:666">>]}
+ ]},
+ meck:expect(consul_interface, consul_bind_config, fun(_XER, _MyName, _ConsulURL) -> {200, FakeConfigwCDAP} end),
+ ?assert(get_platform_envs_and_config() == [FakeBrokerName, "http://myconsuldotcom:8500", <<"http://666.666.666.666:666">>, jiffy:decode(jiffy:encode(FakeConfigwCDAP), [return_maps])]),
+
+ meck:unload(util),
+ meck:unload(consul_interface).
+
+resolve_cbs_test() ->
+ try meck:new(consul_interface, [passthrough]) catch _:_ -> ok end,
+ meck:expect(consul_interface, consul_get_service_ip_port, fun(_XER, Appname, _ConsulURL) ->
+ case Appname of
+ "config_binding_service" -> {"666.666.666.666", 10000}
+ end
+ end),
+ ?assert(resolve_cbs("", "") == "http://666.666.666.666:10000"),
+ meck:unload(consul_interface).
+
+
+
+