Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.
Open
32 changes: 32 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ install: generate mod
lint:
@echo "--> Running linter"
@golangci-lint run
go mod verify

.PHONY: all tools generate build install
test:
@echo "--> Running Tests"
@go test ./... -v

.PHONY: all tools generate build install test
113 changes: 113 additions & 0 deletions cmd/utils_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also build/run the app here? Or is that better done in CI?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can do app level scaffolding but not module level, which i think is fine. I can spend time next week working on this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think app level is fine for now and adding module support to the testing at a later date.

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)
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ 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
github.com/spf13/afero v1.2.2 // indirect
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
)
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down