Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
Add tests for StorageQuery.get_main_storage[_id]/1
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomassaro committed Oct 15, 2017
1 parent a73d093 commit f352669
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/software/query/storage.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,26 @@ defmodule Helix.Software.Query.Storage do
defdelegate get_storage_drives(storage),
to: StorageDriveInternal

# TODO Test
@spec get_main_storage(Server.idt) ::
Storage.t
@doc """
Returns the "main" storage of a server, which, for the time being, is the only
storage a server may have.
"""
def get_main_storage(server) do
server
|> get_main_storage_id()
|> fetch()
end

@spec get_main_storage_id(Server.idt) ::
Storage.id
def get_main_storage(server = %Server{}),
do: get_main_storage(server.server_id)
def get_main_storage(server_id = %Server.ID{}) do
@doc """
Identical to `get_main_storage`, but only returns the server's storage id.
"""
def get_main_storage_id(server = %Server{}),
do: get_main_storage_id(server.server_id)
def get_main_storage_id(server_id = %Server.ID{}) do
server_id
|> CacheQuery.from_server_get_storages!()
|> List.first()
Expand Down
24 changes: 24 additions & 0 deletions test/software/query/storage_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ defmodule Helix.Software.Query.StorageTest do

alias Helix.Software.Query.Storage, as: StorageQuery

alias Helix.Test.Server.Setup, as: ServerSetup
alias Helix.Test.Software.Helper, as: SoftwareHelper
alias Helix.Test.Software.Setup, as: SoftwareSetup

describe "storage_contents/1" do
Expand Down Expand Up @@ -42,4 +44,26 @@ defmodule Helix.Software.Query.StorageTest do
refute Enum.empty?(StorageQuery.files_on_storage(storage))
end
end

describe "get_main_storage_id/1" do
test "returns the 'main' storage id of the server" do
{server, _} = ServerSetup.server()

storage = SoftwareHelper.get_storage(server)
main_storage_id = StorageQuery.get_main_storage_id(server)

assert storage.storage_id == main_storage_id
end
end

describe "get_main_storage/1" do
test "returns the 'main' storage of the server" do
{server, _} = ServerSetup.server()

storage = SoftwareHelper.get_storage(server)
main_storage = StorageQuery.get_main_storage(server)

assert storage == main_storage
end
end
end

0 comments on commit f352669

Please sign in to comment.