Refactor tests

This commit is contained in:
Mike Cifelli 2024-04-01 10:48:49 -04:00
parent c1c46707ba
commit d278cfa353
Signed by: mike
GPG Key ID: 6B08C6BE47D08E4C
5 changed files with 156 additions and 146 deletions

View File

@ -8,6 +8,7 @@ defmodule Chronoscope.NTS.CertificateTest do
setup :verify_on_exit!
describe "Chronoscope.NTS.Certificate.expiration_date()" do
test "parses the expiration date of a certificate" do
{:ok, expiration, _} =
:secp256r1
@ -19,7 +20,9 @@ defmodule Chronoscope.NTS.CertificateTest do
assert DateTime.diff(expiration, DateTime.utc_now(), :day) == 12
end
end
describe "Chronoscope.NTS.Certificate.cert_time_to_iso8601()" do
test "converts certificate datetime to iso8601" do
DateTimeMock
|> expect(:utc_now, fn -> ~U[2024-03-31 01:23:45Z] end)
@ -40,4 +43,5 @@ defmodule Chronoscope.NTS.CertificateTest do
assert cert_time_to_iso8601("010326110000Z") == "3001-03-26T11:00:00Z"
end
end
end

View File

@ -3,8 +3,10 @@ defmodule Chronoscope.NTS.KeyEstablishmentRequestTest do
import Chronoscope.NTS.KeyEstablishmentRequest
describe "Chronoscope.NTS.KeyEstablishmentRequest.create()" do
test "builds request" do
assert create() ==
<<0x80, 0x01, 0x00, 0x02, 0x00, 0x00, 0x80, 0x04, 0x00, 0x04, 0x00, 0x1E, 0x00, 0x0F, 0x80, 0x00, 0x00, 0x00>>
end
end
end

View File

@ -3,6 +3,7 @@ defmodule Chronoscope.NTS.KeyEstablishmentResponseTest do
import Chronoscope.NTS.KeyEstablishmentResponse
describe "Chronoscope.NTS.KeyEstablishmentResponse.parse()" do
test "handles empty response" do
assert parse([]) == {:ok, %{}}
end
@ -141,4 +142,5 @@ defmodule Chronoscope.NTS.KeyEstablishmentResponseTest do
next_protocols: ["NTPv4"]
}}
end
end
end

View File

@ -1,7 +1,8 @@
defmodule ChronoscopeWeb.API.V1.HealthControllerTest do
use ChronoscopeWeb.ConnCase, async: true
test "indicates health", %{conn: conn} do
describe "GET /api/v1/health" do
test "is healthy", %{conn: conn} do
response =
conn
|> get(~p"/api/v1/health")
@ -9,4 +10,5 @@ defmodule ChronoscopeWeb.API.V1.HealthControllerTest do
assert %{"healthy" => true} == response
end
end
end

View File

@ -5,7 +5,7 @@ defmodule ChronoscopeWeb.API.V1.NTS.KeyEstablishmentControllerTest do
setup :verify_on_exit!
describe "/api/v1/nts/key-establishment" do
describe "GET /api/v1/nts/key-establishment" do
test "requires a host name", %{conn: conn} do
response =
conn