-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check git configuration before exec world create
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"fmt" | ||
"net" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
@@ -303,3 +304,61 @@ func TestEVMStart(t *testing.T) { | |
// Check and wait until evm is down | ||
assert.Assert(t, evmIsDown(t), "EVM is not successfully shutdown") | ||
} | ||
|
||
func TestCheckGitConfig(t *testing.T) { | ||
t.Run("Real Scenario", func(t *testing.T) { | ||
// Test when both user name and email with real values | ||
err := checkGitConfig() | ||
if err != nil { | ||
t.Fatalf("Expected no error, got %v", err) | ||
} | ||
}) | ||
|
||
t.Run("Error Username", func(t *testing.T) { | ||
// Test when user name is not set | ||
execCommand = fakeExecCommandGetGitUsername | ||
err := checkGitConfig() | ||
assert.Error(t, err, "retrieving Git user name, please set it using `git config --global user.name 'Your Name'`") | ||
}) | ||
|
||
t.Run("Error Email", func(t *testing.T) { | ||
// Test when user name is not set | ||
execCommand = fakeExecCommandGetGitEmail | ||
err := checkGitConfig() | ||
assert.Error(t, err, "retrieving Git user email, please set it using `git config --global user.email 'Your Email'`") | ||
}) | ||
} | ||
|
||
// fakeExecCommand is a fake version of exec.Command that simulates git config output | ||
func fakeExecCommandGetGitUsername(command string, args ...string) *exec.Cmd { | ||
commandStr := fmt.Sprintf("%s %s", command, strings.Join(args, " ")) | ||
|
||
var cmd *exec.Cmd | ||
switch commandStr { | ||
case "git config --get user.name": | ||
cmd = exec.Command("echo") | ||
case "git config --get user.email": | ||
cmd = exec.Command("echo", "[email protected]") | ||
default: | ||
cmd = exec.Command("echo") | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
// fakeExecCommand is a fake version of exec.Command that simulates git config output | ||
func fakeExecCommandGetGitEmail(command string, args ...string) *exec.Cmd { | ||
commandStr := fmt.Sprintf("%s %s", command, strings.Join(args, " ")) | ||
|
||
var cmd *exec.Cmd | ||
switch commandStr { | ||
case "git config --get user.name": | ||
cmd = exec.Command("echo", "Test User") | ||
case "git config --get user.email": | ||
cmd = exec.Command("echo") | ||
default: | ||
cmd = exec.Command("echo") | ||
} | ||
|
||
return cmd | ||
} |