gitea源码

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package nosql
  4. import (
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/require"
  8. )
  9. func TestToRedisURI(t *testing.T) {
  10. tests := []struct {
  11. name string
  12. connection string
  13. want string
  14. }{
  15. {
  16. name: "old_default",
  17. connection: "addrs=127.0.0.1:6379 db=0",
  18. want: "redis://127.0.0.1:6379/0",
  19. },
  20. {
  21. name: "old_macaron_session_default",
  22. connection: "network=tcp,addr=127.0.0.1:6379,password=macaron,db=0,pool_size=100,idle_timeout=180",
  23. want: "redis://:macaron@127.0.0.1:6379/0?idle_timeout=180s&pool_size=100",
  24. },
  25. }
  26. for _, tt := range tests {
  27. t.Run(tt.name, func(t *testing.T) {
  28. got := ToRedisURI(tt.connection)
  29. require.NotNil(t, got)
  30. assert.Equal(t, tt.want, got.String())
  31. })
  32. }
  33. }