allow register mock
This commit is contained in:
		
							parent
							
								
									641a791265
								
							
						
					
					
						commit
						452dae86be
					
				| @ -1,5 +1,5 @@ | |||||||
| # developing | # developing | ||||||
| - Web mock and test support. [4565](https://github.com/beego/beego/pull/4565) | - Web mock and test support. [4565](https://github.com/beego/beego/pull/4565) [4574](https://github.com/beego/beego/pull/4574) | ||||||
| - Error codes definition of cache module. [4493](https://github.com/beego/beego/pull/4493) | - Error codes definition of cache module. [4493](https://github.com/beego/beego/pull/4493) | ||||||
| - Remove generateCommentRoute http hook. Using `bee generate routers` commands instead.[4486](https://github.com/beego/beego/pull/4486) [bee PR 762](https://github.com/beego/bee/pull/762) | - Remove generateCommentRoute http hook. Using `bee generate routers` commands instead.[4486](https://github.com/beego/beego/pull/4486) [bee PR 762](https://github.com/beego/bee/pull/762) | ||||||
| - Fix: /abc.html/aaa match /abc/aaa. [4459](https://github.com/beego/beego/pull/4459) | - Fix: /abc.html/aaa match /abc/aaa. [4459](https://github.com/beego/beego/pull/4459) | ||||||
|  | |||||||
| @ -521,7 +521,7 @@ func init() { | |||||||
| 
 | 
 | ||||||
| 	err := InitGlobalInstance("ini", "conf/app.conf") | 	err := InitGlobalInstance("ini", "conf/app.conf") | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		logs.Warn("init global config instance failed. If you donot use this, just ignore it. ", err) | 		logs.Debug("init global config instance failed. If you donot use this, just ignore it. ", err) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -54,7 +54,7 @@ func (c *TestController) HelloSession() { | |||||||
| 		c.Ctx.WriteString("error") | 		c.Ctx.WriteString("error") | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	c.SetSession("name", "Tom") | 	_ = c.SetSession("name", "Tom") | ||||||
| 	c.Ctx.WriteString("set") | 	c.Ctx.WriteString("set") | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -77,6 +77,7 @@ func (s *SessionProvider) SessionAll(ctx context.Context) int { | |||||||
| 
 | 
 | ||||||
| // SessionGC do nothing | // SessionGC do nothing | ||||||
| func (s *SessionProvider) SessionGC(ctx context.Context) { | func (s *SessionProvider) SessionGC(ctx context.Context) { | ||||||
|  | 	// we do anything since we don't need to mock GC | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -105,6 +106,7 @@ func (s *SessionStore) SessionID(ctx context.Context) string { | |||||||
| 
 | 
 | ||||||
| // SessionRelease do nothing | // SessionRelease do nothing | ||||||
| func (s *SessionStore) SessionRelease(ctx context.Context, w http.ResponseWriter) { | func (s *SessionStore) SessionRelease(ctx context.Context, w http.ResponseWriter) { | ||||||
|  | 	// Support in the future if necessary, now I think we don't need to implement this | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *SessionStore) Flush(ctx context.Context) error { | func (s *SessionStore) Flush(ctx context.Context) error { | ||||||
|  | |||||||
| @ -70,15 +70,11 @@ var provides = make(map[string]Provider) | |||||||
| var SLogger = NewSessionLog(os.Stderr) | var SLogger = NewSessionLog(os.Stderr) | ||||||
| 
 | 
 | ||||||
| // Register makes a session provide available by the provided name. | // Register makes a session provide available by the provided name. | ||||||
| // If Register is called twice with the same name or if driver is nil, | // If provider is nil, it panic | ||||||
| // it panics. |  | ||||||
| func Register(name string, provide Provider) { | func Register(name string, provide Provider) { | ||||||
| 	if provide == nil { | 	if provide == nil { | ||||||
| 		panic("session: Register provide is nil") | 		panic("session: Register provide is nil") | ||||||
| 	} | 	} | ||||||
| 	if _, dup := provides[name]; dup { |  | ||||||
| 		panic("session: Register called twice for provider " + name) |  | ||||||
| 	} |  | ||||||
| 	provides[name] = provide | 	provides[name] = provide | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user