github.com/dolanor/pop@v4.13.0+incompatible/genny/fizz/cempty/options_test.go (about) 1 package cempty 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 func Test_Options_Validate(t *testing.T) { 11 r := require.New(t) 12 13 t0, _ := time.Parse(time.RFC3339, "2019-08-28T07:46:02Z") 14 nowFunc = func() time.Time { return t0 } 15 defer func() { nowFunc = time.Now }() 16 17 opts := &Options{} 18 err := opts.Validate() 19 r.Error(err) 20 21 opts.TableName = "widget" 22 23 err = opts.Validate() 24 r.NoError(err) 25 26 r.Equal(opts.Name, "20190828074602_create_widgets") 27 r.Equal("migrations", opts.Path) 28 29 // Custom migration name 30 opts.Name = "custom_migration" 31 err = opts.Validate() 32 r.NoError(err) 33 34 r.Equal(opts.Name, "custom_migration") 35 r.Equal("migrations", opts.Path) 36 } 37 38 func Test_Options_Validate_Errors(t *testing.T) { 39 r := require.New(t) 40 41 opts := &Options{ 42 TableName: "widget", 43 Type: "sql", 44 } 45 err := opts.Validate() 46 r.EqualError(err, "sql migrations require a fizz translator") 47 48 opts.Translator = mockTranslator{} 49 opts.Type = "aaa" 50 err = opts.Validate() 51 r.EqualError(err, "aaa migration type is not allowed") 52 }