github.com/wawandco/ox@v0.13.6-0.20230809142027-913b3d837f2a/plugins/tools/flect/initializer_test.go (about) 1 package flect 2 3 import ( 4 "context" 5 "os" 6 "testing" 7 8 "github.com/wawandco/ox/plugins/base/new" 9 ) 10 11 func TestInitializer(t *testing.T) { 12 t.Run("InflectionsFileDoesNotExist", func(t *testing.T) { 13 root := t.TempDir() 14 err := os.Chdir(root) 15 if err != nil { 16 t.Error("could not change to temp directory") 17 } 18 19 i := Initializer{} 20 ctx := context.Background() 21 options := new.Options{ 22 Folder: root, 23 } 24 25 err = i.Initialize(ctx, options) 26 if err != nil { 27 t.Fatalf("error should be nil, got %v", err) 28 } 29 30 _, err = os.Stat(root) 31 32 if os.IsNotExist(err) { 33 t.Fatalf("Did not create file ") 34 } 35 36 }) 37 t.Run("inflectionFileExist", func(t *testing.T) { 38 39 root := t.TempDir() 40 err := os.Chdir(root) 41 if err != nil { 42 t.Error("could not change to temp directory") 43 } 44 45 rootYml := root + "/inflections.yml" 46 _, err = os.Create(rootYml) 47 if err != nil { 48 t.Fatalf("Problem creating file, %v", err) 49 } 50 51 i := Initializer{} 52 ctx := context.Background() 53 options := new.Options{ 54 Folder: root, 55 } 56 57 err = i.Initialize(ctx, options) 58 if err != nil { 59 t.Fatalf("error should be type nil, got %v", err) 60 } 61 }) 62 }