github.com/fastly/cli@v1.7.2-0.20240304164155-9d0f1d77c3bf/pkg/mock/config_file.go (about)

     1  package mock
     2  
     3  // ConfigFile is a mock implementation of the toml.ReadWriter interface that's
     4  // used for testing.
     5  type ConfigFile struct {
     6  	PathFn   func() string
     7  	ExistsFn func() bool
     8  	ReadFn   func(c any) error
     9  	WriteFn  func(c any) error
    10  }
    11  
    12  // Path satisfies the toml.ReadWriter interface for testing purposes.
    13  func (c *ConfigFile) Path() string {
    14  	return c.PathFn()
    15  }
    16  
    17  // Exists satisfies the toml.ReadWriter interface for testing purposes.
    18  func (c *ConfigFile) Exists() bool {
    19  	return c.ExistsFn()
    20  }
    21  
    22  // Read satisfies the toml.ReadWriter interface for testing purposes.
    23  func (c *ConfigFile) Read(config any) error {
    24  	return c.ReadFn(config)
    25  }
    26  
    27  // Write satisfies the toml.ReadWriter interface for testing purposes.
    28  func (c *ConfigFile) Write(config any) error {
    29  	return c.WriteFn(config)
    30  }
    31  
    32  // NewNonExistentConfigFile is a test helper function which constructs a new
    33  // non-existent config file interface.
    34  func NewNonExistentConfigFile() *ConfigFile {
    35  	return &ConfigFile{
    36  		PathFn: func() string {
    37  			return ""
    38  		},
    39  		ExistsFn: func() bool {
    40  			return false
    41  		},
    42  	}
    43  }