This repository has been archived by the owner on Aug 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Trendyol/feature/cli-tests
Add integration tests for set and run commands
- Loading branch information
Showing
3 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
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,101 @@ | ||
package cmd | ||
|
||
import ( | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
// There is not any mocking. Do not run tests when use the this tool. | ||
|
||
func TestRunCommand_WhenRunsWithEmptyArgs_ReturnsOutput(t *testing.T) { | ||
runCmd := exec.Command("go", "run", "../main.go", "run", | ||
"--repository", "", | ||
"--startDate", "", | ||
"--endDate", "") | ||
|
||
out, err := runCmd.Output() | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
want := "date will be like -s YYYY-MM-DD" | ||
got := string(out) | ||
if !strings.Contains(got, want) { | ||
t.Errorf("Unexpected data.\nGot: %s\nExpected: %s", got, want) | ||
} | ||
} | ||
|
||
func TestRunCommand_WhenRunsWithCorrectCloneAddressButWrongArgs_ReturnsOutput(t *testing.T) { | ||
addCmd := exec.Command("go", "run", "../main.go", "add", | ||
"--cloneAddress", "https://github.com/Trendyol/medusa.git", | ||
"--team", "trendyol-team", | ||
"--releaseTagPattern", "release-v", | ||
"--fixCommitPatterns", "fix", "-f", "hotfix") | ||
|
||
_, err := addCmd.Output() | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
runCmd := exec.Command("go", "run", "../main.go", "run", | ||
"--repository", "medusa", | ||
"--startDate", "", | ||
"--endDate", "") | ||
|
||
out, err := runCmd.Output() | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
removeCmd := exec.Command("go", "run", "../main.go", "remove", | ||
"--repository", "medusa") | ||
|
||
_, err = removeCmd.Output() | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
want := "date will be like -s YYYY-MM-DD" | ||
got := string(out) | ||
if !strings.Contains(got, want) { | ||
t.Errorf("Unexpected data.\nGot: %s\nExpected: %s", got, want) | ||
} | ||
} | ||
|
||
func TestRunCommand_WhenRunsWithCorrectArgs_ReturnsOutput(t *testing.T) { | ||
addCmd := exec.Command("go", "run", "../main.go", "add", | ||
"--cloneAddress", "https://github.com/Trendyol/android-ui-components.git", | ||
"--team", "trendyol-team", | ||
"--releaseTagPattern", "toolbar-", | ||
"--fixCommitPatterns", "fix", "-f", "hotfix") | ||
|
||
_, err := addCmd.Output() | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
runCmd := exec.Command("go", "run", "../main.go", "run", | ||
"--repository", "android-ui-components", | ||
"--startDate", "2019-01-01", | ||
"--endDate", "2020-12-31") | ||
|
||
out, err := runCmd.Output() | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
removeCmd := exec.Command("go", "run", "../main.go", "remove", | ||
"--repository", "medusa") | ||
|
||
_, err = removeCmd.Output() | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
want := "metrics file generated" | ||
got := string(out) | ||
if !strings.Contains(got, want) { | ||
t.Errorf("Unexpected data.\nGot: %s\nExpected: %s", got, want) | ||
} | ||
} |
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,41 @@ | ||
package cmd | ||
|
||
import ( | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
// There is not any mocking. Do not run tests when use the this tool. | ||
|
||
func TestSetCommand_WhenRunsWithEmptyArgs_ReturnsOutput(t *testing.T) { | ||
cmd := exec.Command("go", "run", "../main.go", "set", | ||
"--output", "") | ||
|
||
out, err := cmd.Output() | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
want := "output parameter error please check and re run" | ||
got := string(out) | ||
if !strings.Contains(got, want) { | ||
t.Errorf("Unexpected data.\nGot: %s\nExpected: %s", got, want) | ||
} | ||
} | ||
|
||
func TestSetCommand_WhenRunsWithCorrectArgs_ReturnsOutput(t *testing.T) { | ||
cmd := exec.Command("go", "run", "../main.go", "set", | ||
"--output", "/Users/furkan.bozdag/Desktop") | ||
|
||
out, err := cmd.Output() | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
|
||
want := "" | ||
got := string(out) | ||
if !strings.Contains(got, want) { | ||
t.Errorf("Unexpected data.\nGot: %s\nExpected: %s", got, want) | ||
} | ||
} |