Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elixir version upgrades #56

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Divo.MixProject do
def project do
[
app: :divo,
version: "2.0.0",
version: "2.0.1",
elixir: "~> 1.14.4",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand All @@ -28,7 +28,7 @@ defmodule Divo.MixProject do
[
{:jason, "~> 1.4"},
{:patiently, "~> 0.2"},
{:mock, "~> 0.3", only: :test},
{:placebo_test, "~> 3.0", only: :test},
{:temporary_env, "~> 2.0", only: :test},
{:credo, "~> 1.7", only: :dev, runtime: false},
{:dialyxir, "~> 1.3", only: :dev, runtime: false},
Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"},
"patiently": {:hex, :patiently, "0.2.0", "67eb139591e10c4b363ae0198e832552f191c58894731efd3bf124ec4722267a", [:mix], [], "hexpm", "c08cc5edc27def565647a9b55a0bea8025a5f81a4472e57692f28f2292c44c94"},
"placebo": {:hex, :placebo, "2.0.0", "c0e773dec77e941bcbcc14d10b759f2d66775aff9b75051f3e41939b64300e81", [:mix], [{:meck, "~> 0.9", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm", "e0872cec8848d7e59ba96396f45ee1ad34662c689c86ba6190694d38b4289844"},
"placebo_test": {:hex, :placebo_test, "3.0.0", "4624c0e4019fcf378b4f9f8651563d7eaa2fba12b4f870dc5659087d16716c88", [:mix], [{:meck, "~> 0.9.2", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm", "1d22b2a2fa347201dc82e654de5a694f32c4751ac4189c23010f373728320971"},
"temporary_env": {:hex, :temporary_env, "2.0.1", "d4b5e031837e5619485e1f23af7cba7e897b8fd546eaaa8b10c812d642ec4546", [:mix], [], "hexpm", "f9420044742b5f0479a7f8243e86b048b6a2d4878bce026a3615065b11199c27"},
}
40 changes: 16 additions & 24 deletions test/compose_test.exs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
defmodule Divo.ComposeTest do
use ExUnit.Case, async: false
use Placebo

import Mock

setup_with_mocks([
{System, [:passthrough], [cmd: fn(_, _) -> {"", 0} end]},
{System, [], [cmd: fn(_, _, _) -> {"", 0} end]},
{System, [], [get_env: fn(_) -> "/tmp" end]}
]) do
{:ok, foo: "bar"}
setup do
allow(System.cmd(any(), any()), meck_options: [:passthrough])
allow(System.get_env(any()), return: "/tmp")
allow(System.cmd(any(), any(), any()), return: {"", 0})
:ok
end

test "docker run command called with expected arguments" do

Check failure on line 12 in test/compose_test.exs

View workflow job for this annotation

GitHub Actions / Verify Application

test docker run command called with expected arguments (Divo.ComposeTest)
Divo.Compose.run()

assert_called(
Expand All @@ -19,37 +17,31 @@
)
end

test "docker run command with bad exit is raised as an error" do

Check failure on line 20 in test/compose_test.exs

View workflow job for this annotation

GitHub Actions / Verify Application

test docker run command with bad exit is raised as an error (Divo.ComposeTest)
Divo.Compose.run()

error_message = "Failed to get authorization token: NoCredentialProviders: no valid providers in chain. Deprecated."

with_mocks(
[
{Divo.Validate, [], [validate: fn(_) -> :ok end]},
{System, [], [cmd: fn(_, _, _) -> {error_message, 1} end]},
{System, [], [get_env: fn(_) -> "/tmp" end]}
]
) do
assert_raise RuntimeError, "Docker Compose exited with code: 1. " <> error_message, fn ->
Divo.Compose.run()
end
allow(Divo.Validate.validate(any()), return: :ok)

allow(System.cmd(any(), any(), any()),
return: {error_message, 1}
)

assert_raise RuntimeError, "Docker Compose exited with code: 1. " <> error_message, fn ->
Divo.Compose.run()
end
end

test "docker stop command called with expected arguments" do

Check failure on line 36 in test/compose_test.exs

View workflow job for this annotation

GitHub Actions / Verify Application

test docker stop command called with expected arguments (Divo.ComposeTest)
:ok = Divo.Compose.stop()

assert_called(
System.cmd("docker-compose", ["--file", "/tmp/divo.compose", "stop"], stderr_to_stdout: true)
)
assert_called(System.cmd("docker-compose", ["--file", "/tmp/divo.compose", "stop"], stderr_to_stdout: true))
end

test "docker stop and rm commands called with expected arguments on kill" do

Check failure on line 42 in test/compose_test.exs

View workflow job for this annotation

GitHub Actions / Verify Application

test docker stop and rm commands called with expected arguments on kill (Divo.ComposeTest)
:ok = Divo.Compose.kill()

assert_called(
System.cmd("docker-compose", ["--file", "/tmp/divo.compose", "down"], stderr_to_stdout: true)
)
assert_called(System.cmd("docker-compose", ["--file", "/tmp/divo.compose", "down"], stderr_to_stdout: true))
end
end
56 changes: 28 additions & 28 deletions test/file_test.exs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
defmodule Divo.FileTest do
use ExUnit.Case

import Mock
use Placebo

require TemporaryEnv

test "correctly determines the filename" do

Check failure on line 7 in test/file_test.exs

View workflow job for this annotation

GitHub Actions / Verify Application

test correctly determines the filename (Divo.FileTest)
with_mock(System, [], [get_env: fn ("TMPDIR") -> "/var/tmp/foo" end]) do
assert Divo.File.file_name() == "/var/tmp/foo/divo.compose"
end
allow(System.get_env("TMPDIR"), return: "/var/tmp/foo")

assert Divo.File.file_name() == "/var/tmp/foo/divo.compose"
end

test "correctly defaults the filename" do

Check failure on line 13 in test/file_test.exs

View workflow job for this annotation

GitHub Actions / Verify Application

test correctly defaults the filename (Divo.FileTest)
with_mock(System, [], [get_env: fn ("TMPDIR") -> nil end]) do
assert Divo.File.file_name() == "/tmp/divo.compose"
end
allow(System.get_env("TMPDIR"), return: nil)

assert Divo.File.file_name() == "/tmp/divo.compose"
end

test "uses existing compose file" do

Check failure on line 19 in test/file_test.exs

View workflow job for this annotation

GitHub Actions / Verify Application

test uses existing compose file (Divo.FileTest)
TemporaryEnv.put :divo, :divo, "test/docker-compose.yaml" do
file = Divo.Helper.fetch_config()

Expand All @@ -25,33 +24,35 @@
end
end

describe "generate" do
setup_with_mocks([
{System, [], [get_env: fn ("TMPDIR") -> "/var/tmp/foo" end]},
{File, [], [write!: fn (_, _) -> :ok end]},
{DivoFoobar, [:non_strict], [gen_stack: fn(_) -> %{} end]},
{DivoBarbaz, [:non_strict], [gen_stack: fn(_) -> %{} end]}
]) do
{:ok, foo: "bar"}
end
test "generates compose file from app config" do

Check failure on line 27 in test/file_test.exs

View workflow job for this annotation

GitHub Actions / Verify Application

test generates compose file from app config (Divo.FileTest)
allow(File.write!(any(), any()), return: :ok)
allow(System.get_env("TMPDIR"), return: "/var/tmp/foo")

test "generates compose file from app config" do
config = Divo.Helper.fetch_config()
config = Divo.Helper.fetch_config()

assert Divo.File.ensure_file(config) == "/var/tmp/foo/divo.compose"
end
assert Divo.File.ensure_file(config) == "/var/tmp/foo/divo.compose"
end

test "generates compose file from a behaviour implementation of a single service" do
services = [{DivoFoobar, [db_password: "we-are-divo", db_name: "foobar-db", something: "else"]}]
test "generates compose file from a behaviour implementation of a single service" do

Check failure on line 36 in test/file_test.exs

View workflow job for this annotation

GitHub Actions / Verify Application

test generates compose file from a behaviour implementation of a single service (Divo.FileTest)
allow(File.write!(any(), any()), return: :ok)
allow(System.get_env("TMPDIR"), return: "/var/tmp/bar")
allow(DivoFoobar.gen_stack(any()), return: %{}, meck_options: [:non_strict])

TemporaryEnv.put :divo, :divo, services do
config = Divo.Helper.fetch_config()
services = [{DivoFoobar, [db_password: "we-are-divo", db_name: "foobar-db", something: "else"]}]

TemporaryEnv.put :divo, :divo, services do
config = Divo.Helper.fetch_config()

assert Divo.File.ensure_file(config) == "/var/tmp/foo/divo.compose"
end
assert Divo.File.ensure_file(config) == "/var/tmp/bar/divo.compose"
end
end

test "concatenates compose file from multiple implementations of the behaviour" do

Check failure on line 50 in test/file_test.exs

View workflow job for this annotation

GitHub Actions / Verify Application

test concatenates compose file from multiple implementations of the behaviour (Divo.FileTest)
allow(File.write!(any(), any()), return: :ok)
allow(System.get_env("TMPDIR"), return: "/var/tmp/foo")
allow(DivoFoobar.gen_stack(any()), return: %{}, meck_options: [:non_strict])
allow(DivoBarbaz.gen_stack(any()), return: %{}, meck_options: [:non_strict])

services = [
{DivoFoobar, [db_password: "we-are-divo", db_name: "foobar-db", something: "else"]},
DivoBarbaz
Expand All @@ -63,5 +64,4 @@
assert Divo.File.ensure_file(config) == "/var/tmp/foo/divo.compose"
end
end
end
end
Loading