github.com/wawandco/oxplugins@v0.7.11/tools/buffalo/model/imports_test.go (about) 1 package model 2 3 import ( 4 "reflect" 5 "testing" 6 7 "github.com/gobuffalo/flect/name" 8 ) 9 10 func Test_BuildImports(t *testing.T) { 11 cases := []struct { 12 attrs []attr 13 expected []string 14 testName string 15 }{ 16 { 17 testName: "With Default Attributes", 18 attrs: []attr{{Name: name.New("id"), goType: "uuid"}, {Name: name.New("created_at"), goType: "timestamp"}, {Name: name.New("updated_at"), goType: "timestamp"}}, 19 expected: []string{"fmt", "github.com/gofrs/uuid", "time"}, 20 }, 21 { 22 testName: "All Possible Attributes", 23 attrs: []attr{{Name: name.New("id"), goType: "uuid"}, {Name: name.New("created_at"), goType: "timestamp"}, {Name: name.New("updated_at"), goType: "timestamp"}, {Name: name.New("description"), goType: "nulls.String"}, {Name: name.New("prices"), goType: "slices.Float"}}, 24 expected: []string{"fmt", "github.com/gobuffalo/nulls", "github.com/gobuffalo/pop/v5/slices", "github.com/gofrs/uuid", "time"}, 25 }, 26 } 27 28 for _, c := range cases { 29 t.Run(c.testName, func(t *testing.T) { 30 imports := buildImports(c.attrs) 31 if !reflect.DeepEqual(c.expected, imports) { 32 t.Errorf("unexpected result, it should be %v but got %v", c.expected, imports) 33 } 34 }) 35 } 36 }