code.gitea.io/gitea@v1.19.3/modules/nosql/manager_redis_test.go (about) 1 // Copyright 2022 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package nosql 5 6 import ( 7 "net/url" 8 "testing" 9 ) 10 11 func TestRedisUsernameOpt(t *testing.T) { 12 uri, _ := url.Parse("redis://redis:password@myredis/0") 13 opts := getRedisOptions(uri) 14 15 if opts.Username != "redis" { 16 t.Fail() 17 } 18 } 19 20 func TestRedisPasswordOpt(t *testing.T) { 21 uri, _ := url.Parse("redis://redis:password@myredis/0") 22 opts := getRedisOptions(uri) 23 24 if opts.Password != "password" { 25 t.Fail() 26 } 27 } 28 29 func TestSkipVerifyOpt(t *testing.T) { 30 uri, _ := url.Parse("rediss://myredis/0?skipverify=true") 31 tlsConfig := getRedisTLSOptions(uri) 32 33 if !tlsConfig.InsecureSkipVerify { 34 t.Fail() 35 } 36 } 37 38 func TestInsecureSkipVerifyOpt(t *testing.T) { 39 uri, _ := url.Parse("rediss://myredis/0?insecureskipverify=true") 40 tlsConfig := getRedisTLSOptions(uri) 41 42 if !tlsConfig.InsecureSkipVerify { 43 t.Fail() 44 } 45 } 46 47 func TestRedisSentinelUsernameOpt(t *testing.T) { 48 uri, _ := url.Parse("redis+sentinel://redis:password@myredis/0?sentinelusername=suser&sentinelpassword=spass") 49 opts := getRedisOptions(uri).Failover() 50 51 if opts.SentinelUsername != "suser" { 52 t.Fail() 53 } 54 } 55 56 func TestRedisSentinelPasswordOpt(t *testing.T) { 57 uri, _ := url.Parse("redis+sentinel://redis:password@myredis/0?sentinelusername=suser&sentinelpassword=spass") 58 opts := getRedisOptions(uri).Failover() 59 60 if opts.SentinelPassword != "spass" { 61 t.Fail() 62 } 63 } 64 65 func TestRedisDatabaseIndexTcp(t *testing.T) { 66 uri, _ := url.Parse("redis://redis:password@myredis/12") 67 opts := getRedisOptions(uri) 68 69 if opts.DB != 12 { 70 t.Fail() 71 } 72 } 73 74 func TestRedisDatabaseIndexUnix(t *testing.T) { 75 uri, _ := url.Parse("redis+socket:///var/run/redis.sock?database=12") 76 opts := getRedisOptions(uri) 77 78 if opts.DB != 12 { 79 t.Fail() 80 } 81 }