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 #1 from Trendyol/feature/cli-tests
Browse files Browse the repository at this point in the history
Add cli tests for repository command
  • Loading branch information
burakolgun authored May 25, 2020
2 parents 51a0554 + d1fe15c commit 49fb899
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 0 deletions.
Binary file removed .DS_Store
Binary file not shown.
135 changes: 135 additions & 0 deletions cmd/repository_command_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package cmd

import (
"bytes"
"os/exec"
"strings"
"testing"
)

// There is not any mocking. Do not run tests when use the this tool.

func TestAddCommand_WhenRunsWithEmptyArgs_ReturnsOutput(t *testing.T) {
cmd := exec.Command("go", "run", "../main.go", "add",
"--cloneAddress", "",
"--team", "",
"--releaseTagPattern", "",
"--fixCommitPatterns", "")

out, err := cmd.Output()
if err != nil {
t.Errorf(err.Error())
}

want := "You must specify a repository to clone"
got := string(out)
if !strings.Contains(got, want) {
t.Errorf("Unexpected data.\nGot: %s\nExpected: %s", got, want)
}
}

func TestAddCommand_WhenRunsWithCorrectCloneAddressButWrongArgs_ReturnsOutput(t *testing.T) {
cmd := exec.Command("go", "run", "../main.go", "add",
"--cloneAddress", "https://github.com/Trendyol/four-key.git",
"--teams=")

var got bytes.Buffer
cmd.Stderr = &got
_, _ = cmd.Output()

want := "unknown flag: --teams"
if !strings.Contains(got.String(), want) {
t.Errorf("Unexpected data.\nGot: %s\nExpected: %s", got.String(), want)
}
}

func TestAddCommand_WhenRunsWithCorrectArgs_ReturnsOutput(t *testing.T) {
cmd := 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")

out, err := cmd.Output()
if err != nil {
t.Errorf(err.Error())
}

want := "successfully added your repository to config file"
got := string(out)
if !strings.Contains(got, want) {
t.Errorf("Unexpected data.\nGot: %s\nExpected: %s", got, want)
}
}

func TestRemoveCommand_WhenRunsWithWrongArg_ReturnsOutput(t *testing.T) {
cmd := exec.Command("go", "run", "../main.go", "remove",
"--repositorysss", "")

var got bytes.Buffer
cmd.Stderr = &got
_, _ = cmd.Output()

want := "unknown flag: --repositorysss"
if !strings.Contains(got.String(), want) {
t.Errorf("Unexpected data.\nGot: %s\nExpected: %s", got.String(), want)
}
}

func TestRemoveCommand_WhenRunsWithCorrectArg_ReturnsOutput(t *testing.T) {
cmd := 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")

out, err := cmd.Output()
if err != nil {
t.Errorf(err.Error())
}

cmd = exec.Command("go", "run", "../main.go", "remove",
"--repository", "four-key")

out, err = cmd.Output()
if err != nil {
t.Errorf(err.Error())
}

want := "successfully removed four-key repository from the config file"
got := string(out)
if !strings.Contains(got, want) {
t.Errorf("Unexpected data.\nGot: %s\nExpected: %s", got, want)
}
}

func TestRemoveCommand_WhenRunsWithDoesNotExistRepository_ReturnsOutput(t *testing.T) {
cmd := exec.Command("go", "run", "../main.go", "remove",
"--repository", "four-key")

out, err := cmd.Output()
if err != nil {
t.Errorf(err.Error())
}

want := "The four-key repository does not exist!"
got := string(out)
if !strings.Contains(got, want) {
t.Errorf("Unexpected data.\nGot: %s\nExpected: %s", got, want)
}
}

func TestListCommand_WhenRunsCorrectly_ReturnsOutput(t *testing.T) {
cmd := exec.Command("go", "run", "../main.go", "list")

out, err := cmd.Output()
if err != nil {
t.Errorf(err.Error())
}

want := "repository/repositories has been found"
got := string(out)
if !strings.Contains(got, want) {
t.Errorf("Unexpected data.\nGot: %s\nExpected: %s", got, want)
}
}
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
Expand All @@ -56,6 +57,7 @@ github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
Expand All @@ -79,16 +81,19 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
Expand Down Expand Up @@ -116,13 +121,17 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8=
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.4.0 h1:yXHLWeravcrgGyFSyCgdYpXQ9dR9c/WED3pg1RhxqEU=
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4=
github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI=
Expand Down
Binary file removed settings/.DS_Store
Binary file not shown.

0 comments on commit 49fb899

Please sign in to comment.