Path: blob/main/pkg/metrics/instance/configstore/mock.go
5363 views
package configstore12import (3"context"45"github.com/grafana/agent/pkg/metrics/instance"6)78// Mock is a Mock Store. Useful primarily for testing.9type Mock struct {10ListFunc func(ctx context.Context) ([]string, error)11GetFunc func(ctx context.Context, key string) (instance.Config, error)12PutFunc func(ctx context.Context, c instance.Config) (created bool, err error)13DeleteFunc func(ctx context.Context, key string) error14AllFunc func(ctx context.Context, keep func(key string) bool) (<-chan instance.Config, error)15WatchFunc func() <-chan WatchEvent16CloseFunc func() error17}1819// List implements Store.20func (s *Mock) List(ctx context.Context) ([]string, error) {21if s.ListFunc != nil {22return s.ListFunc(ctx)23}24panic("List not implemented")25}2627// Get implements Store.28func (s *Mock) Get(ctx context.Context, key string) (instance.Config, error) {29if s.GetFunc != nil {30return s.GetFunc(ctx, key)31}32panic("Get not implemented")33}3435// Put implements Store.36func (s *Mock) Put(ctx context.Context, c instance.Config) (created bool, err error) {37if s.PutFunc != nil {38return s.PutFunc(ctx, c)39}40panic("Put not implemented")41}4243// Delete implements Store.44func (s *Mock) Delete(ctx context.Context, key string) error {45if s.DeleteFunc != nil {46return s.DeleteFunc(ctx, key)47}48panic("Delete not implemented")49}5051// All implements Store.52func (s *Mock) All(ctx context.Context, keep func(key string) bool) (<-chan instance.Config, error) {53if s.AllFunc != nil {54return s.AllFunc(ctx, keep)55}56panic("All not implemented")57}5859// Watch implements Store.60func (s *Mock) Watch() <-chan WatchEvent {61if s.WatchFunc != nil {62return s.WatchFunc()63}64panic("Watch not implemented")65}6667// Close implements Store.68func (s *Mock) Close() error {69if s.CloseFunc != nil {70return s.CloseFunc()71}72panic("Close not implemented")73}747576