aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTommy Carpenter <tommy@research.att.com>2017-09-26 10:18:21 -0400
committerTommy Carpenter <tommy@research.att.com>2017-09-26 10:19:10 -0400
commit483289371744c88d60a887252a2634a867e023d7 (patch)
treee6452320a0e2bfb9ce78d85f6f52f38306fd350f
parent4d68a25267d0173b13e6238d76274dc874967872 (diff)
Add unit testing for consul_interface
Issue-ID: DCAEGEN2-99 Change-Id: I66af63cfe523227a515ae5e81ba0e2fe32f4cb2f Signed-off-by: Tommy Carpenter <tommy@research.att.com>
-rw-r--r--Changelog.md3
-rw-r--r--rebar.config3
-rw-r--r--src/cdap_interface_tests.erl50
-rw-r--r--src/cdapbroker.app.src2
-rw-r--r--src/consul_interface_tests.erl88
-rw-r--r--src/util_tests.erl3
-rw-r--r--swagger/swagger.yaml2
7 files changed, 143 insertions, 8 deletions
diff --git a/Changelog.md b/Changelog.md
index 393f1ba..14ad272 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
+## [4.0.9] - Sep 26 2017
+* Add unit tests for consul_interface, 32% now
+
## [4.0.8] - Sep 25 2017
* Greatly increase unit tests, at 27% now
diff --git a/rebar.config b/rebar.config
index 91ed457..7b57ec3 100644
--- a/rebar.config
+++ b/rebar.config
@@ -1,6 +1,6 @@
{relx, [
{release,
- {cdapbroker,"4.0.8"},
+ {cdapbroker,"4.0.9"},
[cdapbroker]
},
%{extend_start_script,true},
@@ -72,6 +72,7 @@
workflows_tests,
httpabs_tests,
util_tests,
+ consul_interface_tests,
%sup is out of the box OTP
cdapbroker_sup
]}.
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),
diff --git a/src/cdapbroker.app.src b/src/cdapbroker.app.src
index f5a1821..08fc59d 100644
--- a/src/cdapbroker.app.src
+++ b/src/cdapbroker.app.src
@@ -1,6 +1,6 @@
{application, cdapbroker,
[{description, "Interface between Consul and CDAP in DCAE"},
- {vsn, "4.0.8"},
+ {vsn, "4.0.9"},
{registered, []},
{mod, { cdapbroker_app, []}},
{applications,
diff --git a/src/consul_interface_tests.erl b/src/consul_interface_tests.erl
new file mode 100644
index 0000000..cefa1fe
--- /dev/null
+++ b/src/consul_interface_tests.erl
@@ -0,0 +1,88 @@
+% ============LICENSE_START=======================================================
+% org.onap.dcae
+% ================================================================================
+% Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+% ================================================================================
+% Licensed under the Apache License, Version 2.0 (the "License");
+% you may not use this file except in compliance with the License.
+% You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+% See the License for the specific language governing permissions and
+% limitations under the License.
+% ============LICENSE_END=========================================================
+%
+% ECOMP is a trademark and service mark of AT&T Intellectual Property.
+
+-module(consul_interface_tests).
+-include_lib("eunit/include/eunit.hrl").
+
+-import(consul_interface, [
+ consul_get_service/3,
+ consul_read_kv/3,
+ consul_get_configuration/3,
+ consul_get_preferences/3,
+ consul_bind_config/3
+ ]).
+
+consul_bind_config_test() ->
+ try meck:new(httpabs, [passthrough]) catch _:_ -> ok end,
+ try meck:new(util, [passthrough]) catch _:_ -> ok end,
+ FakeReturn = {[{<<"i am here">>, <<"my son">>}]},
+ meck:expect(util, resolve_cbs, fun(_XER, _ConsulURL) -> "http://666.666.666.666:10000" end), %dont try to test the consul part here
+ meck:expect(httpabs, get, fun(_XER, URL) -> case URL of
+ "http://666.666.666.666:10000/service_component/salvationnotfound" -> {404, ""};
+ "http://666.666.666.666:10000/service_component/salvation" -> {200, jiffy:encode(FakeReturn)}
+ end end),
+ ?assert(consul_bind_config("", "salvation", "") == {200, FakeReturn}),
+ ?assert(consul_bind_config("", "salvationnotfound", "") == {404, ""}),
+ meck:unload(httpabs),
+ meck:unload(util).
+
+consul_read_kv_test() ->
+ try meck:new(httpabs, [passthrough]) catch _:_ -> ok end,
+ Val = base64:encode("salvation"),
+ FakeReturn = jiffy:encode([{[{<<"Value">>, Val}]}]),
+ meck:expect(httpabs, get, fun(_XER, URL) -> case URL of
+ "http://666.666.666.666:666/v1/kv/salvationnotfound" -> {404, ""};
+ "http://666.666.666.666:666/v1/kv/salvation" -> {200, FakeReturn}
+ end end),
+ ?assert(consul_read_kv("", <<"salvation">>, "http://666.666.666.666:666") == {200, <<"salvation">>}),
+ ?assert(consul_read_kv("", <<"salvationnotfound">>, "http://666.666.666.666:666") == {404, ""}),
+ meck:unload(httpabs).
+
+consul_get_configuration_preferences_test() ->
+ try meck:new(httpabs, [passthrough]) catch _:_ -> ok end,
+ Val = base64:encode(jiffy:encode({[{<<"iam">>, <<"thebestestjson">>}]})),
+ FakeReturn = jiffy:encode([{[{<<"Value">>, Val}]}]),
+ meck:expect(httpabs, get, fun(_XER, URL) -> case URL of
+ "http://666.666.666.666:666/v1/kv/salvationnotfound" -> {404, ""};
+ "http://666.666.666.666:666/v1/kv/salvation" -> {200, FakeReturn};
+ "http://666.666.666.666:666/v1/kv/salvation:preferences" -> {200, FakeReturn};
+ "http://666.666.666.666:666/v1/kv/salvationnotfound:preferences" -> {404, ""}
+ end end),
+ ?assert(consul_get_configuration("", <<"salvation">>, "http://666.666.666.666:666") == {200, #{<<"iam">>=><<"thebestestjson">>}}),
+ ?assert(consul_get_configuration("", <<"salvationnotfound">>, "http://666.666.666.666:666") == {404, ""}),
+ ?assert(consul_get_preferences("", <<"salvation">>, "http://666.666.666.666:666") == {200, #{<<"iam">>=><<"thebestestjson">>}}),
+ ?assert(consul_get_preferences("", <<"salvationnotfound">>, "http://666.666.666.666:666") == {404, ""}),
+
+ meck:unload(httpabs).
+
+consul_get_service_test() ->
+ try meck:new(httpabs, [passthrough]) catch _:_ -> ok end,
+ FakeConfig = jiffy:encode({[{<<"your key">>, <<"sir">>}]}),
+ meck:expect(httpabs, get, fun(_XER, URL) -> case URL of
+ "http://666.666.666.666:666/v1/catalog/service/salvationnotfound" -> {404, ""};
+ "http://666.666.666.666:666/v1/catalog/service/salvation" -> {200, FakeConfig}
+ end end),
+ ?assert(consul_get_service("", <<"salvation">>, "http://666.666.666.666:666") == #{<<"your key">> => <<"sir">>}),
+ ?assertException(error, {badmatch,{404,[]}}, consul_get_service("", <<"salvationnotfound">>, "http://666.666.666.666:666")),
+ meck:unload(httpabs).
+
+
+
+
diff --git a/src/util_tests.erl b/src/util_tests.erl
index 1774fb5..8266e75 100644
--- a/src/util_tests.erl
+++ b/src/util_tests.erl
@@ -112,6 +112,3 @@ resolve_cbs_test() ->
?assert(resolve_cbs("", "") == "http://666.666.666.666:10000"),
meck:unload(consul_interface).
-
-
-
diff --git a/swagger/swagger.yaml b/swagger/swagger.yaml
index 736fc66..0e40d74 100644
--- a/swagger/swagger.yaml
+++ b/swagger/swagger.yaml
@@ -5,7 +5,7 @@ swagger: '2.0'
# This is your document metadata
info:
- version: "4.0.8"
+ version: "4.0.9"
title: CDAP Broker API
paths: