• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang store.NewGroup函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestNewManagerGroupInit

func TestNewManagerGroupInit(t *testing.T) {

	err := getTestManager(func(ms *mockStorage) {
		ms.g = func() (*store.Group, error) {
			return store.NewGroup(
				&store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2},
				store.SetGroupWebsite(&store.TableWebsite{WebsiteID: 1, Code: dbr.NullString{NullString: sql.NullString{String: "euro", Valid: true}}, Name: dbr.NullString{NullString: sql.NullString{String: "Europe", Valid: true}}, SortOrder: 0, DefaultGroupID: 1, IsDefault: dbr.NullBool{NullBool: sql.NullBool{Bool: true, Valid: true}}}),
			), nil
		}
	}).Init(config.ScopeID(1), config.ScopeGroupID)
	assert.EqualError(t, store.ErrGroupDefaultStoreNotFound, err.Error(), "Incorrect DefaultStore for a Group")

	err = getTestManager().Init(config.ScopeID(21), config.ScopeGroupID)
	assert.EqualError(t, store.ErrGroupNotFound, err.Error())

	tm3 := getTestManager(func(ms *mockStorage) {
		ms.g = func() (*store.Group, error) {
			return store.NewGroup(
				&store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2},
				store.SetGroupWebsite(&store.TableWebsite{WebsiteID: 1, Code: dbr.NullString{NullString: sql.NullString{String: "euro", Valid: true}}, Name: dbr.NullString{NullString: sql.NullString{String: "Europe", Valid: true}}, SortOrder: 0, DefaultGroupID: 1, IsDefault: dbr.NullBool{NullBool: sql.NullBool{Bool: true, Valid: true}}}),
			).SetStores(store.TableStoreSlice{
				&store.TableStore{StoreID: 2, Code: dbr.NullString{NullString: sql.NullString{String: "at", Valid: true}}, WebsiteID: 1, GroupID: 1, Name: "Österreich", SortOrder: 20, IsActive: true},
			}, nil), nil
		}
	})
	err = tm3.Init(config.ScopeID(1), config.ScopeGroupID)
	assert.NoError(t, err)
	g, err := tm3.Group()
	assert.NoError(t, err)
	assert.NotNil(t, g)
	assert.Equal(t, int64(2), g.Data.DefaultStoreID)
}
开发者ID:postfix,项目名称:csfw,代码行数:32,代码来源:manager_test.go


示例2: TestNewGroupSetStores

func TestNewGroupSetStores(t *testing.T) {

	g := store.NewGroup(
		&store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2},
		nil,
	)
	g.SetStores(
		store.TableStoreSlice{
			&store.TableStore{StoreID: 0, Code: dbr.NullString{NullString: sql.NullString{String: "admin", Valid: true}}, WebsiteID: 0, GroupID: 0, Name: "Admin", SortOrder: 0, IsActive: true},
			&store.TableStore{StoreID: 5, Code: dbr.NullString{NullString: sql.NullString{String: "au", Valid: true}}, WebsiteID: 2, GroupID: 3, Name: "Australia", SortOrder: 10, IsActive: true},
			&store.TableStore{StoreID: 1, Code: dbr.NullString{NullString: sql.NullString{String: "de", Valid: true}}, WebsiteID: 1, GroupID: 1, Name: "Germany", SortOrder: 10, IsActive: true},
			&store.TableStore{StoreID: 4, Code: dbr.NullString{NullString: sql.NullString{String: "uk", Valid: true}}, WebsiteID: 1, GroupID: 2, Name: "UK", SortOrder: 10, IsActive: true},
			&store.TableStore{StoreID: 2, Code: dbr.NullString{NullString: sql.NullString{String: "at", Valid: true}}, WebsiteID: 1, GroupID: 1, Name: "Österreich", SortOrder: 20, IsActive: true},
			&store.TableStore{StoreID: 6, Code: dbr.NullString{NullString: sql.NullString{String: "nz", Valid: true}}, WebsiteID: 2, GroupID: 3, Name: "Kiwi", SortOrder: 30, IsActive: true},
			&store.TableStore{StoreID: 3, Code: dbr.NullString{NullString: sql.NullString{String: "ch", Valid: true}}, WebsiteID: 1, GroupID: 1, Name: "Schweiz", SortOrder: 30, IsActive: true},
		},
		&store.TableWebsite{WebsiteID: 1, Code: dbr.NullString{NullString: sql.NullString{String: "euro", Valid: true}}, Name: dbr.NullString{NullString: sql.NullString{String: "Europe", Valid: true}}, SortOrder: 0, DefaultGroupID: 1, IsDefault: dbr.NullBool{NullBool: sql.NullBool{Bool: true, Valid: true}}},
	)
	gStores, err := g.Stores()
	assert.NoError(t, err)
	assert.EqualValues(t, utils.StringSlice{"de", "at", "ch"}, gStores.Codes())

	gDefaultStore, err := g.DefaultStore()
	assert.NoError(t, err)
	assert.EqualValues(t, "euro", gDefaultStore.Website().Data().Code.String)
	assert.EqualValues(t, "DACH Group", gDefaultStore.Group().Data().Name)
	assert.EqualValues(t, "at", gDefaultStore.Data().Code.String)
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:28,代码来源:group_test.go


示例3: TestNewGroupSetStoresPanicWebsiteIncorrect

func TestNewGroupSetStoresPanicWebsiteIncorrect(t *testing.T) {
	defer func() {
		if r := recover(); r != nil {
			if err, ok := r.(error); ok {
				assert.EqualError(t, store.ErrGroupWebsiteNotFound, err.Error())
			} else {
				t.Errorf("Failed to convert to type error: %#v", err)
			}
		} else {
			t.Error("Cannot find panic")
		}
	}()

	g := store.NewGroup(
		&store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2},
		nil,
	)

	g.SetStores(
		store.TableStoreSlice{
			&store.TableStore{StoreID: 0, Code: dbr.NullString{NullString: sql.NullString{String: "admin", Valid: true}}, WebsiteID: 0, GroupID: 0, Name: "Admin", SortOrder: 0, IsActive: true},
		},
		&store.TableWebsite{WebsiteID: 2, Code: dbr.NullString{NullString: sql.NullString{String: "oz", Valid: true}}, Name: dbr.NullString{NullString: sql.NullString{String: "OZ", Valid: true}}, SortOrder: 20, DefaultGroupID: 3, IsDefault: dbr.NullBool{NullBool: sql.NullBool{Bool: false, Valid: true}}},
	)
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:25,代码来源:group_test.go


示例4: TestNewGroupSetStores

func TestNewGroupSetStores(t *testing.T) {

	g, err := store.NewGroup(
		&store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2},
		nil, // this is just for to confuse the NewGroup ApplyOption function
		store.SetGroupStores(
			store.TableStoreSlice{
				&store.TableStore{StoreID: 0, Code: dbr.NewNullString("admin"), WebsiteID: 0, GroupID: 0, Name: "Admin", SortOrder: 0, IsActive: true},
				&store.TableStore{StoreID: 5, Code: dbr.NewNullString("au"), WebsiteID: 2, GroupID: 3, Name: "Australia", SortOrder: 10, IsActive: true},
				&store.TableStore{StoreID: 1, Code: dbr.NewNullString("de"), WebsiteID: 1, GroupID: 1, Name: "Germany", SortOrder: 10, IsActive: true},
				&store.TableStore{StoreID: 4, Code: dbr.NewNullString("uk"), WebsiteID: 1, GroupID: 2, Name: "UK", SortOrder: 10, IsActive: true},
				&store.TableStore{StoreID: 2, Code: dbr.NewNullString("at"), WebsiteID: 1, GroupID: 1, Name: "Österreich", SortOrder: 20, IsActive: true},
				&store.TableStore{StoreID: 6, Code: dbr.NewNullString("nz"), WebsiteID: 2, GroupID: 3, Name: "Kiwi", SortOrder: 30, IsActive: true},
				&store.TableStore{StoreID: 3, Code: dbr.NewNullString("ch"), WebsiteID: 1, GroupID: 1, Name: "Schweiz", SortOrder: 30, IsActive: true},
			},
			&store.TableWebsite{WebsiteID: 1, Code: dbr.NewNullString("euro"), Name: dbr.NewNullString("Europe"), SortOrder: 0, DefaultGroupID: 1, IsDefault: dbr.NewNullBool(true)},
		),
	)
	assert.NoError(t, err)

	assert.NotNil(t, g.Stores)
	assert.EqualValues(t, utils.StringSlice{"de", "at", "ch"}, g.Stores.Codes())

	gDefaultStore, err := g.DefaultStore()
	assert.NoError(t, err)
	assert.EqualValues(t, "euro", gDefaultStore.Website.Data.Code.String)
	assert.EqualValues(t, "DACH Group", gDefaultStore.Group.Data.Name)
	assert.EqualValues(t, "at", gDefaultStore.Data.Code.String)
}
开发者ID:levcom,项目名称:csfw,代码行数:29,代码来源:group_test.go


示例5: TestNewGroupPanicWebsiteIncorrect

func TestNewGroupPanicWebsiteIncorrect(t *testing.T) {
	ng, err := store.NewGroup(
		&store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2},
		store.SetGroupWebsite(&store.TableWebsite{WebsiteID: 2, Code: dbr.NewNullString("oz"), Name: dbr.NewNullString("OZ"), SortOrder: 20, DefaultGroupID: 3, IsDefault: dbr.NewNullBool(false)}),
	)
	assert.Nil(t, ng)
	assert.EqualError(t, store.ErrGroupWebsiteNotFound, err.Error())
}
开发者ID:levcom,项目名称:csfw,代码行数:8,代码来源:group_test.go


示例6: TestNewGroup

func TestNewGroup(t *testing.T) {
	g := store.NewGroup(
		&store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2},
		nil,
	)
	assert.EqualValues(t, "DACH Group", g.Data.Name)
	assert.Nil(t, g.Stores)

	gStores2, err := g.DefaultStore()
	assert.Nil(t, gStores2)
	assert.EqualError(t, store.ErrGroupDefaultStoreNotFound, err.Error())
}
开发者ID:postfix,项目名称:csfw,代码行数:12,代码来源:group_test.go


示例7: TestNewGroupSetStoresErrorWebsiteIncorrect

func TestNewGroupSetStoresErrorWebsiteIncorrect(t *testing.T) {
	g, err := store.NewGroup(
		&store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2},
		store.SetGroupStores(
			store.TableStoreSlice{
				&store.TableStore{StoreID: 0, Code: dbr.NewNullString("admin"), WebsiteID: 0, GroupID: 0, Name: "Admin", SortOrder: 0, IsActive: true},
			},
			&store.TableWebsite{WebsiteID: 2, Code: dbr.NewNullString("oz"), Name: dbr.NewNullString("OZ"), SortOrder: 20, DefaultGroupID: 3, IsDefault: dbr.NewNullBool(false)},
		),
	)
	assert.Nil(t, g)
	assert.EqualError(t, store.ErrGroupWebsiteIntegrityFailed, err.Error())
}
开发者ID:levcom,项目名称:csfw,代码行数:13,代码来源:group_test.go


示例8: TestNewGroupPanic

func TestNewGroupPanic(t *testing.T) {
	defer func() {
		if r := recover(); r != nil {
			if err, ok := r.(error); ok {
				assert.EqualError(t, store.ErrStoreNewArgNil, err.Error())
			} else {
				t.Errorf("Failed to convert to type error: %#v", err)
			}
		} else {
			t.Error("Cannot find panic")
		}
	}()
	_ = store.NewGroup(nil, nil)
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:14,代码来源:group_test.go


示例9: TestNewGroupSetStoresErrorWebsiteIsNil

func TestNewGroupSetStoresErrorWebsiteIsNil(t *testing.T) {
	g, err := store.NewGroup(
		&store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2},
		nil,
		store.SetGroupStores(
			store.TableStoreSlice{
				&store.TableStore{StoreID: 0, Code: dbr.NewNullString("admin"), WebsiteID: 0, GroupID: 0, Name: "Admin", SortOrder: 0, IsActive: true},
			},
			nil,
		),
	)
	assert.Nil(t, g)
	assert.EqualError(t, store.ErrGroupWebsiteNotFound, err.Error())
}
开发者ID:levcom,项目名称:csfw,代码行数:14,代码来源:group_test.go


示例10: TestNewManagerGroup

func TestNewManagerGroup(t *testing.T) {
	var managerGroupSimpleTest = getTestManager(func(ms *mockStorage) {
		ms.g = func() (*store.Group, error) {
			return store.NewGroup(
				&store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2},
				store.SetGroupWebsite(&store.TableWebsite{WebsiteID: 1, Code: dbr.NullString{NullString: sql.NullString{String: "euro", Valid: true}}, Name: dbr.NullString{NullString: sql.NullString{String: "Europe", Valid: true}}, SortOrder: 0, DefaultGroupID: 1, IsDefault: dbr.NullBool{NullBool: sql.NullBool{Bool: true, Valid: true}}}),
			), nil
		}
		ms.s = func() (*store.Store, error) {
			return store.NewStore(
				&store.TableStore{StoreID: 1, Code: dbr.NullString{NullString: sql.NullString{String: "de", Valid: true}}, WebsiteID: 1, GroupID: 1, Name: "Germany", SortOrder: 10, IsActive: true},
				&store.TableWebsite{WebsiteID: 1, Code: dbr.NullString{NullString: sql.NullString{String: "euro", Valid: true}}, Name: dbr.NullString{NullString: sql.NullString{String: "Europe", Valid: true}}, SortOrder: 0, DefaultGroupID: 1, IsDefault: dbr.NullBool{NullBool: sql.NullBool{Bool: true, Valid: true}}},
				&store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2},
			), nil
		}
	})

	tests := []struct {
		m               *store.Manager
		have            config.ScopeIDer
		wantErr         error
		wantGroupName   string
		wantWebsiteCode string
	}{
		{managerGroupSimpleTest, nil, store.ErrAppStoreNotSet, "", ""},
		{getTestManager(), config.ScopeID(20), store.ErrGroupNotFound, "", ""},
		{managerGroupSimpleTest, config.ScopeID(1), nil, "DACH Group", "euro"},
		{managerGroupSimpleTest, config.ScopeID(1), nil, "DACH Group", "euro"},
	}

	for _, test := range tests {
		g, err := test.m.Group(test.have)
		if test.wantErr != nil {
			assert.Nil(t, g)
			assert.EqualError(t, test.wantErr, err.Error(), "test %#v", test)
		} else {
			assert.NotNil(t, g, "test %#v", test)
			assert.NoError(t, err, "test %#v", test)
			assert.Equal(t, test.wantGroupName, g.Data.Name)
			assert.Equal(t, test.wantWebsiteCode, g.Website.Data.Code.String)
		}
	}
	assert.False(t, managerGroupSimpleTest.IsCacheEmpty())
	managerGroupSimpleTest.ClearCache()
	assert.True(t, managerGroupSimpleTest.IsCacheEmpty())
}
开发者ID:postfix,项目名称:csfw,代码行数:46,代码来源:manager_test.go


示例11: TestNewServiceGroup

func TestNewServiceGroup(t *testing.T) {
	var serviceGroupSimpleTest = storemock.MustNewService(scope.Option{}, func(ms *storemock.Storage) {
		ms.MockGroup = func() (*store.Group, error) {
			return store.NewGroup(
				&store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2},
				store.SetGroupWebsite(&store.TableWebsite{WebsiteID: 1, Code: dbr.NewNullString("euro"), Name: dbr.NewNullString("Europe"), SortOrder: 0, DefaultGroupID: 1, IsDefault: dbr.NewNullBool(true)}),
			)
		}
		ms.MockStore = func() (*store.Store, error) {
			return store.NewStore(
				&store.TableStore{StoreID: 1, Code: dbr.NewNullString("de"), WebsiteID: 1, GroupID: 1, Name: "Germany", SortOrder: 10, IsActive: true},
				&store.TableWebsite{WebsiteID: 1, Code: dbr.NewNullString("euro"), Name: dbr.NewNullString("Europe"), SortOrder: 0, DefaultGroupID: 1, IsDefault: dbr.NewNullBool(true)},
				&store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2},
			)
		}
	})

	tests := []struct {
		m               *store.Service
		have            scope.GroupIDer
		wantErr         error
		wantGroupName   string
		wantWebsiteCode string
	}{
		{serviceGroupSimpleTest, scope.MockID(20), nil, "DACH Group", "euro"},
		{serviceGroupSimpleTest, scope.MockID(1), nil, "DACH Group", "euro"},
		{serviceGroupSimpleTest, scope.MockID(1), nil, "DACH Group", "euro"},
	}

	for i, test := range tests {
		g, err := test.m.Group(test.have)
		if test.wantErr != nil {
			assert.Nil(t, g, "Index %d", i)
			assert.EqualError(t, test.wantErr, err.Error(), "test %#v", test)
		} else {
			assert.NotNil(t, g, "test %#v", test)
			assert.NoError(t, err, "test %#v", test)
			assert.Equal(t, test.wantGroupName, g.Data.Name)
			assert.Equal(t, test.wantWebsiteCode, g.Website.Data.Code.String)
		}
	}
	assert.False(t, serviceGroupSimpleTest.IsCacheEmpty())
	serviceGroupSimpleTest.ClearCache()
	assert.True(t, serviceGroupSimpleTest.IsCacheEmpty())
}
开发者ID:levcom,项目名称:csfw,代码行数:45,代码来源:service_test.go


示例12: TestNewGroupErrorArgument

func TestNewGroupErrorArgument(t *testing.T) {
	ng, err := store.NewGroup(nil, nil)
	assert.Nil(t, ng)
	assert.EqualError(t, store.ErrArgumentCannotBeNil, err.Error())
}
开发者ID:levcom,项目名称:csfw,代码行数:5,代码来源:group_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang store.NewStore函数代码示例发布时间:2022-05-23
下一篇:
Golang money.Money类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap