aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/exdatadog/client_test.exs39
-rw-r--r--test/exdatadog/config_test.exs30
-rw-r--r--test/exdatadog_test.exs64
-rw-r--r--test/test_helper.exs1
4 files changed, 134 insertions, 0 deletions
diff --git a/test/exdatadog/client_test.exs b/test/exdatadog/client_test.exs
new file mode 100644
index 0000000..dc63c1b
--- /dev/null
+++ b/test/exdatadog/client_test.exs
@@ -0,0 +1,39 @@
+defmodule Exdatadog.Client.Test do
+ @moduledoc """
+ Provides Tests for the Exdatadog.Client module
+ """
+ use ExUnit.Case, async: false
+
+ @endpoint "https://app.datadoghq.com/"
+
+ alias Exdatadog.Client
+
+ test "can create new client" do
+ expected = %Client{endpoint: @endpoint, auth: %{api_key: "1234",
+ app_key: "abcd"}}
+ assert Client.new() == expected
+ end
+
+ test "can create new client with api auth" do
+ actual = Client.new(%{api_key: "1234"})
+ assert actual == %Client{endpoint: @endpoint, auth: %{api_key: "1234"}}
+ end
+
+ test "can create new client with api and app auth" do
+ actual = Client.new(%{api_key: "1234", app_key: "abcd"})
+ assert actual == %Client{endpoint: @endpoint, auth: %{api_key: "1234",
+ app_key: "abcd"}}
+ end
+
+ test "can create new client with auth and custom endpoint" do
+ actual = Client.new(%{api_key: "1234"}, "https://test.datadoghq.com/")
+ assert actual == %Client{endpoint: "https://test.datadoghq.com/",
+ auth: %{api_key: "1234"}}
+ end
+
+ test "trailing / appended to endpoint without" do
+ actual = Client.new(nil, "https://test.datadoghq.com")
+ assert actual == %Client{endpoint: "https://test.datadoghq.com/", auth: nil}
+ end
+
+end
diff --git a/test/exdatadog/config_test.exs b/test/exdatadog/config_test.exs
new file mode 100644
index 0000000..2be0c38
--- /dev/null
+++ b/test/exdatadog/config_test.exs
@@ -0,0 +1,30 @@
+defmodule Exdatadog.Config.Test do
+ @moduledoc """
+ Provides tests for Exdatadog.Config
+ """
+ use ExUnit.Case
+
+ import Exdatadog.Config
+
+ setup_all do
+ System.put_env("TEST_VAR", "BAR")
+ Application.put_env(:test_app, :test_key, {:system, "TEST_VAR"})
+ Application.put_env(:test_app, :test_foo, "FOO")
+
+ on_exit fn ->
+ System.delete_env("TEST_VAR")
+ Application.delete_env(:test_app, :test_key)
+ Application.delete_env(:test_app, :test_foo)
+ end
+
+ end
+
+ test "can read variable from application settings" do
+ assert get_env_var(:test_app, :test_foo) == "FOO"
+ end
+
+ test "can read environment variables for settings" do
+ assert get_env_var(:test_app, :test_key) == "BAR"
+ end
+
+end
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
diff --git a/test/test_helper.exs b/test/test_helper.exs
new file mode 100644
index 0000000..869559e
--- /dev/null
+++ b/test/test_helper.exs
@@ -0,0 +1 @@
+ExUnit.start()