Skip to content

Commit

Permalink
Test with ANSI off to make tests easier to read
Browse files Browse the repository at this point in the history
  • Loading branch information
fhunleth committed Feb 4, 2023
1 parent 72cf342 commit 1ce12f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ config :nerves_time_zones, default_time_zone: "Asia/Tokyo"

if Mix.env() == :test do
config :nerves_motd, runtime_mod: NervesMOTD.MockRuntime
config :elixir, ansi_enabled: false
end
14 changes: 7 additions & 7 deletions test/nerves_motd_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ defmodule NervesMOTDTest do
|> Mox.expect(:applications, 1, default_applications_code())
|> Mox.expect(:firmware_valid?, 1, fn -> true end)

assert capture_motd() =~ ~r/Firmware : \e\[32mValid.*\e\[0m/
assert capture_motd() =~ ~r/Firmware : Valid \(A\)/
end

test "Firmware when invalid" do
NervesMOTD.MockRuntime
|> Mox.expect(:applications, 1, default_applications_code())
|> Mox.expect(:firmware_valid?, 1, fn -> false end)

assert capture_motd() =~ ~r/Firmware : \e\[31mNot validated.*\e\[0m/
assert capture_motd() =~ ~r/Firmware : Not validated \(A\)/
end

test "Applications when all apps started" do
Expand All @@ -141,7 +141,7 @@ defmodule NervesMOTDTest do
NervesMOTD.MockRuntime
|> Mox.expect(:applications, 1, fn -> apps end)

assert capture_motd() =~ ~r/Applications : \e\[33m\d* started \(a, b not started\)\e\[0m/
assert capture_motd() =~ ~r/Applications : \d* started \(a, b not started\)/
end

test "Hostname" do
Expand All @@ -165,7 +165,7 @@ defmodule NervesMOTDTest do
{:ok, %{size_mb: 316, used_mb: 316, used_percent: 100}}
end)

assert capture_motd() =~ ~r/Memory usage : \e\[31m316 MB \(100%\).*\e\[0m/
assert capture_motd() =~ ~r/Memory usage : 316 MB \(100%\)/
end

test "Load average" do
Expand Down Expand Up @@ -197,7 +197,7 @@ defmodule NervesMOTDTest do
{:ok, %{size_mb: 14_300, used_mb: 12_900, used_percent: 90}}
end)

assert capture_motd() =~ ~r/Part usage : \e\[31m12900 MB \(90%\)\e\[0m/
assert capture_motd() =~ ~r/Part usage : 12900 MB \(90%\)/
end

test "Application partition usage not available" do
Expand All @@ -207,7 +207,7 @@ defmodule NervesMOTDTest do
:error
end)

assert capture_motd() =~ ~r/Part usage : \e\[31mnot available\e\[0m/
assert capture_motd() =~ ~r/Part usage : not available/
end

test "No application partition" do
Expand All @@ -218,7 +218,7 @@ defmodule NervesMOTDTest do
Nerves.Runtime.KV.put_active("nerves_fw_application_part0_devpath", "")
result = capture_motd()
Nerves.Runtime.KV.put_active("nerves_fw_application_part0_devpath", old_devpath)
assert result =~ ~r/Part usage : \e\[31mnot available\e\[0m/
assert result =~ ~r/Part usage : not available/
end

test "IP addresses" do
Expand Down

0 comments on commit 1ce12f0

Please sign in to comment.