aboutsummaryrefslogtreecommitdiff
path: root/test/exdatadog/search_test.exs
blob: 979784f9dc547674649f6f82c7573740839e710d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
defmodule Exdatadog.Search.Test do
  @moduledoc """
  Tests Exdatadog.Search
  """
  use ExUnit.Case
  use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney

  @cassette_dir "test/fixture/vcr_cassettes/search"

  alias Exdatadog.Client
  import Exdatadog.Search

  doctest Exdatadog.Search

  @lint {Credo.Check.Design.AliasUsage, false}
  setup_all do
    ExVCR.Config.cassette_library_dir(@cassette_dir)
  end

  test "search with un-faceted query" do
    client = Client.new()
    expected = {
      200,
      %{"results" => %{"metrics" => ["test.metric"],
                       "hosts" => ["test.another.example.com",
                                   "test.example.com",
                                   "test.host",
                                   "test.metric.host",
                                   "test.tag.host"]}}
    }
    use_cassette "unfaceted" do
      assert search("test", client) == expected
    end
  end

  test "search with faceted query" do
    client = Client.new()
    expected = {
      200,
      %{"results" => %{"hosts" => ["test.another.example.com",
                                   "test.example.com",
                                   "test.host",
                                   "test.metric.host",
                                   "test.tag.host"]}}
    }
    use_cassette "faceted" do
      assert search("hosts:test", client) == expected
    end
  end

end