当前位置: 首页>>代码示例>>Golang>>正文


Golang csdb.MustConnectTest函数代码示例

本文整理汇总了Golang中github.com/corestoreio/csfw/storage/csdb.MustConnectTest函数的典型用法代码示例。如果您正苦于以下问题:Golang MustConnectTest函数的具体用法?Golang MustConnectTest怎么用?Golang MustConnectTest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了MustConnectTest函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestSaveToDb

func TestSaveToDb(t *testing.T) {
	//for hacking testing added :-)
	db := csdb.MustConnectTest()
	defer db.Close()
	dbrSess := dbr.NewConnection(db, nil).NewSession(nil)

	//		var peds = TableProductEntityDecimalSlice{
	//			&TableProductEntityDecimal{ValueID: 1, AttributeID: 73, StoreID: 0, EntityID: 1, Value: money.New(money.Precision(4)).Set(9990000)},
	//			&TableProductEntityDecimal{ValueID: 2, AttributeID: 78, StoreID: 0, EntityID: 1, Value: money.New(money.Precision(4))}, // null values
	//			&TableProductEntityDecimal{ValueID: 3, AttributeID: 74, StoreID: 0, EntityID: 1, Value: money.New(money.Precision(4))}, // null values
	//			&TableProductEntityDecimal{ValueID: 4, AttributeID: 77, StoreID: 0, EntityID: 1, Value: money.New(money.Precision(4))}, // null values
	//			&TableProductEntityDecimal{ValueID: 5, AttributeID: 73, StoreID: 1, EntityID: 1, Value: money.New(money.Precision(4)).Set(7059933)},
	//			&TableProductEntityDecimal{ValueID: 6, AttributeID: 73, StoreID: 4, EntityID: 1, Value: money.New(money.Precision(4)).Set(7059933)},
	//			&TableProductEntityDecimal{ValueID: 7, AttributeID: 73, StoreID: 2, EntityID: 1, Value: money.New(money.Precision(4)).Set(7059933)},
	//			&TableProductEntityDecimal{ValueID: 8, AttributeID: 73, StoreID: 3, EntityID: 1, Value: money.New(money.Precision(4)).Set(7059933)},
	//		}

	tuple := &TableProductEntityDecimal{ValueID: 0, AttributeID: 73, StoreID: 3, EntityID: 231, Value: money.New(money.Precision(4)).Set(7779933)}
	tuple2 := &TableProductEntityDecimal{ValueID: 0, AttributeID: 74, StoreID: 2, EntityID: 231, Value: money.New(money.Precision(4)).Set(8889933)}
	ib := dbrSess.InsertInto("catalog_product_entity_decimal")
	ib.Columns("attribute_id", "store_id", "entity_id", "value")

	ib.Values(tuple.AttributeID, tuple.StoreID, tuple.EntityID, &tuple.Value)
	ib.Values(tuple2.AttributeID, tuple2.StoreID, tuple2.EntityID, &tuple2.Value)
	//	t.Error(ib.ToSql())
	res, err := ib.Exec()
	t.Log(err)
	t.Logf("%#v", res)
	t.Log(res.LastInsertId())
	t.Log(res.RowsAffected())

}
开发者ID:bom-d-van,项目名称:csfw,代码行数:32,代码来源:encoding_test.go

示例2: TestGetAttributeSelectSql

func TestGetAttributeSelectSql(t *testing.T) {
	dbc := csdb.MustConnectTest()
	defer dbc.Close()

	dbrSess := dbc.NewSession()
	dbrSelect, err := eav.GetAttributeSelectSql(dbrSess, codegen.NewAddAttrTables(dbc.DB, "customer"), 1, 4)
	if err != nil {
		t.Fatal(err)
	}
	sql, _, err := dbrSelect.ToSql()
	assert.NoError(t, err)

	_, err = sqlbeautifier.FromString(sql) // check for syntax errors
	if err != nil {
		t.Fatalf("%s\n\n%s\n", err, sql)
	}

	if testWantGetAttributeSelectSql != sql {

		buf, err := sqlbeautifier.FromString(testWantGetAttributeSelectSql)
		if err != nil {
			t.Fatalf("%s\n%s\n", err, testWantGetAttributeSelectSql)
		}
		sql = sqlbeautifier.MustFromString(sql)
		println(diff.MustUnified(buf.String(), sql), "\n")
		t.Fatal(sql)
	}

	// @todo error is that we have column attribute_model in the select list but it should not occur
	// because in codegen it is defined that this column has no usage so we can skip it.
}
开发者ID:joao-parana,项目名称:csfw,代码行数:31,代码来源:attribute_sql_test.go

