Skip to content

Commit

Permalink
Merge pull request #162 from hypriot/set-time
Browse files Browse the repository at this point in the history
set fake-hwclock
  • Loading branch information
StefanScherer authored Jan 6, 2020
2 parents f69b6aa + 1ce3d5a commit 0e4ca4c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
6 changes: 5 additions & 1 deletion flash
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,6 @@ mount_boot_disk "${disk}" "${boot}"
cp "${FILE}" "${boot}/"
fi


if [ -f "${boot}/device-init.yaml" ]; then
echo "Setting device-init"
if [ -n "${SD_HOSTNAME}" ]; then
Expand All @@ -704,6 +703,11 @@ if [ -f "${boot}/device-init.yaml" ]; then
fi
fi

# set fake-hwclock
if [ -f "${boot}/fake-hwclock.data" ]; then
TZ=UTC date '+%Y-%m-%d %H:%M:%S' > "${boot}/fake-hwclock.data"
fi

# cloud-init
if [ -f "${boot}/user-data" ]; then
if [ -n "${SD_HOSTNAME}" ]; then
Expand Down
34 changes: 34 additions & 0 deletions test/fake-hwclock.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
load test_helper
export OS=$(uname -s)

setup() {
if [ ! -f fake-hwclock.img ]; then
# download SD card image with cloud-init
curl -L -o download.img.zip https://github.com/hypriot/image-builder-rpi/releases/download/1.12.0-rc2/hypriotos-rpi-1.12.0-rc2.img.zip
unzip download.img.zip
# cut only 70 MByte to flash faster
dd if=hypriotos-rpi-1.12.0-rc2.img of=fake-hwclock.img bs=1048576 count=70
fi
stub_diskutil
}

teardown() {
umount_sd_boot /tmp/boot
rm -f $img
unstub_diskutil
}

@test "fake-hwclock: flash updates fake-hwclock.data" {
expected=$(TZ=UTC date '+%Y-%m-%d %H:%M')

run ./flash -f -d $img fake-hwclock.img
assert_success

assert_output_contains Finished.

mount_sd_boot $img /tmp/boot
run cat /tmp/boot/fake-hwclock.data
assert_output_contains "$expected"

assert [ -e "/tmp/boot/fake-hwclock.data" ]
}

0 comments on commit 0e4ca4c

Please sign in to comment.