aboutsummaryrefslogtreecommitdiff
path: root/test/http_test.exs
blob: 61847d4b6a5e2954c6ff6f300ba754aa48786114 (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
defmodule ExPing.HTTP.Test do
  use ExUnit.Case

  describe "head requests" do
    test "can get ok response" do
      for code <- [200, 405] do
        {:ok, _} = ExPing.HTTP.head(URI.parse("localhost/#{code}"))
      end
    end

    test "can get error response" do
      {:error, _} = ExPing.HTTP.head(URI.parse("localhost/500"))
    end

    test "can get timeout response" do
      {:error, :timeout} = ExPing.HTTP.head(URI.parse("localhost/timeout"))
    end
  end

  describe "get requests" do
    test "can get ok response" do
      for code <- [200, 400, 404] do
        {:ok, _} = ExPing.HTTP.get(URI.parse("localhost/#{code}"))
      end
    end

    test "can get error response" do
      {:error, _} = ExPing.HTTP.get(URI.parse("localhost/500"))
    end

    test "can get timeout response" do
      {:error, :timeout} = ExPing.HTTP.get(URI.parse("localhost/timeout"))
    end
  end

end