github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/genny/newapp/web/web_test.go (about)

     1  package web
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/gobuffalo/buffalo/genny/newapp/core"
     8  	"github.com/gobuffalo/envy"
     9  	"github.com/gobuffalo/genny/v2/gentest"
    10  	"github.com/gobuffalo/meta"
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func init() {
    15  	// normalize command output
    16  	envy.Set("GO_BIN", "go")
    17  }
    18  
    19  func Test_New(t *testing.T) {
    20  	r := require.New(t)
    21  
    22  	app := meta.Named("web", ".")
    23  	(&app).PackageRoot("web")
    24  	app.WithModules = true
    25  	envy.Set(envy.GO111MODULE, "on")
    26  
    27  	gg, err := New(&Options{
    28  		Options: &core.Options{
    29  			App: app,
    30  		},
    31  	})
    32  	r.NoError(err)
    33  
    34  	run := gentest.NewRunner()
    35  	run.WithGroup(gg)
    36  
    37  	r.NoError(run.Run())
    38  
    39  	res := run.Results()
    40  
    41  	cmds := []string{
    42  		"go mod init web",
    43  	}
    44  	r.Len(res.Commands, len(cmds))
    45  
    46  	for i, c := range res.Commands {
    47  		r.Equal(cmds[i], strings.Join(c.Args, " "))
    48  	}
    49  
    50  	for _, e := range commonExpected {
    51  		_, err = res.Find(e)
    52  		r.NoError(err)
    53  	}
    54  
    55  	f, err := res.Find("actions/render.go")
    56  	r.NoError(err)
    57  
    58  	body := f.String()
    59  	r.Contains(body, `TemplatesBox: packr.New("app:templates", "../templates"),`)
    60  	r.NotContains(body, `DefaultContentType: "application/json",`)
    61  	unexpected := []string{
    62  		"Dockerfile",
    63  		"database.yml",
    64  		"models/models.go",
    65  		"go.mod",
    66  		".buffalo.dev.yml",
    67  		"assets/css/application.scss.css",
    68  		"public/assets/application.js",
    69  	}
    70  
    71  	for _, u := range unexpected {
    72  		_, err = res.Find(u)
    73  		r.Error(err)
    74  	}
    75  }
    76  
    77  var commonExpected = []string{
    78  	"main.go",
    79  	"actions/app.go",
    80  	"actions/actions_test.go",
    81  	"actions/render.go",
    82  	"actions/home.go",
    83  	"actions/home_test.go",
    84  	"fixtures/sample.toml",
    85  	"grifts/init.go",
    86  	".codeclimate.yml",
    87  	".env",
    88  	"inflections.json",
    89  	"README.md",
    90  	"locales/all.en-us.yaml",
    91  	"public/robots.txt",
    92  	"templates/_flash.plush.html",
    93  	"templates/application.plush.html",
    94  	"templates/index.plush.html",
    95  }