...

Source file src/github.com/launchdarkly/go-server-sdk/v6/internal/sharedtest/mocks/mock_components.go

Documentation: github.com/launchdarkly/go-server-sdk/v6/internal/sharedtest/mocks

     1  package mocks
     2  
     3  import "github.com/launchdarkly/go-server-sdk/v6/subsystems"
     4  
     5  // SingleComponentConfigurer is a test implementation of ComponentConfigurer that always returns the same
     6  // pre-existing instance.
     7  type SingleComponentConfigurer[T any] struct {
     8  	Instance T
     9  }
    10  
    11  func (c SingleComponentConfigurer[T]) Build(clientContext subsystems.ClientContext) (T, error) {
    12  	return c.Instance, nil
    13  }
    14  
    15  // ComponentConfigurerThatReturnsError is a test implementation of ComponentConfigurer that always returns
    16  // an error.
    17  type ComponentConfigurerThatReturnsError[T any] struct {
    18  	Err error
    19  }
    20  
    21  func (c ComponentConfigurerThatReturnsError[T]) Build(clientContext subsystems.ClientContext) (T, error) {
    22  	var empty T
    23  	return empty, c.Err
    24  }
    25  
    26  // ComponentConfigurerThatCapturesClientContext is a test decorator for a ComponentConfigurer that allows
    27  // tests to see the ClientContext that was passed to it.
    28  type ComponentConfigurerThatCapturesClientContext[T any] struct {
    29  	Configurer            subsystems.ComponentConfigurer[T]
    30  	ReceivedClientContext subsystems.ClientContext
    31  }
    32  
    33  func (c *ComponentConfigurerThatCapturesClientContext[T]) Build(clientContext subsystems.ClientContext) (T, error) {
    34  	c.ReceivedClientContext = clientContext
    35  	return c.Configurer.Build(clientContext)
    36  }
    37  

View as plain text