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