github.com/blend/go-sdk@v1.20220411.3/redis/main_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package redis_test
     9  
    10  import (
    11  	"context"
    12  
    13  	radix "github.com/mediocregopher/radix/v4"
    14  )
    15  
    16  // MockRadixClient implements radix.Client for testing.
    17  type MockRadixClient struct {
    18  	radix.Client
    19  	Ops chan radix.Action
    20  }
    21  
    22  // Do implements part of the radix client interface.
    23  func (mrc *MockRadixClient) Do(ctx context.Context, action radix.Action) error {
    24  	pushDone := make(chan struct{})
    25  	go func() {
    26  		defer close(pushDone)
    27  		mrc.Ops <- action
    28  	}()
    29  	select {
    30  	case <-ctx.Done():
    31  		return context.Canceled
    32  	case <-pushDone:
    33  		return nil
    34  	}
    35  }