This repository has been archived by the owner on Mar 25, 2023. It is now read-only.
-
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.
add additional GitMock functions (add & commit) for #28
- Loading branch information
Showing
4 changed files
with
44 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,14 @@ defmodule Gitea.GitMock do | |
if String.contains?(url, "error") do | ||
{:error, %Git.Error{message: "git clone error (mock)"}} | ||
else | ||
{:ok, %Git.Repository{path: Gitea.Helpers.local_repo_path("test-org", "test-repo")}} | ||
# copy the contents of /test-repo into /tmp/test-repo when mock:true | ||
path = Gitea.Helpers.local_repo_path("test-org", "test-repo") | ||
submodule = Path.join([File.cwd!(), "test-repo"]) |> Path.expand() | ||
# Useful.empty_dir_contents(Envar.get("GIT_TEMP_DIR_PATH")) | ||
File.mkdir_p(path) | ||
File.cp_r(Path.join([submodule, ".git"]), path) | ||
File.copy(Path.join([submodule, "README.md"]), path) | ||
{:ok, %Git.Repository{path: path}} | ||
end | ||
end | ||
end | ||
|
@@ -52,4 +59,35 @@ defmodule Gitea.GitMock do | |
repo_name = Gitea.Helpers.get_repo_name_from_url(repo_path <> ".git") | ||
{:ok, "To ssh://gitea-server.fly.dev:10022/myorg/#{repo_name}.git\n"} | ||
end | ||
|
||
@doc """ | ||
`commit/2` (mock) simulate a commit and always returns {:ok, commit_info} | ||
## Examples | ||
iex> GitMock.commit("my-repo", ["any", "args"]) | ||
{:ok, "[master dc5b0d4] test msg\n Author: Al Ex <[email protected]>\n 1 file changed, 1 insertion(+)\n"} | ||
""" | ||
@spec commit(Git.Repository.t(), [any]) :: {:ok, any} | ||
def commit(repo, _args) do | ||
IO.inspect(repo) | ||
|
||
if String.contains?(repo.path, "error") do | ||
{:error, %Git.Error{message: "git clone error (mock)"}} | ||
else | ||
{:ok, | ||
"[master dc5b0d4] test msg\n Author: Al Ex <[email protected]>\n 1 file changed, 1 insertion(+)\n"} | ||
end | ||
end | ||
|
||
@doc """ | ||
`add/2` (mock) simulate a commit and always returns {:ok, any} | ||
## Examples | ||
iex> GitMock.add("my-repo", ["."]) | ||
{:ok, "any string"} | ||
""" | ||
@spec add(String.t(), [any]) :: {:ok, any} | ||
def add(_repo_path, _args) do | ||
{:ok, "totes always works"} | ||
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
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 |
---|---|---|
|
@@ -166,6 +166,7 @@ defmodule GiteaTest do | |
org_name = "myorg" | ||
repo_name = create_test_git_repo(org_name) | ||
file_name = "README.md" | ||
|
||
text = "text #{repo_name}" | ||
|
||
assert {:ok, _path} = Gitea.local_file_write_text(org_name, repo_name, file_name, text) | ||
|
@@ -201,6 +202,7 @@ defmodule GiteaTest do | |
email: "[email protected]" | ||
}) | ||
|
||
IO.inspect(msg) | ||
assert String.contains?(msg, "test msg") | ||
assert String.contains?(msg, "1 file changed, 1 insertion(+)") | ||
|
||
|