diff options
author | Tommy Carpenter <tommy@research.att.com> | 2017-09-26 10:18:21 -0400 |
---|---|---|
committer | Tommy Carpenter <tommy@research.att.com> | 2017-09-26 10:19:10 -0400 |
commit | 483289371744c88d60a887252a2634a867e023d7 (patch) | |
tree | e6452320a0e2bfb9ce78d85f6f52f38306fd350f /src/cdap_interface_tests.erl | |
parent | 4d68a25267d0173b13e6238d76274dc874967872 (diff) |
Add unit testing for consul_interface
Issue-ID: DCAEGEN2-99
Change-Id: I66af63cfe523227a515ae5e81ba0e2fe32f4cb2f
Signed-off-by: Tommy Carpenter <tommy@research.att.com>
Diffstat (limited to 'src/cdap_interface_tests.erl')
-rw-r--r-- | src/cdap_interface_tests.erl | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/src/cdap_interface_tests.erl b/src/cdap_interface_tests.erl index c1d1e6c..6270f4f 100644 --- a/src/cdap_interface_tests.erl +++ b/src/cdap_interface_tests.erl @@ -29,15 +29,61 @@ form_service_json_from_service_tuple/4, get_app_preferences/4, get_app_config/4, - get_pipeline_healthcheck/5 + get_pipeline_healthcheck/5, + get_app_healthcheck_program/5 ]). +-include("application.hrl"). + +get_app_healthcheck_program_test() -> + P = #program{type = <<"flows">>, id = <<"WhoFlow">>}, + try meck:new(httpabs, [passthrough]) catch _:_ -> ok end, + + %not found + meck:expect(httpabs, get, fun(_XER, URL) -> case URL of + "http://666.666.666.666:666/v3/namespaces/testns/apps/1234appNOTFOUND/flows/WhoFlow" -> {404, ""} + end end), + ?assert(get_app_healthcheck_program("", "1234%%%%^@#$%@#$%#$^@$.appNOTFOUND", "testns", "http://666.666.666.666:666", P) == 400), + + %found but malformed status + MalformedReturn = jiffy:encode({[{<<"nostatus">>, <<"FOR YOU">>}]}), + meck:expect(httpabs, get, fun(_XER, URL) -> case URL of + "http://666.666.666.666:666/v3/namespaces/testns/apps/1234appNOTFOUND/flows/WhoFlow" -> {200, ""}; + "http://666.666.666.666:666/v3/namespaces/testns/apps/1234appNOTFOUND/flows/WhoFlow/status" -> {200, MalformedReturn} + end end), + ?assert(get_app_healthcheck_program("", "1234%%%%^@#$%@#$%#$^@$.appNOTFOUND", "testns", "http://666.666.666.666:666", P) == 400), + + %bad status code + BadStatus = jiffy:encode({[{<<"status">>, <<"NOTRUNNING">>}]}), + meck:expect(httpabs, get, fun(_XER, URL) -> case URL of + "http://666.666.666.666:666/v3/namespaces/testns/apps/1234appNOTFOUND/flows/WhoFlow" -> {200, ""}; + "http://666.666.666.666:666/v3/namespaces/testns/apps/1234appNOTFOUND/flows/WhoFlow/status" -> {500, BadStatus} + end end), + ?assert(get_app_healthcheck_program("", "1234%%%%^@#$%@#$%#$^@$.appNOTFOUND", "testns", "http://666.666.666.666:666", P) == 400), + + %found but bad status + BadReturn = jiffy:encode({[{<<"status">>, <<"NOTRUNNING">>}]}), + meck:expect(httpabs, get, fun(_XER, URL) -> case URL of + "http://666.666.666.666:666/v3/namespaces/testns/apps/1234appNOTFOUND/flows/WhoFlow" -> {200, ""}; + "http://666.666.666.666:666/v3/namespaces/testns/apps/1234appNOTFOUND/flows/WhoFlow/status" -> {200, BadReturn} + end end), + ?assert(get_app_healthcheck_program("", "1234%%%%^@#$%@#$%#$^@$.appNOTFOUND", "testns", "http://666.666.666.666:666", P) == 400), + + %all good + GoodReturn = jiffy:encode({[{<<"status">>, <<"RUNNING">>}]}), + meck:expect(httpabs, get, fun(_XER, URL) -> case URL of + "http://666.666.666.666:666/v3/namespaces/testns/apps/1234appNOTFOUND/flows/WhoFlow" -> {200, ""}; + "http://666.666.666.666:666/v3/namespaces/testns/apps/1234appNOTFOUND/flows/WhoFlow/status" -> {200, GoodReturn} + end end), + ?assert(get_app_healthcheck_program("", "1234%%%%^@#$%@#$%#$^@$.appNOTFOUND", "testns", "http://666.666.666.666:666", P) == 200), + + meck:unload(httpabs). + get_pipeline_healthcheck_test() -> FakeReturn = jiffy:encode({[{<<"status">>, <<"SCHEDULED">>}]}), try meck:new(httpabs, [passthrough]) catch _:_ -> ok end, %notfound meck:expect(httpabs, get, fun(_XER, URL) -> case URL of - "http://666.666.666.666:666/v3/namespaces/testns/apps/1234app/schedules/dataPipelineSchedule/status" -> {200, FakeReturn}; "http://666.666.666.666:666/v3/namespaces/testns/apps/1234appNOTFOUND/schedules/dataPipelineSchedule/status" -> {404, ""} end end), ?assert(get_pipeline_healthcheck("", "1234%%%%^@#$%@#$%#$^@$.appNOTFOUND", "testns", "http://666.666.666.666:666", 666) == 400), |