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")
}
예제 #2
0
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")
}
예제 #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)
	}
}
예제 #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")
	}
}
예제 #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)
	}
}
예제 #6
0
파일: beamer.go 프로젝트: denkhaus/beamer
//############################################################################
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
}
예제 #7
0
func (b simpleExprBuilder) Equals() int {
	return builder.GetStruct(b).(simpleExpr).Equals()
}
예제 #8
0
func (b FunctionBuilder) build() functionData {
	return builder.GetStruct(b).(functionData)
}
예제 #9
0
func (b answersReqBuilder) Build() AnswerRequest {
	return builder.GetStruct(b).(AnswerRequest)
}
예제 #10
0
func (b searchReqBuilder) Build() SearchRequest {
	return builder.GetStruct(b).(SearchRequest)
}
예제 #11
0
// 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()
}
예제 #12
0
// 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()
}
예제 #13
0
func (rb ruleBuilder) Build() Rule {
	return builder.GetStruct(rb).(Rule)
}
예제 #14
0
func TestSetNil(t *testing.T) {
	b := FooBuilder.I(nil)
	builder.GetStruct(b)
}
예제 #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()
}
예제 #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()
}
예제 #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()
}
예제 #18
0
func (b ContainerBuilder) build() containerData {
	return builder.GetStruct(b).(containerData)
}
예제 #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()
}
예제 #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()
}
예제 #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()
}
예제 #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()
}
예제 #23
0
func TestZeroBuilder(t *testing.T) {
	f := builder.GetStruct(fooBuilder{}.X(1)).(Foo)
	if f.X != 1 {
		t.Error("nil builder failed")
	}
}
예제 #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()
}
예제 #25
0
파일: beamer.go 프로젝트: denkhaus/beamer
//############################################################################
func (p beamerBuilder) Build() common.BeamerCtx {
	return builder.GetStruct(p).(common.BeamerCtx)
}