github.com/wawandco/oxpecker@v1.5.7-0.20210910201653-5958d4afdd89/tools/buffalo/cmd/initializer_test.go (about) 1 package cmd 2 3 import ( 4 "bytes" 5 "context" 6 "io/ioutil" 7 "os" 8 "path/filepath" 9 "testing" 10 11 "github.com/wawandco/oxpecker/lifecycle/new" 12 ) 13 14 func TestInitializer(t *testing.T) { 15 t.Run("CompleteArgs", func(t *testing.T) { 16 root := t.TempDir() 17 err := os.Chdir(root) 18 if err != nil { 19 t.Error("could not change to temp directory") 20 } 21 22 err = os.MkdirAll(filepath.Join(root, "myapp"), 0777) 23 if err != nil { 24 t.Error("could not change to temp directory") 25 } 26 27 i := Initializer{} 28 ctx := context.Background() 29 options := new.Options{ 30 Name: "myapp", 31 Module: "oosss/myapp", 32 Folder: filepath.Join(root, "myapp"), 33 } 34 35 err = i.Initialize(ctx, options) 36 if err != nil { 37 t.Fatalf("error should be nil, got %v", err) 38 } 39 40 bmodels, err := ioutil.ReadFile(filepath.Join(root, "myapp", "cmd", "myapp", "main.go")) 41 if err != nil { 42 t.Fatal("should have created the file") 43 } 44 45 if !bytes.Contains(bmodels, []byte(`var server = &servers.Simple{`)) { 46 t.Fatal("should contain server definition") 47 } 48 49 if !bytes.Contains(bmodels, []byte(`bapp.Serve(server)`)) { 50 t.Fatal("should use the server to start the app.") 51 } 52 53 }) 54 }