github.com/blend/go-sdk@v1.20220411.3/redis/radix_client_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  	"bytes"
    12  	"context"
    13  	"testing"
    14  	"time"
    15  
    16  	radix "github.com/mediocregopher/radix/v4"
    17  
    18  	"github.com/blend/go-sdk/assert"
    19  	"github.com/blend/go-sdk/logger"
    20  	"github.com/blend/go-sdk/redis"
    21  )
    22  
    23  func Test_RadixClient_Do(t *testing.T) {
    24  	its := assert.New(t)
    25  
    26  	buf := new(bytes.Buffer)
    27  	log := logger.Memory(buf)
    28  	defer log.Close()
    29  
    30  	logEvents := make(chan redis.Event)
    31  	log.Listen("test", "test", redis.NewEventListener(func(_ context.Context, e redis.Event) {
    32  		logEvents <- e
    33  	}))
    34  
    35  	mockRadixClient := &MockRadixClient{
    36  		Ops: make(chan radix.Action, 1),
    37  	}
    38  
    39  	rc := &redis.RadixClient{
    40  		Log:    log,
    41  		Client: mockRadixClient,
    42  	}
    43  
    44  	var foo string
    45  	its.Nil(rc.Do(context.TODO(), &foo, "GET", "foo"))
    46  }
    47  
    48  func Test_RadixClient_Do_timeout(t *testing.T) {
    49  	its := assert.New(t)
    50  
    51  	mockRadixClient := &MockRadixClient{
    52  		Ops: make(chan radix.Action),
    53  	}
    54  	rc := &redis.RadixClient{
    55  		Config: redis.Config{
    56  			Timeout: time.Millisecond,
    57  		},
    58  		Client: mockRadixClient,
    59  	}
    60  	var foo string
    61  	its.NotNil(rc.Do(context.Background(), &foo, "GET", "foo"))
    62  }