github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/nosql/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 "testing" 10 ) 11 12 func TestToRedisURI(t *testing.T) { 13 tests := []struct { 14 name string 15 connection string 16 want string 17 }{ 18 { 19 name: "old_default", 20 connection: "addrs=127.0.0.1:6379 db=0", 21 want: "redis://127.0.0.1:6379/0", 22 }, 23 { 24 name: "old_macaron_session_default", 25 connection: "network=tcp,addr=127.0.0.1:6379,password=macaron,db=0,pool_size=100,idle_timeout=180", 26 want: "redis://:macaron@127.0.0.1:6379/0?idle_timeout=180s&pool_size=100", 27 }, 28 } 29 for _, tt := range tests { 30 t.Run(tt.name, func(t *testing.T) { 31 if got := ToRedisURI(tt.connection); got == nil || got.String() != tt.want { 32 t.Errorf(`ToRedisURI(%q) = %s, want %s`, tt.connection, got.String(), tt.want) 33 } 34 }) 35 } 36 }