github.com/wawandco/ox@v0.13.6-0.20230809142027-913b3d837f2a/plugins/tools/ox/model/initializer_test.go (about) 1 package model 2 3 import ( 4 "bytes" 5 "context" 6 "os" 7 "path/filepath" 8 "testing" 9 10 "github.com/wawandco/ox/plugins/base/new" 11 ) 12 13 func TestInitializer(t *testing.T) { 14 t.Run("CompleteArgs", func(t *testing.T) { 15 root := t.TempDir() 16 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 _, err = os.Stat(filepath.Join(root, "myapp", "app", "models", "models_test.go")) 41 if err != nil { 42 t.Fatal("should have created the file") 43 } 44 45 bmodels, err := os.ReadFile(filepath.Join(root, "myapp", "app", "models", "models.go")) 46 if err != nil { 47 t.Fatal("should have created the file") 48 } 49 50 if !bytes.Contains(bmodels, []byte(`github.com/gobuffalo/pop/v6`)) { 51 t.Fatal("models should contain pop import") 52 } 53 54 bmodelst, err := os.ReadFile(filepath.Join(root, "myapp", "app", "models", "models_test.go")) 55 if err != nil { 56 t.Fatal("should have created the file") 57 } 58 59 if !bytes.Contains(bmodelst, []byte(`github.com/gobuffalo/suite/v4`)) { 60 t.Fatal("models should contain suite import") 61 } 62 63 }) 64 65 }