func getTestManager(opts ...func(ms *mockStorage)) *store.Manager { ms := &mockStorage{} for _, opt := range opts { opt(ms) } return store.NewManager(store.SetManagerStorage(ms)) }
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()) }
func TestNewManagerReInit(t *testing.T) { t.Skip(TODO_Better_Test_Data) // quick implement, use mock of dbr.SessionRunner and remove connection dbc := csdb.MustConnectTest() defer dbc.Close() dbrSess := dbc.NewSession() storeManager := store.NewManager(store.NewStorage(nil /* trick it*/)) if err := storeManager.ReInit(dbrSess); err != nil { t.Fatal(err) } tests := []struct { have scope.StoreIDer wantErr error }{ {scope.MockCode("dede"), nil}, {scope.MockCode("czcz"), store.ErrIDNotFoundTableStoreSlice}, {scope.MockID(1), nil}, {scope.MockID(100), store.ErrStoreNotFound}, {mockIDCode{1, "dede"}, nil}, {mockIDCode{2, "czfr"}, 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, "No Err; for test: %#v", test) assert.NotNil(t, s) // assert.NotEmpty(t, s.Data.Code.String, "%#v", s.Data) } else { assert.Error(t, err, "Err for test: %#v", test) assert.EqualError(t, test.wantErr, err.Error(), "EqualErr for test: %#v", test) assert.Nil(t, s) } } assert.False(t, storeManager.IsCacheEmpty()) storeManager.ClearCache() assert.True(t, storeManager.IsCacheEmpty()) }
err := getTestManager().Init(config.ScopeCode("euro"), config.ScopeDefaultID) assert.EqualError(t, err, store.ErrUnsupportedScopeGroup.Error()) } var storeManagerRequestStore = store.NewManager( store.NewStorageOption( store.SetStorageWebsites( &store.TableWebsite{WebsiteID: 0, Code: dbr.NullString{NullString: sql.NullString{String: "admin", Valid: true}}, Name: dbr.NullString{NullString: sql.NullString{String: "Admin", Valid: true}}, SortOrder: 0, DefaultGroupID: 0, IsDefault: dbr.NullBool{NullBool: sql.NullBool{Bool: false, Valid: 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.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}}}, ), store.SetStorageGroups( &store.TableGroup{GroupID: 3, WebsiteID: 2, Name: "Australia", RootCategoryID: 2, DefaultStoreID: 5}, &store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2}, &store.TableGroup{GroupID: 0, WebsiteID: 0, Name: "Default", RootCategoryID: 0, DefaultStoreID: 0}, &store.TableGroup{GroupID: 2, WebsiteID: 1, Name: "UK Group", RootCategoryID: 2, DefaultStoreID: 4}, ), store.SetStorageStores( &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{IsActive: false, StoreID: 3, Code: dbr.NullString{NullString: sql.NullString{String: "ch", Valid: true}}, WebsiteID: 1, GroupID: 1, Name: "Schweiz", SortOrder: 30}, ), ), ) type testNewManagerGetRequestStore struct { haveR config.ScopeIDer wantStoreCode string