github.com/supabase/cli@v1.168.1/internal/test/new/new.go (about) 1 package new 2 3 import ( 4 "context" 5 _ "embed" 6 "fmt" 7 "path/filepath" 8 9 "github.com/go-errors/errors" 10 "github.com/spf13/afero" 11 "github.com/supabase/cli/internal/utils" 12 ) 13 14 const ( 15 TemplatePgTAP = "pgtap" 16 ) 17 18 var ( 19 //go:embed templates/pgtap.sql 20 pgtapTest []byte 21 ) 22 23 func Run(ctx context.Context, name, template string, fsys afero.Fs) error { 24 path := filepath.Join(utils.DbTestsDir, fmt.Sprintf("%s_test.sql", name)) 25 if _, err := fsys.Stat(path); err == nil { 26 return errors.New(path + " already exists.") 27 } 28 if err := utils.WriteFile(path, getTemplate(template), fsys); err != nil { 29 return err 30 } 31 fmt.Printf("Created new %s test at %s.\n", template, utils.Bold(path)) 32 return nil 33 } 34 35 func getTemplate(name string) []byte { 36 switch name { 37 case TemplatePgTAP: 38 return pgtapTest 39 } 40 return nil 41 }