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")
}
Exemple #3
0
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)
	}
}
Exemple #4
0
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")
	}
}
Exemple #5
0
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)
	}
}
Exemple #6
0
//############################################################################
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
}
Exemple #7
0
func (b simpleExprBuilder) Equals() int {
	return builder.GetStruct(b).(simpleExpr).Equals()
}
Exemple #8
0
func (b FunctionBuilder) build() functionData {
	return builder.GetStruct(b).(functionData)
}
Exemple #9
0
func (b answersReqBuilder) Build() AnswerRequest {
	return builder.GetStruct(b).(AnswerRequest)
}
Exemple #10
0
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()
}
Exemple #13
0
func (rb ruleBuilder) Build() Rule {
	return builder.GetStruct(rb).(Rule)
}
Exemple #14
0
func TestSetNil(t *testing.T) {
	b := FooBuilder.I(nil)
	builder.GetStruct(b)
}
Exemple #15
0
// 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()
}
Exemple #16
0
// 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()
}
Exemple #17
0
// 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()
}
Exemple #18
0
func (b ContainerBuilder) build() containerData {
	return builder.GetStruct(b).(containerData)
}
Exemple #19
0
// 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()
}
Exemple #20
0
// 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()
}
Exemple #21
0
// 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()
}
Exemple #22
0
// 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()
}
Exemple #23
0
func TestZeroBuilder(t *testing.T) {
	f := builder.GetStruct(fooBuilder{}.X(1)).(Foo)
	if f.X != 1 {
		t.Error("nil builder failed")
	}
}
Exemple #24
0
// 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()
}
Exemple #25
0
//############################################################################
func (p beamerBuilder) Build() common.BeamerCtx {
	return builder.GetStruct(p).(common.BeamerCtx)
}