sqlboiler/cmds/imports_test.go
Patrick O'brien 48a9ba8d29 Added main template test file, fixed errors
* Fixed TestTemplates bug (now shows compile errors properly)
* Fixed all compile errors for templates (except test templates)
* Added conditional imports for column types
2016-03-23 13:08:35 +10:00

72 lines
1.3 KiB
Go

package cmds
import (
"reflect"
"testing"
"github.com/pobri19/sqlboiler/dbdrivers"
)
func TestCombineConditionalTypeImports(t *testing.T) {
imports1 := imports{
standard: importList{
`"errors"`,
`"fmt"`,
},
thirdparty: importList{
`"github.com/pobri19/sqlboiler/boil"`,
},
}
importsExpected := imports{
standard: importList{
`"errors"`,
`"fmt"`,
`"time"`,
},
thirdparty: importList{
`"github.com/pobri19/sqlboiler/boil"`,
`"gopkg.in/guregu/null.v3"`,
},
}
cols := []dbdrivers.DBColumn{
dbdrivers.DBColumn{
Type: "null.Time",
},
dbdrivers.DBColumn{
Type: "null.Time",
},
dbdrivers.DBColumn{
Type: "time.Time",
},
dbdrivers.DBColumn{
Type: "null.Float",
},
}
res1 := combineConditionalTypeImports(imports1, sqlBoilerConditionalTypeImports, cols)
if !reflect.DeepEqual(res1, importsExpected) {
t.Errorf("Expected res1 to match importsExpected, got:\n\n%#v\n", res1)
}
imports2 := imports{
standard: importList{
`"errors"`,
`"fmt"`,
`"time"`,
},
thirdparty: importList{
`"github.com/pobri19/sqlboiler/boil"`,
`"gopkg.in/guregu/null.v3"`,
},
}
res2 := combineConditionalTypeImports(imports2, sqlBoilerConditionalTypeImports, cols)
if !reflect.DeepEqual(res2, importsExpected) {
t.Errorf("Expected res2 to match importsExpected, got:\n\n%#v\n", res1)
}
}