sqlboiler/cmds/imports_test.go
2016-03-28 01:03:14 +10:00

71 lines
1.3 KiB
Go

package cmds
import (
"reflect"
"testing"
"github.com/pobri19/sqlboiler/dbdrivers"
)
func TestCombineTypeImports(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.Column{
dbdrivers.Column{
Type: "null.Time",
},
dbdrivers.Column{
Type: "null.Time",
},
dbdrivers.Column{
Type: "time.Time",
},
dbdrivers.Column{
Type: "null.Float",
},
}
res1 := combineTypeImports(imports1, sqlBoilerTypeImports, 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 := combineTypeImports(imports2, sqlBoilerTypeImports, cols)
if !reflect.DeepEqual(res2, importsExpected) {
t.Errorf("Expected res2 to match importsExpected, got:\n\n%#v\n", res1)
}
}