From 40554c474af310d407a53e546fd83fa852ad16a4 Mon Sep 17 00:00:00 2001 From: bozd4g Date: Sat, 6 Jun 2020 14:59:00 +0300 Subject: [PATCH 1/2] Add integration tests for run and set command. Edit test filename of repository command. --- ...=> repository_command_integration_test.go} | 0 cmd/run_command_integration_test.go | 101 ++++++++++++++++++ cmd/set_command_integration_test.go | 41 +++++++ 3 files changed, 142 insertions(+) rename cmd/{repository_command_test.go => repository_command_integration_test.go} (100%) create mode 100644 cmd/run_command_integration_test.go create mode 100644 cmd/set_command_integration_test.go diff --git a/cmd/repository_command_test.go b/cmd/repository_command_integration_test.go similarity index 100% rename from cmd/repository_command_test.go rename to cmd/repository_command_integration_test.go diff --git a/cmd/run_command_integration_test.go b/cmd/run_command_integration_test.go new file mode 100644 index 0000000..1aec2cf --- /dev/null +++ b/cmd/run_command_integration_test.go @@ -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/four-key.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", "four-key", + "--startDate", "", + "--endDate", "") + + out, err := runCmd.Output() + if err != nil { + t.Errorf(err.Error()) + } + + removeCmd := exec.Command("go", "run", "../main.go", "remove", + "--repository", "four-key") + + _, 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/four-key.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", "four-key", + "--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", "four-key") + + _, 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) + } +} \ No newline at end of file diff --git a/cmd/set_command_integration_test.go b/cmd/set_command_integration_test.go new file mode 100644 index 0000000..aacb771 --- /dev/null +++ b/cmd/set_command_integration_test.go @@ -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) + } +} \ No newline at end of file From 050f42b9f73b04a1bc51799d95141dfb070cbffb Mon Sep 17 00:00:00 2001 From: bozd4g Date: Sat, 6 Jun 2020 16:51:59 +0300 Subject: [PATCH 2/2] Edit repository address for tests --- cmd/run_command_integration_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/run_command_integration_test.go b/cmd/run_command_integration_test.go index 1aec2cf..a496212 100644 --- a/cmd/run_command_integration_test.go +++ b/cmd/run_command_integration_test.go @@ -28,7 +28,7 @@ func TestRunCommand_WhenRunsWithEmptyArgs_ReturnsOutput(t *testing.T) { func TestRunCommand_WhenRunsWithCorrectCloneAddressButWrongArgs_ReturnsOutput(t *testing.T) { addCmd := exec.Command("go", "run", "../main.go", "add", - "--cloneAddress", "https://github.com/Trendyol/four-key.git", + "--cloneAddress", "https://github.com/Trendyol/medusa.git", "--team", "trendyol-team", "--releaseTagPattern", "release-v", "--fixCommitPatterns", "fix", "-f", "hotfix") @@ -39,7 +39,7 @@ func TestRunCommand_WhenRunsWithCorrectCloneAddressButWrongArgs_ReturnsOutput(t } runCmd := exec.Command("go", "run", "../main.go", "run", - "--repository", "four-key", + "--repository", "medusa", "--startDate", "", "--endDate", "") @@ -49,7 +49,7 @@ func TestRunCommand_WhenRunsWithCorrectCloneAddressButWrongArgs_ReturnsOutput(t } removeCmd := exec.Command("go", "run", "../main.go", "remove", - "--repository", "four-key") + "--repository", "medusa") _, err = removeCmd.Output() if err != nil { @@ -65,9 +65,9 @@ func TestRunCommand_WhenRunsWithCorrectCloneAddressButWrongArgs_ReturnsOutput(t func TestRunCommand_WhenRunsWithCorrectArgs_ReturnsOutput(t *testing.T) { addCmd := exec.Command("go", "run", "../main.go", "add", - "--cloneAddress", "https://github.com/Trendyol/four-key.git", + "--cloneAddress", "https://github.com/Trendyol/android-ui-components.git", "--team", "trendyol-team", - "--releaseTagPattern", "release-v", + "--releaseTagPattern", "toolbar-", "--fixCommitPatterns", "fix", "-f", "hotfix") _, err := addCmd.Output() @@ -76,7 +76,7 @@ func TestRunCommand_WhenRunsWithCorrectArgs_ReturnsOutput(t *testing.T) { } runCmd := exec.Command("go", "run", "../main.go", "run", - "--repository", "four-key", + "--repository", "android-ui-components", "--startDate", "2019-01-01", "--endDate", "2020-12-31") @@ -86,7 +86,7 @@ func TestRunCommand_WhenRunsWithCorrectArgs_ReturnsOutput(t *testing.T) { } removeCmd := exec.Command("go", "run", "../main.go", "remove", - "--repository", "four-key") + "--repository", "medusa") _, err = removeCmd.Output() if err != nil {