client_mock_test.go 755 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package memcachedreceiver
  4. import (
  5. "encoding/json"
  6. "net"
  7. "os"
  8. "github.com/grobie/gomemcache/memcache"
  9. )
  10. type fakeClient struct{}
  11. var _ client = (*fakeClient)(nil)
  12. func (c *fakeClient) Stats() (map[net.Addr]memcache.Stats, error) {
  13. bytes, err := os.ReadFile("./testdata/fake_stats.json")
  14. if err != nil {
  15. return nil, err
  16. }
  17. stats := make(map[net.Addr]memcache.Stats)
  18. statsJSON := make(map[string]memcache.Stats)
  19. err = json.Unmarshal(bytes, &statsJSON)
  20. if err != nil {
  21. return nil, err
  22. }
  23. for addr, s := range statsJSON {
  24. tcpaddr, err := net.ResolveTCPAddr("tcp", addr)
  25. if err != nil {
  26. return nil, err
  27. }
  28. stats[tcpaddr] = s
  29. }
  30. return stats, nil
  31. }