diff options
author | kballou <kballou@devnulllabs.io> | 2016-12-27 10:02:42 -0700 |
---|---|---|
committer | kballou <kballou@devnulllabs.io> | 2016-12-27 10:40:28 -0700 |
commit | 6e36a9c3fb482cc993a3fa6511c51cc19b59d5a2 (patch) | |
tree | 2b70dbdb2ca4ff29927b61a2c0b845945de3b848 /test/exdatadog_test.exs | |
parent | b79f51aac09b6a612725e1fae5af283c4025aa34 (diff) | |
download | exdatadog-6e36a9c3fb482cc993a3fa6511c51cc19b59d5a2.tar.gz exdatadog-6e36a9c3fb482cc993a3fa6511c51cc19b59d5a2.tar.xz |
Add base datadog client
This adds a base HTTPoison Datadog Client library.
Diffstat (limited to 'test/exdatadog_test.exs')
-rw-r--r-- | test/exdatadog_test.exs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/test/exdatadog_test.exs b/test/exdatadog_test.exs new file mode 100644 index 0000000..5e752ab --- /dev/null +++ b/test/exdatadog_test.exs @@ -0,0 +1,64 @@ +defmodule ExdatadogTest do + @moduledoc """ + Provides tests for the Exdatadog module + """ + use ExUnit.Case + + alias HTTPoison.Response + import Exdatadog + + doctest Exdatadog + + setup_all do + :meck.new(Poison, [:no_link]) + + on_exit fn -> + :meck.unload(Poison) + end + end + + test "auth_params using api_key" do + assert auth_params(%{api_key: "1234"}) == [api_key: "1234"] + end + + test "auth_params using api_key and app_key" do + expected = [application_key: "abcd", api_key: "1234"] + assert auth_params(%{api_key: "1234", app_key: "abcd"}) == expected + end + + test "auth_params with no auth" do + assert auth_params(%{}) == [] + assert auth_params(nil) == [] + end + + test "process_response with 200" do + assert process_response(%Response{status_code: 200, + headers: %{}, + body: "json"}) == {200, "json"} + assert :meck.validate(Poison) + end + + test "process_response with non-200" do + assert process_response(%Response{status_code: 404, + headers: %{}, + body: "json"}) == {404, "json"} + + assert :meck.validate(Poison) + end + + test "process_resposne_body with nil body" do + assert process_response_body("") == nil + end + + test "process_response_body with content" do + :meck.expect(Poison, :decode!, 1, :decoded_json) + assert process_response_body("json") == :decoded_json + end + + test "process_response with empty body" do + assert process_response(%Response{status_code: 202, + headers: %{}, + body: nil}) == {202, nil} + end + +end |