func TestRunWithDB(t *testing.T) { db := &sql.DB{} assert.NotPanics(t, func() { builder.GetStruct(Select().RunWith(db)) builder.GetStruct(Insert("t").RunWith(db)) builder.GetStruct(Update("t").RunWith(db)) builder.GetStruct(Delete("t").RunWith(db)) }, "RunWith(*sql.DB) should not panic") }
func TestRunWithTx(t *testing.T) { tx := &sql.Tx{} assert.NotPanics(t, func() { builder.GetStruct(Select().RunWith(tx)) builder.GetStruct(Insert("t").RunWith(tx)) builder.GetStruct(Update("t").RunWith(tx)) builder.GetStruct(Delete("t").RunWith(tx)) }, "RunWith(*sql.Tx) should not panic") }
func TestGetStruct(t *testing.T) { b := FooBuilder.X(1).Y(2).Add(3).Add(4) s := builder.GetStruct(b).(Foo) expected := Foo{X: 1, Y: 2, Add: []int{3, 4}} if !reflect.DeepEqual(s, expected) { t.Errorf("expected %v, got %v", expected, s) } }
func TestSetInvalidNil(t *testing.T) { var panicVal interface{} func() { defer func() { panicVal = recover() }() b := builder.Set(FooBuilder, "X", nil) builder.GetStruct(b) }() if panicVal == nil { t.Errorf("expected panic, didn't") } }
func TestUnregisteredBuilder(t *testing.T) { b := unregBuilder{}.Add(1) x, _ := builder.Get(b, "X") expected := []interface{}{1} if !reflect.DeepEqual(x.([]interface{}), expected) { t.Errorf("expected %v, got %v", expected, x) } x = builder.GetMap(b)["X"] expected = []interface{}{1} if !reflect.DeepEqual(x.([]interface{}), expected) { t.Errorf("expected %v, got %v", expected, x) } s := builder.GetStruct(b) if s != nil { t.Errorf("expected nil, got %v", s) } }
//############################################################################ func (p beamerBuilder) Run() error { ctx := builder.GetStruct(p).(common.BeamerCtx) pipes := make([]pipe.Pipe, 0) for _, t := range ctx.Tasks { pip, err := t.Assemble(ctx) if err != nil { return err } pipes = append(pipes, pip) } script := pipe.Script(pipes...) output, err := pipe.CombinedOutput(script) if err != nil { return err } applog.Infof("%s", output) return nil }
func (b simpleExprBuilder) Equals() int { return builder.GetStruct(b).(simpleExpr).Equals() }
func (b FunctionBuilder) build() functionData { return builder.GetStruct(b).(functionData) }
func (b answersReqBuilder) Build() AnswerRequest { return builder.GetStruct(b).(AnswerRequest) }
func (b searchReqBuilder) Build() SearchRequest { return builder.GetStruct(b).(SearchRequest) }
// ToSql builds the query into a SQL string and bound args. func (b UpdateBuilder) ToSql() (string, []interface{}, error) { data := builder.GetStruct(b).(updateData) return data.ToSql() }
// Exec builds and Execs the query with the Runner set by RunWith. func (b UpdateBuilder) Exec() (sql.Result, error) { data := builder.GetStruct(b).(updateData) return data.Exec() }
func (rb ruleBuilder) Build() Rule { return builder.GetStruct(rb).(Rule) }
func TestSetNil(t *testing.T) { b := FooBuilder.I(nil) builder.GetStruct(b) }
// Exec builds and Execs the query with the Runner set by RunWith. func (b InsertBuilder) Exec() (sql.Result, error) { data := builder.GetStruct(b).(insertData) return data.Exec() }
// QueryRow builds and QueryRows the query with the Runner set by RunWith. func (b InsertBuilder) QueryRow() RowScanner { data := builder.GetStruct(b).(insertData) return data.QueryRow() }
// Exec builds and Execs the query with the Runner set by RunWith. func (b SelectBuilder) Exec() (sql.Result, error) { data := builder.GetStruct(b).(selectData) return data.Exec() }
func (b ContainerBuilder) build() containerData { return builder.GetStruct(b).(containerData) }
// Query builds and Querys the query with the Runner set by RunWith. func (b SelectBuilder) Query() (*sql.Rows, error) { data := builder.GetStruct(b).(selectData) return data.Query() }
// ToSql builds the query into a SQL string and bound args. func (b SelectBuilder) ToSql() (string, []interface{}, error) { data := builder.GetStruct(b).(selectData) return data.ToSql() }
// QueryRow builds and QueryRows the query with the Runner set by RunWith. func (b SelectBuilder) QueryRow() RowScanner { data := builder.GetStruct(b).(selectData) return data.QueryRow() }
// Query builds and Querys the query with the Runner set by RunWith. func (b InsertBuilder) Query() (*sql.Rows, error) { data := builder.GetStruct(b).(insertData) return data.Query() }
func TestZeroBuilder(t *testing.T) { f := builder.GetStruct(fooBuilder{}.X(1)).(Foo) if f.X != 1 { t.Error("nil builder failed") } }
// ToSql builds the query into a SQL string and bound args. func (b InsertBuilder) ToSql() (string, []interface{}, error) { data := builder.GetStruct(b).(insertData) return data.ToSql() }
//############################################################################ func (p beamerBuilder) Build() common.BeamerCtx { return builder.GetStruct(p).(common.BeamerCtx) }