Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from Trendyol/feature/cli-tests
Browse files Browse the repository at this point in the history
Add integration tests for set and run commands
  • Loading branch information
burakolgun authored Jun 8, 2020
2 parents 49fb899 + 050f42b commit fb1e4b3
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
File renamed without changes.
101 changes: 101 additions & 0 deletions cmd/run_command_integration_test.go
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)
}
}
41 changes: 41 additions & 0 deletions cmd/set_command_integration_test.go
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)
}
}

0 comments on commit fb1e4b3

Please sign in to comment.