client_test.go 910 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package redisreceiver
  4. import (
  5. "os"
  6. "path/filepath"
  7. "runtime"
  8. "strings"
  9. "testing"
  10. "github.com/stretchr/testify/require"
  11. )
  12. var _ client = (*fakeClient)(nil)
  13. type fakeClient struct{}
  14. func newFakeClient() *fakeClient {
  15. return &fakeClient{}
  16. }
  17. func (c fakeClient) delimiter() string {
  18. if runtime.GOOS == "windows" {
  19. return "\r\n"
  20. }
  21. return "\n"
  22. }
  23. func (fakeClient) retrieveInfo() (string, error) {
  24. return readFile("info")
  25. }
  26. func (fakeClient) close() error {
  27. return nil
  28. }
  29. func readFile(fname string) (string, error) {
  30. file, err := os.ReadFile(filepath.Join("testdata", fname+".txt"))
  31. if err != nil {
  32. return "", err
  33. }
  34. return string(file), nil
  35. }
  36. func TestRetrieveInfo(t *testing.T) {
  37. g := fakeClient{}
  38. res, err := g.retrieveInfo()
  39. require.Nil(t, err)
  40. require.True(t, strings.HasPrefix(res, "# Server"))
  41. }