github.com/wawandco/oxpecker@v1.5.7-0.20210910201653-5958d4afdd89/tools/buffalo/config/initializer_test.go (about) 1 package config 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 29 ctx := context.Background() 30 options := new.Options{ 31 Name: "myapp", 32 Module: "oosss/myapp", 33 Folder: filepath.Join(root, "myapp"), 34 } 35 36 err = i.Initialize(ctx, options) 37 if err != nil { 38 t.Fatalf("error should be nil, got %v", err) 39 } 40 41 bm, err := ioutil.ReadFile(filepath.Join(root, "myapp", "config", "database.yml")) 42 if err != nil { 43 t.Fatal("should have created the file") 44 } 45 46 if !bytes.Contains(bm, []byte(`{{ envOr "DATABASE_URL" "postgres://postgres:postgres@127.0.0.1:5432/myapp_test?sslmode=disable" }}`)) { 47 t.Fatalf("should contain %v envor expression", string(bm)) 48 } 49 50 }) 51 }