github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/nosql/manager_redis_test.go (about)

     1  // Copyright 2023 The GitBundle Inc. All rights reserved.
     2  // Copyright 2017 The Gitea Authors. All rights reserved.
     3  // Use of this source code is governed by a MIT-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package nosql
     7  
     8  import (
     9  	"net/url"
    10  	"testing"
    11  )
    12  
    13  func TestRedisUsernameOpt(t *testing.T) {
    14  	uri, _ := url.Parse("redis://redis:password@myredis/0")
    15  	opts := getRedisOptions(uri)
    16  
    17  	if opts.Username != "redis" {
    18  		t.Fail()
    19  	}
    20  }
    21  
    22  func TestRedisPasswordOpt(t *testing.T) {
    23  	uri, _ := url.Parse("redis://redis:password@myredis/0")
    24  	opts := getRedisOptions(uri)
    25  
    26  	if opts.Password != "password" {
    27  		t.Fail()
    28  	}
    29  }
    30  
    31  func TestRedisSentinelUsernameOpt(t *testing.T) {
    32  	uri, _ := url.Parse("redis+sentinel://redis:password@myredis/0?sentinelusername=suser&sentinelpassword=spass")
    33  	opts := getRedisOptions(uri).Failover()
    34  
    35  	if opts.SentinelUsername != "suser" {
    36  		t.Fail()
    37  	}
    38  }
    39  
    40  func TestRedisSentinelPasswordOpt(t *testing.T) {
    41  	uri, _ := url.Parse("redis+sentinel://redis:password@myredis/0?sentinelusername=suser&sentinelpassword=spass")
    42  	opts := getRedisOptions(uri).Failover()
    43  
    44  	if opts.SentinelPassword != "spass" {
    45  		t.Fail()
    46  	}
    47  }
    48  
    49  func TestRedisDatabaseIndexTcp(t *testing.T) {
    50  	uri, _ := url.Parse("redis://redis:password@myredis/12")
    51  	opts := getRedisOptions(uri)
    52  
    53  	if opts.DB != 12 {
    54  		t.Fail()
    55  	}
    56  }
    57  
    58  func TestRedisDatabaseIndexUnix(t *testing.T) {
    59  	uri, _ := url.Parse("redis+socket:///var/run/redis.sock?database=12")
    60  	opts := getRedisOptions(uri)
    61  
    62  	if opts.DB != 12 {
    63  		t.Fail()
    64  	}
    65  }