diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..3d20cb4 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,32 @@ +name: Go +on: [pull_request] +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.13 + uses: actions/setup-go@v1 + with: + go-version: 1.13 + id: go + + # This is used since the above action does not set it for now + # Remove once https://github.com/actions/setup-go/issues/27 is fixed + - name: setup env + run: | + echo "::set-env name=GOPATH::$(go env GOPATH)" + echo "::add-path::$(go env GOPATH)/bin" + shell: bash + + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + + - name: Tools + run: make tools + + - name: Build + run: make build + + - name: Test + run: make test diff --git a/Makefile b/Makefile index 6b127a7..922cae9 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,9 @@ install: generate mod lint: @echo "--> Running linter" @golangci-lint run - go mod verify -.PHONY: all tools generate build install \ No newline at end of file +test: + @echo "--> Running Tests" + @go test ./... -v + +.PHONY: all tools generate build install test \ No newline at end of file diff --git a/cmd/utils_test.go b/cmd/utils_test.go new file mode 100644 index 0000000..1b98018 --- /dev/null +++ b/cmd/utils_test.go @@ -0,0 +1,113 @@ +package cmd + +import ( + "io/ioutil" + "log" + "os" + "strings" + "testing" + + "github.com/iancoleman/strcase" + "github.com/stretchr/testify/require" +) + +func TestScaffoldTutorialNameservice(t *testing.T) { + tmp, err := ioutil.TempDir("", "scaffold-test-") + if err != nil { + log.Fatal(err) + } + defer os.RemoveAll(tmp) // clean up + os.Chdir(tmp) + + user := "username" + repo := "repository" + dir := "nameservice" + nameRaw := dir + nameCapitalCamelCase := strcase.ToCamel(nameRaw) + nameLowerCamelCase := strcase.ToLowerCamel(nameRaw) + nameLowerCase := strings.ToLower(nameLowerCamelCase) + ns := UserRepoArgs{ + Dir: dir, + User: user, + Repo: repo, + NameRaw: nameRaw, + NameLowerCase: nameLowerCase, + NameCapitalCamelCase: nameCapitalCamelCase, + NameLowerCamelCase: nameLowerCamelCase, + } + err = scaffold(dir, outputPath, ns) + require.NoError(t, err) +} +func TestScaffoldTutorialHelloChain(t *testing.T) { + tmp, err := ioutil.TempDir("", "scaffold-test-") + if err != nil { + log.Fatal(err) + } + defer os.RemoveAll(tmp) // clean up + os.Chdir(tmp) + + user := "username" + repo := "repository" + dir := "hellochain" + nameRaw := dir + nameCapitalCamelCase := strcase.ToCamel(nameRaw) + nameLowerCamelCase := strcase.ToLowerCamel(nameRaw) + nameLowerCase := strings.ToLower(nameLowerCamelCase) + ns := UserRepoArgs{ + Dir: dir, + User: user, + Repo: repo, + NameRaw: nameRaw, + NameLowerCase: nameLowerCase, + NameCapitalCamelCase: nameCapitalCamelCase, + NameLowerCamelCase: nameLowerCamelCase, + } + err = scaffold(dir, outputPath, ns) + require.NoError(t, err) +} + +func TestScaffoldApp(t *testing.T) { + tmp, err := ioutil.TempDir("", "scaffold-test-") + if err != nil { + log.Fatal(err) + } + defer os.RemoveAll(tmp) // clean up + os.Chdir(tmp) + + lvl := "lvl-1" + dir := lvl + user := "username" + repo := "repository" + + ns := UserRepoArgs{ + Dir: dir, + User: user, + Repo: repo, + } + err = scaffold(dir, outputPath, ns) + require.NoError(t, err) +} + +func TestScaffoldModule(t *testing.T) { + tmp, err := ioutil.TempDir("", "scaffold-test-") + if err != nil { + log.Fatal(err) + } + // defer os.RemoveAll(tmp) // clean up + os.Chdir(tmp) + + dir := "module" + user := "username" + repo := "repository" + nameRaw := "myModule" + nameLowerCase := strings.ToLower(nameRaw) + mdl := UserRepoArgs{ + User: user, + Repo: repo, + Dir: dir, + NameRaw: nameRaw, + NameLowerCase: nameLowerCase, + } + err = scaffold(dir, outputPath, mdl) + require.NoError(t, err) +} diff --git a/go.mod b/go.mod index d5811d9..2a57ef6 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/cosmos/scaffold go 1.13 require ( + github.com/go-bindata/go-bindata v3.1.2+incompatible // indirect github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 github.com/mitchellh/go-homedir v1.1.0 github.com/pelletier/go-toml v1.4.0 // indirect @@ -10,7 +11,7 @@ require ( github.com/spf13/cobra v0.0.5 github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/viper v1.5.0 - github.com/stretchr/testify v1.4.0 // indirect + github.com/stretchr/testify v1.4.0 golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // indirect golang.org/x/text v0.3.2 // indirect ) diff --git a/go.sum b/go.sum index 54df01d..4bd9681 100644 --- a/go.sum +++ b/go.sum @@ -25,6 +25,8 @@ github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8 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/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE= +github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0 h1:MP4Eh7ZCb31lleYCFuwm0oe4/YGak+5l1vA2NOE80nA= @@ -114,6 +116,7 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM github.com/spf13/viper v1.5.0 h1:GpsTwfsQ27oS/Aha/6d1oD7tpKIqWnOA6tgOX9HHkt4= github.com/spf13/viper v1.5.0/go.mod h1:AkYRkVJF8TkSG/xet6PzXX+l39KhhXa2pdqVSxnTcn4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=