...

Source file src/github.com/letsencrypt/boulder/ratelimits/source_redis_test.go

Documentation: github.com/letsencrypt/boulder/ratelimits

     1  package ratelimits
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/letsencrypt/boulder/cmd"
     7  	"github.com/letsencrypt/boulder/metrics"
     8  	"github.com/letsencrypt/boulder/test"
     9  	"golang.org/x/net/context"
    10  
    11  	"github.com/jmhodges/clock"
    12  	"github.com/redis/go-redis/v9"
    13  )
    14  
    15  func newTestRedisSource(clk clock.FakeClock, addrs map[string]string) *RedisSource {
    16  	CACertFile := "../test/redis-tls/minica.pem"
    17  	CertFile := "../test/redis-tls/boulder/cert.pem"
    18  	KeyFile := "../test/redis-tls/boulder/key.pem"
    19  	tlsConfig := cmd.TLSConfig{
    20  		CACertFile: CACertFile,
    21  		CertFile:   CertFile,
    22  		KeyFile:    KeyFile,
    23  	}
    24  	tlsConfig2, err := tlsConfig.Load(metrics.NoopRegisterer)
    25  	if err != nil {
    26  		panic(err)
    27  	}
    28  
    29  	client := redis.NewRing(&redis.RingOptions{
    30  		Addrs:     addrs,
    31  		Username:  "unittest-rw",
    32  		Password:  "824968fa490f4ecec1e52d5e34916bdb60d45f8d",
    33  		TLSConfig: tlsConfig2,
    34  	})
    35  	return NewRedisSource(client, clk, metrics.NoopRegisterer)
    36  }
    37  
    38  func newRedisTestLimiter(t *testing.T, clk clock.FakeClock) *Limiter {
    39  	return newTestLimiter(t, newTestRedisSource(clk, map[string]string{
    40  		"shard1": "10.33.33.4:4218",
    41  		"shard2": "10.33.33.5:4218",
    42  	}), clk)
    43  }
    44  
    45  func Test_RedisSource_Ping(t *testing.T) {
    46  	clk := clock.NewFake()
    47  	workingSource := newTestRedisSource(clk, map[string]string{
    48  		"shard1": "10.33.33.4:4218",
    49  		"shard2": "10.33.33.5:4218",
    50  	})
    51  
    52  	err := workingSource.Ping(context.Background())
    53  	test.AssertNotError(t, err, "Ping should not error")
    54  
    55  	missingFirstShardSource := newTestRedisSource(clk, map[string]string{
    56  		"shard1": "10.33.33.4:1337",
    57  		"shard2": "10.33.33.5:4218",
    58  	})
    59  
    60  	err = missingFirstShardSource.Ping(context.Background())
    61  	test.AssertError(t, err, "Ping should not error")
    62  
    63  	missingSecondShardSource := newTestRedisSource(clk, map[string]string{
    64  		"shard1": "10.33.33.4:4218",
    65  		"shard2": "10.33.33.5:1337",
    66  	})
    67  
    68  	err = missingSecondShardSource.Ping(context.Background())
    69  	test.AssertError(t, err, "Ping should not error")
    70  }
    71  

View as plain text