mirror of
				https://github.com/redis/go-redis.git
				synced 2025-11-04 02:33:24 +03:00 
			
		
		
		
	Signed-off-by: fukua95 <fukua95@gmail.com> Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
		
			
				
	
	
		
			27 lines
		
	
	
		
			558 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			27 lines
		
	
	
		
			558 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package redis
 | 
						|
 | 
						|
import (
 | 
						|
	"context"
 | 
						|
)
 | 
						|
 | 
						|
// mockCmdable is a mock implementation of cmdable that records the last command.
 | 
						|
// This is used for unit testing command construction without requiring a Redis server.
 | 
						|
type mockCmdable struct {
 | 
						|
	lastCmd   Cmder
 | 
						|
	returnErr error
 | 
						|
}
 | 
						|
 | 
						|
func (m *mockCmdable) call(_ context.Context, cmd Cmder) error {
 | 
						|
	m.lastCmd = cmd
 | 
						|
	if m.returnErr != nil {
 | 
						|
		cmd.SetErr(m.returnErr)
 | 
						|
	}
 | 
						|
	return m.returnErr
 | 
						|
}
 | 
						|
 | 
						|
func (m *mockCmdable) asCmdable() cmdable {
 | 
						|
	return func(ctx context.Context, cmd Cmder) error {
 | 
						|
		return m.call(ctx, cmd)
 | 
						|
	}
 | 
						|
}
 |