-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Introduce Storage to act as Git Config a façade
Move Actions.add/1 to Storage abstraction
- Loading branch information
Amadeu 🦄 Lindo 🌈
committed
Sep 23, 2020
1 parent
708511f
commit f84a7dc
Showing
5 changed files
with
63 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
defmodule GitPair.Storage do | ||
@git_config "config" | ||
@key "pair" | ||
@success_exit_status 0 | ||
|
||
def add([identifier, email]) do | ||
run(["--add", "#{@key}.#{identifier}.identifier", identifier]) | ||
run(["--add", "#{@key}.#{identifier}.email", email]) | ||
|
||
{:ok, nil} | ||
end | ||
|
||
def run(command) do | ||
runner().cmd("git", [@git_config | command]) | ||
end | ||
|
||
def runner() do | ||
Application.get_env(:git_pair, :command_runner, System) | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ defmodule GitPair.ActionsTest do | |
|
||
setup :verify_on_exit! | ||
|
||
test ".add calls git config add command" do | ||
test ".add calls git config add command passing username" do | ||
expect(SystemMock, :cmd, fn _cmd, _options -> | ||
{"", 0} | ||
end) | ||
|
@@ -19,6 +19,17 @@ defmodule GitPair.ActionsTest do | |
assert message == "User fake-user added" | ||
end | ||
|
||
test ".add calls git config add command passing identifier and email" do | ||
expect(SystemMock, :cmd, fn _cmd, _options -> | ||
{"", 0} | ||
end) | ||
|
||
{result, message} = Actions.add(["fake-user", "[email protected]"]) | ||
|
||
assert result == :ok | ||
assert message == "User fake-user ([email protected]) added" | ||
end | ||
|
||
test ".rm calls git config unset command" do | ||
expect(SystemMock, :cmd, fn _cmd, _options -> | ||
{"", 0} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
defmodule GitPair.StorageTest do | ||
use ExUnit.Case, async: true | ||
|
||
import Mox | ||
|
||
alias GitPair.Storage | ||
alias GitPair.SystemMock | ||
|
||
setup :verify_on_exit! | ||
|
||
describe "add/2" do | ||
test "stores user with identifier and email" do | ||
command_prefix = ["config", "--add"] | ||
expect(SystemMock, :cmd, fn _cmd, options -> | ||
assert options == command_prefix ++ ["pair.fake-user.identifier", "fake-user"] | ||
{"", 0} | ||
end) | ||
|
||
expect(SystemMock, :cmd, fn _cmd, options -> | ||
assert options == command_prefix ++ ["pair.fake-user.email", "[email protected]"] | ||
{"", 0} | ||
end) | ||
|
||
{result, message} = Storage.add(["fake-user", "[email protected]"]) | ||
|
||
assert result == :ok | ||
assert message == nil | ||
end | ||
end | ||
end |