示例3: TestEntityTypeSliceGetByCode

func TestEntityTypeSliceGetByCode(t *testing.T) {
	db := csdb.MustConnectTest()
	defer db.Close()
	dbrSess := dbr.NewConnection(db, nil).NewSession(nil)

	s, err := eav.TableCollection.Structure(eav.TableIndexEntityType)
	if err != nil {
		t.Error(err)
	}

	var entityTypeCollection eav.TableEntityTypeSlice
	_, err = dbrSess.
		Select(s.Columns...).
		From(s.Name).
		LoadStructs(&entityTypeCollection)
	if err != nil {
		t.Error(err)
	}

	etc, err := entityTypeCollection.GetByCode("catalog_categories")
	assert.Nil(t, etc)
	assert.Error(t, err)

	etc, err = entityTypeCollection.GetByCode("catalog_category")
	assert.NotNil(t, etc)
	assert.NoError(t, err)
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:27,代码来源:entity_type_test.go

示例4: TestStorageReInit

func TestStorageReInit(t *testing.T) {

	// quick implement, use mock of dbr.SessionRunner and remove connection
	dbc := csdb.MustConnectTest()
	defer func() { assert.NoError(t, dbc.Close()) }()

	nsg := store.MustNewStorage(nil, nil, nil)
	assert.NoError(t, nsg.ReInit(dbc.NewSession()))

	stores, err := nsg.Stores()
	assert.NoError(t, err)
	assert.True(t, stores.Len() > 0, "Expecting at least one store loaded from DB")
	for _, s := range stores {
		assert.NotEmpty(t, s.Data.Code.String, "Store: %#v", s.Data)
	}

	groups, err := nsg.Groups()
	assert.True(t, groups.Len() > 0, "Expecting at least one group loaded from DB")
	assert.NoError(t, err)
	for _, g := range groups {
		assert.NotEmpty(t, g.Data.Name, "Group: %#v", g.Data)
	}

	websites, err := nsg.Websites()
	assert.True(t, websites.Len() > 0, "Expecting at least one website loaded from DB")
	assert.NoError(t, err)
	for _, w := range websites {
		assert.NotEmpty(t, w.Data.Code.String, "Website: %#v", w.Data)
	}
}
开发者ID:joao-parana,项目名称:csfw,代码行数:30,代码来源:storage_test.go

示例5: TestTableStructure

func TestTableStructure(t *testing.T) {
	db := csdb.MustConnectTest()
	defer db.Close()

	sValid, err := tableMap.Structure(table1)
	assert.NotNil(t, sValid)
	assert.NoError(t, err)

	assert.Equal(t, "catalog_category_anc_categs_index_tmp", tableMap.Name(table2))
	assert.Equal(t, "", tableMap.Name(table4))

	sInvalid, err := tableMap.Structure(table4)
	assert.Nil(t, sInvalid)
	assert.Error(t, err)

	dbrSess := dbr.NewConnection(db, nil).NewSession(nil)
	selectBuilder, err := sValid.Select(dbrSess)
	assert.NoError(t, err)
	selectString, _ := selectBuilder.ToSql()
	assert.Equal(t, "SELECT `main_table`.`category_id`, `main_table`.`path` FROM `catalog_category_anc_categs_index_idx` AS `main_table`", selectString)

	selectBuilder, err = sInvalid.Select(dbrSess)
	assert.Error(t, err)
	assert.Nil(t, selectBuilder)
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:25,代码来源:csdb_test.go

示例6: TestGetFieldNames

func TestGetFieldNames(t *testing.T) {
	db := csdb.MustConnectTest()
	defer db.Close()

	tests := []struct {
		table  string
		pkOnly bool
		count  int
	}{
		{
			table:  "eav_attribute",
			pkOnly: false,
			count:  15,
		},
		{
			table:  "catalog_product_entity_decimal",
			pkOnly: true,
			count:  1,
		},
	}

	for _, test := range tests {
		cols, err := GetColumns(db, test.table)
		if err != nil {
			t.Error(err)
		}
		fields := cols.GetFieldNames(test.pkOnly)
		assert.Len(t, fields, test.count)
	}
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:30,代码来源:database_test.go

示例7: TestGetTables

func TestGetTables(t *testing.T) {
	db := csdb.MustConnectTest()
	defer db.Close()

	tests := []struct {
		query    string
		expErr   bool
		expCount int
	}{
		{
			query:    "SHOW TABLES LIKE 'catalog_product_entity%'",
			expErr:   false,
			expCount: 11,
		},
		{
			query:    "SHOW TABLES LIK ' catalog_product_entity",
			expErr:   true,
			expCount: 0,
		},
	}

	for _, test := range tests {
		tables, err := GetTables(db, test.query)
		if test.expErr {
			assert.Error(t, err)
		}
		if !test.expErr && err != nil {
			t.Error(err)
		}

		assert.Len(t, tables, test.expCount)
	}
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:33,代码来源:database_test.go

示例8: TestApplyCoreConfigData

// TestApplyCoreConfigData reads from the MySQL core_config_data table and applies
// these value to the underlying storage. tries to get back the values from the
// underlying storage
func TestApplyCoreConfigData(t *testing.T) {
	defer debugLogBuf.Reset()
	defer infoLogBuf.Reset()

	dbc := csdb.MustConnectTest()
	defer func() { assert.NoError(t, dbc.Close()) }()
	sess := dbc.NewSession(nil) // nil tricks the NewSession ;-)

	s := config.NewService()
	defer func() { assert.NoError(t, s.Close()) }()

	loadedRows, writtenRows, err := s.ApplyCoreConfigData(sess)
	if err != nil {
		t.Fatal(err)
	}
	assert.True(t, loadedRows > 9, "loadedRows %d", loadedRows)
	assert.True(t, writtenRows > 9, "writtenRows %d", writtenRows)

	//	println("\n", debugLogBuf.String(), "\n")
	//	println("\n", infoLogBuf.String(), "\n")

	assert.NoError(t, s.Write(config.Path("web/secure/offloader_header"), config.ScopeDefault(), config.Value("SSL_OFFLOADED")))

	h, err := s.String(config.Path("web/secure/offloader_header"), config.ScopeDefault())
	assert.NoError(t, err)
	assert.Exactly(t, "SSL_OFFLOADED", h)

	assert.Len(t, s.Storage.AllKeys(), writtenRows)
}
开发者ID:joao-parana,项目名称:csfw,代码行数:32,代码来源:service_test.go

示例9: init

func init() {
	dbc := csdb.MustConnectTest()
	defer dbc.Close()
	if err := eav.TableCollection.Init(dbc.NewSession()); err != nil {
		panic(err)
	}
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:7,代码来源:entity_type_test.go

示例10: init

func init() {
	dbc := csdb.MustConnectTest()
	config.TableCollection.Init(dbc.NewSession())
	if err := dbc.Close(); err != nil {
		panic(err)
	}
}
开发者ID:levcom,项目名称:csfw,代码行数:7,代码来源:manager_test.go

示例11: TestDBStorageMultipleStmt

func TestDBStorageMultipleStmt(t *testing.T) {
	debugLogBuf.Reset()
	defer debugLogBuf.Reset() // contains only data from the debug level, info level will be dumped to os.Stdout
	defer infoLogBuf.Reset()

	if testing.Short() {
		t.Skip("Test skipped in short mode")
	}
	dbc := csdb.MustConnectTest()
	defer func() { assert.NoError(t, dbc.Close()) }()

	sdb := config.MustNewDBStorage(dbc.DB)
	sdb.All.Idle = time.Second * 1
	sdb.Read.Idle = time.Second * 1
	sdb.Write.Idle = time.Second * 1

	sdb.Start()

	tests := []struct {
		key       string
		value     interface{}
		wantValue string
	}{
		{"websites/10/testDBStorage/secure/base_url", "http://corestore.io", "http://corestore.io"},
		{"websites/10/testDBStorage/log/active", 1, "1"},
		{"websites/20/testDBStorage/log/clean", 19.999, "19.999"},
		{"websites/20/testDBStorage/product/shipping", 29.999, "29.999"},
		{"default/0/testDBStorage/checkout/multishipping", false, "false"},
	}
	for i, test := range tests {
		sdb.Set(test.key, test.value)
		assert.Exactly(t, test.wantValue, sdb.Get(test.key), "Test: %v", test)
		if i < 2 {
			// last two iterations reopen a new statement, not closing it and reusing it
			time.Sleep(time.Millisecond * 1500) // trigger ticker to close statements
		}
	}

	for i, test := range tests {
		ak := util.StringSlice(sdb.AllKeys())
		assert.True(t, ak.Include(test.key), "Missing Key: %s", test.key)
		if i < 2 {
			time.Sleep(time.Millisecond * 1500) // trigger ticker to close statements
		}
	}
	assert.NoError(t, sdb.Stop())

	logStr := debugLogBuf.String()
	assert.Exactly(t, 3, strings.Count(logStr, `csdb.ResurrectStmt.stmt.Prepare SQL: "INSERT INTO`))
	assert.Exactly(t, 3, strings.Count(logStr, "csdb.ResurrectStmt.stmt.Prepare SQL: \"SELECT `value` FROM"))

	assert.Exactly(t, 4, strings.Count(logStr, `csdb.ResurrectStmt.stmt.Close SQL: "INSERT INTO`), "\n%s\n", logStr)
	assert.Exactly(t, 4, strings.Count(logStr, "csdb.ResurrectStmt.stmt.Close SQL: \"SELECT `value` FROM"))

	//println("\n", logStr, "\n")

	// 6 is: open close for iteration 0+1, open in iteration 2 and close in iteration 4
	assert.Exactly(t, 6, strings.Count(logStr, fmt.Sprintf("CONCAT(scope,'%s',scope_id,'%s',path) AS `fqpath`", scope.PS, scope.PS)))
}
开发者ID:joao-parana,项目名称:csfw,代码行数:59,代码来源:service_storage_db_test.go

示例12: TestApplyCoreConfigData

func TestApplyCoreConfigData(t *testing.T) {
	db := csdb.MustConnectTest()
	defer db.Close()
	sess := dbr.NewConnection(db, nil).NewSession(nil)

	m := config.NewManager()
	if err := m.ApplyCoreConfigData(sess); err != nil {
		t.Error(err)
	}
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:10,代码来源:manager_test.go

示例13: TestTableGroupSliceLoad

func TestTableGroupSliceLoad(t *testing.T) {
	db := csdb.MustConnectTest()
	defer db.Close()
	dbrSess := dbr.NewConnection(db, nil).NewSession(nil)
	var groups store.TableGroupSlice
	groups.Load(dbrSess)
	assert.True(t, groups.Len() > 2)
	for _, s := range groups {
		assert.True(t, len(s.Name) > 1)
	}
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:11,代码来源:group_test.go

示例14: TestTableStoreSliceLoad

func TestTableStoreSliceLoad(t *testing.T) {
	db := csdb.MustConnectTest()
	defer db.Close()
	dbrSess := dbr.NewConnection(db, nil).NewSession(nil)
	var stores store.TableStoreSlice
	stores.Load(dbrSess)
	assert.True(t, stores.Len() > 2)
	for _, s := range stores {
		assert.True(t, len(s.Code.String) > 1)
	}
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:11,代码来源:store_test.go

示例15: TestApplyCoreConfigData

func TestApplyCoreConfigData(t *testing.T) {
	dbc := csdb.MustConnectTest()
	defer func() { assert.NoError(t, dbc.Close()) }()
	sess := dbc.NewSession(nil)

	m := config.NewManager()
	if err := m.ApplyCoreConfigData(sess); err != nil {
		t.Error(err)
	}
	// todo check if data has been really written ;-)
}
开发者ID:levcom,项目名称:csfw,代码行数:11,代码来源:manager_test.go


注:本文中的github.com/corestoreio/csfw/storage/csdb.MustConnectTest函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。