Created
June 29, 2024 14:51
-
-
Save costa/8b97420f67dc29c7df762392b16feffe to your computer and use it in GitHub Desktop.
drv/icloud's formal specification (with RSpec, excerpt) -- a part of self server system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ...definitions... | |
describe "REST API" do | |
# ... | |
context "when authenticated, with a sample video" do | |
# ...setup... | |
describe 'PUT /media/YYYY/MM/DD/IMG_NNNN.MOV' do | |
it "downloads media (a video) if it doesn't exist" do | |
expect(File.exist? video_path).not_to be | |
rest_put({}, "media/#{@media_path}") | |
expect_in_time 30 do # NOTE the file just started to download | |
sleep 2 | |
# NOTE it's reasonable for a video file to be 1MB at least | |
expect(File.size video_path).to be > 2**10 | |
end | |
end | |
it "skips downloading media (a video) if it exists already" do | |
mtime = File.mtime(video_path) | |
rest_put({}, "media/#{@media_path}") | |
expect(File.mtime video_path).to eq mtime | |
end | |
end | |
describe 'GET /' do | |
# NOTE this depends in part on the service's "healthcheck" | |
# (which comprises regular requests to this endpoint) | |
it "should fetch all the videos' metadata, log new and deleted ones and return the list" do | |
expect(videos = rest_get).not_to be_empty # SEE above | |
expect( | |
new_video_path = | |
ask("Shoot a new (short) video, wait until it makes to iCloud; its media path (YYYY/MM/DD/IMG_NNNN.MOV)") | |
).to match MEDIA_PATH_RE | |
expect_in_time 90 do | |
expect(@msgs.pop).to include act: 'created', path: "media/#{new_video_path}", src: 'icloud' | |
end | |
expect(rest_get - videos).to include new_video_path | |
expect(ask "Now, remove that video from iCloud please [OK]").to be_empty | |
expect_in_time 180 do | |
expect(@msgs.pop).to include act: 'deleted', path: "media/#{new_video_path}", src: 'icloud' | |
end | |
expect(rest_get).not_to include new_video_path | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment