本文整理汇总了Golang中github.com/corestoreio/csfw/config.ScopeID函数的典型用法代码示例。如果您正苦于以下问题:Golang ScopeID函数的具体用法?Golang ScopeID怎么用?Golang ScopeID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ScopeID函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: TestNewManagerStoreInit
func TestNewManagerStoreInit(t *testing.T) {
tms := getTestManager(func(ms *mockStorage) {
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 {
haveManager *store.Manager
haveID config.ScopeIDer
wantErr error
}{
{tms, config.ScopeID(1), nil},
{tms, config.ScopeID(1), store.ErrAppStoreSet},
{tms, nil, store.ErrAppStoreSet},
{tms, nil, store.ErrAppStoreSet},
}
for _, test := range tests {
haveErr := test.haveManager.Init(test.haveID, config.ScopeStoreID)
if test.wantErr != nil {
assert.Error(t, haveErr)
assert.EqualError(t, test.wantErr, haveErr.Error())
} else {
assert.NoError(t, haveErr)
}
s, err := test.haveManager.Store()
assert.NotNil(t, s)
assert.NoError(t, err)
}
}
开发者ID:postfix,项目名称:csfw,代码行数:35,代码来源:manager_test.go
示例3: TestDialerPoolSingleton
func TestDialerPoolSingleton(t *testing.T) {
dm1, err := NewDaemon(
SetConfig(configMock),
SetScope(config.ScopeID(6023)),
)
assert.NoError(t, err)
assert.NotNil(t, dm1)
assert.Equal(t, uint64(0x96b8eb270abcef94), dm1.ID()) // "smtp.fastmail.com40402522e71a49e"
dm2, err := NewDaemon(
SetConfig(configMock),
SetScope(config.ScopeID(6023)),
)
assert.NoError(t, err)
assert.NotNil(t, dm2)
// t.Logf("%p == %p", dm1.dialer, dm2.dialer)
dp1 := dm1.dialer
dp2 := dm2.dialer
assert.True(t, dp1 == dp2, "dm1.dialer != dm2.dialer but must be equal")
dm3, err := NewDaemon(
SetConfig(configMock),
SetScope(config.ScopeID(7077)),
)
assert.NoError(t, err)
assert.NotNil(t, dm3)
dp3 := dm3.dialer
assert.True(t, dp1 == dp2 && dp1 != dp3 && dp2 != dp3, "dm1.dialer == dm2.dialer && dm1.dialer != dm3.dialer")
}
开发者ID:optimuse,项目名称:csfw,代码行数:33,代码来源:daemon_dialer_test.go
示例4: DefaultStoreView
// DefaultStoreView traverses through the websites to find the default website and gets
// the default group which has the default store id assigned to. Only one website can be the default one.
func (st *Storage) DefaultStoreView() (*Store, error) {
for _, website := range st.websites {
if website.IsDefault.Bool && website.IsDefault.Valid {
g, err := st.group(config.ScopeID(website.DefaultGroupID))
if err != nil {
return nil, err
}
return st.Store(config.ScopeID(g.DefaultStoreID))
}
}
return nil, ErrStoreNotFound
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:14,代码来源:storage.go
示例5: NewDaemon
// NewDaemon creates a new mail sending daemon to send to a SMTP server.
// Per default it uses localhost:25, creates an unbuffered channel, uses the
// config.DefaultManager, applies the admin scope (0) and sets the SMTP
// timeout to 30s.
func NewDaemon(opts ...DaemonOption) (*Daemon, error) {
d := &Daemon{
config: config.DefaultManager,
scopeID: config.ScopeID(0), // Default Scope aka Admin Scope
smtpTimeout: time.Second * 30,
}
d.SetOptions(opts...)
if d.IsOffline() {
SetSendFunc(OfflineSend)(d)
}
if d.msgChan == nil {
d.msgChan = make(chan *gomail.Message)
}
if nil == d.dialer && nil == d.sendFunc {
d.dialer = dialerPool.allocatePlain(d)
}
if d.lastErrs != nil {
return nil, d // because Daemon implements error interface
}
return d, nil
}
开发者ID:optimuse,项目名称:csfw,代码行数:29,代码来源:daemon.go
示例6: NewDaemon
// NewDaemon creates a new mail sending daemon to send to a SMTP server.
// Per default it uses localhost:25, creates an unbuffered channel, uses the
// config.DefaultManager, applies the admin scope (0) and sets the SMTP
// timeout to 30s.
func NewDaemon(opts ...DaemonOption) (*Daemon, error) {
d := &Daemon{
Config: config.DefaultManager,
ScopeID: config.ScopeID(0), // Default Scope aka Admin Scope
SmtpTimeout: time.Second * 30,
}
d.SetOptions(opts...)
if d.IsOffline() {
SetSendFunc(OfflineSend)(d)
}
if d.msgChan == nil {
d.msgChan = make(chan *gomail.Message)
}
if nil == d.sendFunc && nil == d.dialer {
d.lastErrs = append(d.lastErrs, errors.New("Missing a Dialer or SendFunc. Please set them via DaemonOption"))
}
if d.lastErrs != nil {
return nil, d // because Daemon implements error interface
}
return d, nil
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:29,代码来源:daemon.go
示例7: TestDaemonOfflineLogger
func TestDaemonOfflineLogger(t *testing.T) {
offLog := mail.OfflineLogger
defer func() {
mail.OfflineLogger = offLog
}()
var logBufI bytes.Buffer
var logBufE bytes.Buffer
mail.OfflineLogger = log.NewStdLogger(
log.SetStdLevel(log.StdLevelInfo),
log.SetStdInfo(&logBufI, "test", std.LstdFlags),
log.SetStdError(&logBufE, "test", std.LstdFlags),
)
dm, err := mail.NewDaemon()
dm.Config = configMock
dm.ScopeID = config.ScopeID(3001)
assert.NoError(t, err)
assert.NotNil(t, dm)
assert.True(t, dm.IsOffline())
go func() { assert.NoError(t, dm.Worker()) }()
assert.NoError(t, dm.SendPlain("[email protected]", "[email protected]", "Phoning home", "Hey Apple stop phoning home or you become apple puree"))
assert.NoError(t, dm.Stop())
assert.True(t, mail.OfflineLogger.IsInfo())
time.Sleep(time.Millisecond) // waiting for channel to drain
assert.Contains(t, logBufI.String(), `Send from: "[email protected]" to: []string{"[email protected]"} msg: "Mime-Version: 1.0`)
assert.Empty(t, logBufE.String())
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:33,代码来源:daemon_test.go
示例8: TestDaemonOffline
func TestDaemonOffline(t *testing.T) {
offSend := mail.OfflineSend
defer func() {
mail.OfflineSend = offSend
}()
mail.OfflineSend = func(from string, to []string, msg io.WriterTo) error {
var buf bytes.Buffer
_, err := msg.WriteTo(&buf)
assert.NoError(t, err)
assert.Equal(t, "[email protected]", from)
assert.Equal(t, []string{"[email protected]"}, to)
assert.Contains(t, buf.String(), "phoning home")
assert.Contains(t, buf.String(), "Subject: Phoning home")
return nil
}
dm, err := mail.NewDaemon()
dm.Config = configMock
dm.ScopeID = config.ScopeID(3001)
assert.NoError(t, err)
assert.NotNil(t, dm)
assert.True(t, dm.IsOffline())
go func() { assert.NoError(t, dm.Worker()) }()
assert.NoError(t, dm.SendPlain("[email protected]", "[email protected]", "Phoning home", "Hey Apple stop phoning home or you become apple puree"))
assert.NoError(t, dm.Stop())
assert.EqualError(t, dm.Worker(), mail.ErrMailChannelClosed.Error())
assert.EqualError(t, dm.Stop(), mail.ErrMailChannelClosed.Error())
assert.EqualError(t, dm.Send(nil), mail.ErrMailChannelClosed.Error())
assert.EqualError(t, dm.SendPlain("", "", "", ""), mail.ErrMailChannelClosed.Error())
assert.EqualError(t, dm.SendHtml("", "", "", ""), mail.ErrMailChannelClosed.Error())
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:35,代码来源:daemon_test.go
示例9: TestDaemonWorkerReDialCloseError
func TestDaemonWorkerReDialCloseError(t *testing.T) {
defer errLogBuf.Reset()
dm, err := mail.NewDaemon(
mail.SetConfig(configMock),
mail.SetScope(config.ScopeID(4010)),
mail.SetDialer(
mockDial{
t: t,
closeErr: errors.New("Test Close Error"),
},
),
)
assert.NoError(t, err)
assert.NotNil(t, dm)
assert.False(t, dm.IsOffline())
go func() {
assert.EqualError(t, dm.Worker(), "Test Close Error", "See goroutine")
}()
assert.NoError(t, dm.SendPlain("[email protected]", "[email protected]", "Spagetti", "Pastafari meets Rustafari"))
time.Sleep(time.Millisecond * 100)
assert.NoError(t, dm.Stop())
assert.Contains(t, errLogBuf.String(), "mail.daemon.workerDial.timeout.Close err: Test Close Error")
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:26,代码来源:daemon_test.go
示例10: TestNewManagerStore
func TestNewManagerStore(t *testing.T) {
assert.True(t, managerStoreSimpleTest.IsCacheEmpty())
for j := 0; j < 3; j++ {
s, err := managerStoreSimpleTest.Store(config.ScopeCode("notNil"))
assert.NoError(t, err)
assert.NotNil(t, s)
assert.EqualValues(t, "de", s.Data.Code.String)
}
assert.False(t, managerStoreSimpleTest.IsCacheEmpty())
managerStoreSimpleTest.ClearCache()
assert.True(t, managerStoreSimpleTest.IsCacheEmpty())
tests := []struct {
have config.ScopeIDer
wantErr error
}{
{config.ScopeCode("nilSlices"), store.ErrStoreNotFound},
{config.ScopeID(2), store.ErrStoreNotFound},
{nil, store.ErrAppStoreNotSet},
}
managerEmpty := getTestManager()
for _, test := range tests {
s, err := managerEmpty.Store(test.have)
assert.Nil(t, s)
assert.EqualError(t, test.wantErr, err.Error())
}
assert.True(t, managerStoreSimpleTest.IsCacheEmpty())
}
开发者ID:postfix,项目名称:csfw,代码行数:29,代码来源:manager_test.go
示例11: TestNewManagerReInit
func TestNewManagerReInit(t *testing.T) {
numCPU := runtime.NumCPU()
prevCPU := runtime.GOMAXPROCS(numCPU)
t.Logf("GOMAXPROCS was: %d now: %d", prevCPU, numCPU)
defer runtime.GOMAXPROCS(prevCPU)
// quick implement, use mock of dbr.SessionRunner and remove connection
db := csdb.MustConnectTest()
defer db.Close()
dbrSess := dbr.NewConnection(db, nil).NewSession(nil)
storeManager := store.NewManager(store.NewStorageOption(nil /* trick it*/))
if err := storeManager.ReInit(dbrSess); err != nil {
t.Fatal(err)
}
tests := []struct {
have config.ScopeIDer
wantErr error
}{
{config.ScopeCode("de"), nil},
{config.ScopeCode("cz"), store.ErrStoreNotFound},
{config.ScopeCode("de"), nil},
{config.ScopeID(1), nil},
{config.ScopeID(100), store.ErrStoreNotFound},
{mockIDCode{1, "de"}, nil},
{mockIDCode{2, "cz"}, store.ErrStoreNotFound},
{mockIDCode{2, ""}, nil},
{nil, store.ErrAppStoreNotSet}, // if set returns default store
}
for _, test := range tests {
s, err := storeManager.Store(test.have)
if test.wantErr == nil {
assert.NoError(t, err, "For test: %#v", test)
assert.NotNil(t, s)
// assert.NotEmpty(t, s.Data().Code.String, "%#v", s.Data())
} else {
assert.Error(t, err, "For test: %#v", test)
assert.EqualError(t, test.wantErr, err.Error(), "For test: %#v", test)
assert.Nil(t, s)
}
}
assert.False(t, storeManager.IsCacheEmpty())
storeManager.ClearCache()
assert.True(t, storeManager.IsCacheEmpty())
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:47,代码来源:manager_test.go
示例12: 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
示例13: TestNewManagerGetRequestStore_ScopeStore
func TestNewManagerGetRequestStore_ScopeStore(t *testing.T) {
testCode := config.ScopeCode("de")
testScope := config.ScopeStoreID
if haveStore, haveErr := storeManagerRequestStore.GetRequestStore(config.ScopeID(1), testScope); haveErr == nil {
t.Error("appStore should not be set!")
t.Fail()
} else {
assert.Nil(t, haveStore)
assert.EqualError(t, store.ErrAppStoreNotSet, haveErr.Error())
}
// init with scope store
if err := storeManagerRequestStore.Init(testCode, testScope); err != nil {
t.Error(err)
t.Fail()
}
assert.EqualError(t, store.ErrAppStoreSet, storeManagerRequestStore.Init(testCode, testScope).Error())
if s, err := storeManagerRequestStore.Store(); err == nil {
assert.EqualValues(t, "de", s.Data.Code.String)
} else {
assert.EqualError(t, err, store.ErrStoreNotFound.Error())
t.Fail()
}
tests := []testNewManagerGetRequestStore{
{config.ScopeID(232), "", store.ErrStoreNotFound},
{nil, "", store.ErrStoreNotFound},
{config.ScopeCode("\U0001f631"), "", store.ErrStoreNotFound},
{config.ScopeID(6), "nz", nil},
{config.ScopeCode("ch"), "", store.ErrStoreNotActive},
{config.ScopeCode("nz"), "nz", nil},
{config.ScopeCode("de"), "de", nil},
{config.ScopeID(2), "at", nil},
{config.ScopeID(2), "at", nil},
{config.ScopeCode("au"), "au", nil},
{config.ScopeCode("ch"), "", store.ErrStoreNotActive},
}
runNewManagerGetRequestStore(t, testScope, tests)
}
开发者ID:postfix,项目名称:csfw,代码行数:45,代码来源:manager_test.go
示例14: TestDialerPoolDefaultConfig
func TestDialerPoolDefaultConfig(t *testing.T) {
dm, err := NewDaemon(
SetConfig(configMock),
SetScope(config.ScopeID(5015)),
)
assert.NoError(t, err)
assert.NotNil(t, dm)
assert.Equal(t, uint64(0xcc72e0b18f4a60fb), dm.ID()) // "localhost25"
}
开发者ID:optimuse,项目名称:csfw,代码行数:9,代码来源:daemon_dialer_test.go
示例15: Store
// Store creates a new Store which contains the the store, its group and website
// according to the interface definition.
func (st *Storage) Store(r config.ScopeIDer) (*Store, error) {
s, err := st.store(r)
if err != nil {
return nil, errgo.Mask(err)
}
w, err := st.website(config.ScopeID(s.WebsiteID))
if err != nil {
return nil, errgo.Mask(err)
}
g, err := st.group(config.ScopeID(s.GroupID))
if err != nil {
return nil, errgo.Mask(err)
}
ns := NewStore(s, w, g, SetStoreConfig(st.cr))
ns.Website().SetGroupsStores(st.groups, st.stores)
ns.Group().SetStores(st.stores, w)
return ns, nil
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:20,代码来源:storage.go
示例16: Stores
// Stores creates a new store slice. Can return an error when the website or
// the group cannot be found.
func (st *Storage) Stores() (StoreSlice, error) {
stores := make(StoreSlice, len(st.stores), len(st.stores))
for i, s := range st.stores {
var err error
if stores[i], err = st.Store(config.ScopeID(s.StoreID)); err != nil {
return nil, errgo.Mask(err)
}
}
return stores, nil
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:12,代码来源:storage.go
示例17: TestStorageWebsite
func TestStorageWebsite(t *testing.T) {
tests := []struct {
have config.ScopeIDer
err error
wantWCode string
}{
{nil, store.ErrWebsiteNotFound, ""},
{config.ScopeID(2015), store.ErrWebsiteNotFound, ""},
{config.ScopeID(1), nil, "euro"},
{config.ScopeCode("asia"), store.ErrWebsiteNotFound, ""},
{config.ScopeCode("oz"), nil, "oz"},
{mockIDCode{1, "oz"}, nil, "oz"},
{mockIDCode{1, "ozzz"}, store.ErrWebsiteNotFound, ""},
}
for _, test := range tests {
w, err := testStorage.Website(test.have)
if test.err != nil {
assert.Nil(t, w)
assert.EqualError(t, test.err, err.Error())
} else {
assert.NotNil(t, w, "Test: %#v", test)
assert.NoError(t, err, "Test: %#v", test)
assert.Equal(t, test.wantWCode, w.Data().Code.String, "Test: %#v", test)
}
}
w, err := testStorage.Website(config.ScopeCode("euro"))
assert.NoError(t, err)
assert.NotNil(t, w)
dGroup, err := w.DefaultGroup()
assert.NoError(t, err)
assert.EqualValues(t, "DACH Group", dGroup.Data().Name)
groups, err := w.Groups()
assert.NoError(t, err)
assert.EqualValues(t, utils.Int64Slice{1, 2}, groups.IDs())
stores, err := w.Stores()
assert.NoError(t, err)
assert.EqualValues(t, utils.StringSlice{"de", "uk", "at", "ch"}, stores.Codes())
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:43,代码来源:storage_test.go
示例18: TestStorageStore
func TestStorageStore(t *testing.T) {
tests := []struct {
have config.ScopeIDer
err error
wantCode string
}{
{nil, store.ErrStoreNotFound, ""},
{config.ScopeID(2015), store.ErrStoreNotFound, ""},
{config.ScopeID(1), nil, "de"},
{config.ScopeCode("asia"), store.ErrStoreNotFound, ""},
{config.ScopeCode("nz"), nil, "nz"},
{mockIDCode{4, "nz"}, nil, "nz"},
{mockIDCode{4, "auuuuu"}, store.ErrStoreNotFound, ""},
}
for _, test := range tests {
s, err := testStorage.Store(test.have)
if test.err != nil {
assert.Nil(t, s, "%#v", test)
assert.EqualError(t, test.err, err.Error())
} else {
assert.NotNil(t, s, "%#v", test)
assert.NoError(t, err, "%#v", test)
assert.Equal(t, test.wantCode, s.Data().Code.String)
}
}
s, err := testStorage.Store(config.ScopeCode("at"))
assert.NoError(t, err)
assert.NotNil(t, s)
assert.EqualValues(t, "DACH Group", s.Group().Data().Name)
website := s.Website()
assert.EqualValues(t, "euro", website.Data().Code.String)
wg, err := website.DefaultGroup()
assert.NotNil(t, wg)
assert.EqualValues(t, "DACH Group", wg.Data().Name)
wgs, err := wg.DefaultStore()
assert.NoError(t, err)
assert.EqualValues(t, "at", wgs.Data().Code.String)
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:42,代码来源:storage_test.go
示例19: Groups
// Groups creates a new group slice containing its website all related stores.
// May panic when a website pointer is nil.
func (st *Storage) Groups() (GroupSlice, error) {
groups := make(GroupSlice, len(st.groups), len(st.groups))
for i, g := range st.groups {
w, err := st.website(config.ScopeID(g.WebsiteID))
if err != nil {
return nil, errgo.Mask(err)
}
groups[i] = NewGroup(g, SetGroupConfig(st.cr), SetGroupWebsite(w)).SetStores(st.stores, nil)
}
return groups, nil
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:13,代码来源:storage.go
示例20: TestNewManagerGetRequestStore_ScopeWebsite
func TestNewManagerGetRequestStore_ScopeWebsite(t *testing.T) {
testCode := config.ScopeID(1)
testScope := config.ScopeWebsiteID
if haveStore, haveErr := storeManagerRequestStore.GetRequestStore(config.ScopeID(1), testScope); haveErr == nil {
t.Error("appStore should not be set!")
t.Fail()
} else {
assert.Nil(t, haveStore)
assert.EqualError(t, store.ErrAppStoreNotSet, haveErr.Error())
}
assert.EqualError(t, store.ErrUnsupportedScopeGroup, storeManagerRequestStore.Init(config.ScopeID(123), config.ScopeDefaultID).Error())
assert.EqualError(t, store.ErrWebsiteNotFound, storeManagerRequestStore.Init(config.ScopeID(123), testScope).Error())
if err := storeManagerRequestStore.Init(testCode, testScope); err != nil {
t.Error(err)
t.Fail()
}
assert.EqualError(t, store.ErrAppStoreSet, storeManagerRequestStore.Init(testCode, testScope).Error())
if s, err := storeManagerRequestStore.Store(); err == nil {
assert.EqualValues(t, "at", s.Data.Code.String)
} else {
assert.EqualError(t, err, store.ErrStoreNotFound.Error())
t.Fail()
}
if w, err := storeManagerRequestStore.Website(); err == nil {
assert.EqualValues(t, "euro", w.Data.Code.String)
} else {
assert.EqualError(t, err, store.ErrStoreNotFound.Error())
t.Fail()
}
tests := []testNewManagerGetRequestStore{
{config.ScopeID(232), "", store.ErrStoreNotFound},
{nil, "", store.ErrStoreNotFound},
{config.ScopeCode("\U0001f631"), "", store.ErrStoreNotFound},
{config.ScopeID(6), "nz", store.ErrStoreChangeNotAllowed},
{config.ScopeCode("ch"), "", store.ErrStoreNotActive},
{config.ScopeCode("de"), "de", nil},
{config.ScopeID(2), "at", nil},
{config.ScopeID(2), "at", nil},
{config.ScopeCode("au"), "au", store.ErrStoreChangeNotAllowed},
{config.ScopeCode("ch"), "", store.ErrStoreNotActive},
}
runNewManagerGetRequestStore(t, testScope, tests)
}
开发者ID:postfix,项目名称:csfw,代码行数:51,代码来源:manager_test.go
注:本文中的github.com/corestoreio/csfw/config.ScopeID函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论