Skip to content

Commit

Permalink
Fix default timezone test so that it can't be tricked
Browse files Browse the repository at this point in the history
The default timezone test would inadvertently use system-supplied
timezone files which would make it pass even though it should have
failed before the fix in the previous commit.
  • Loading branch information
fhunleth committed Apr 23, 2021
1 parent 66aaa7e commit a5db568
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions test/nerves_time_zones_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,23 @@ defmodule NervesTimeZonesTest do
test "default can be changed" do
# Clear out the time zone file
NervesTimeZones.reset_time_zone()
capture_log(fn -> Application.stop(:nerves_time_zones) end)

# This should be a fresh start
capture_log(fn ->
Application.stop(:nerves_time_zones)
Application.stop(:zoneinfo)
end)

# This should simulate a fresh start and not get tricked by
# zoneinfo finding system time zone files.
Application.put_env(:zoneinfo, :tzpath, "/some/place/without/zoneinfo")
Calendar.put_time_zone_database(Calendar.UTCOnlyTimeZoneDatabase)

# Set the default and check that it is used
Application.put_env(:nerves_time_zones, :default_time_zone, "America/Chicago")
Application.start(:nerves_time_zones)
Application.ensure_all_started(:nerves_time_zones)
assert NervesTimeZones.get_time_zone() == "America/Chicago"

# Restore the default
# Restore the default for the next tests
:application.unset_env(:nerves_time_zones, :default_time_zone)
capture_log(fn -> Application.stop(:nerves_time_zones) end)
Application.start(:nerves_time_zones)
Expand Down

0 comments on commit a5db568

Please sign in to comment.