github.com/friesencr/pop/v6@v6.1.6/soda/cmd/generate/model_cmd_test.go (about) 1 package generate 2 3 import ( 4 "os" 5 "path/filepath" 6 "testing" 7 8 "github.com/stretchr/testify/require" 9 ) 10 11 func Test_ModelCmd_NoArg(t *testing.T) { 12 r := require.New(t) 13 c := ModelCmd 14 c.SetArgs([]string{}) 15 16 tdir := t.TempDir() 17 18 pwd, err := os.Getwd() 19 r.NoError(err) 20 os.Chdir(tdir) 21 defer os.Chdir(pwd) 22 23 err = c.Execute() 24 r.EqualError(err, "you must set a name for your model") 25 } 26 27 func Test_ModelCmd_NameOnly(t *testing.T) { 28 r := require.New(t) 29 c := ModelCmd 30 c.SetArgs([]string{"users"}) 31 32 tdir := t.TempDir() 33 34 pwd, err := os.Getwd() 35 r.NoError(err) 36 os.Chdir(tdir) 37 defer os.Chdir(pwd) 38 39 err = c.Execute() 40 r.NoError(err) 41 42 r.DirExists(filepath.Join(tdir, "migrations")) 43 r.DirExists(filepath.Join(tdir, "models")) 44 r.FileExists(filepath.Join(tdir, "models", "user.go")) 45 r.FileExists(filepath.Join(tdir, "models", "user_test.go")) 46 }