...

Source file src/github.com/Shopify/go-storage/mock_fs.go

Documentation: github.com/Shopify/go-storage

     1  package storage
     2  
     3  import (
     4  	"context"
     5  	"io"
     6  
     7  	"github.com/stretchr/testify/mock"
     8  )
     9  
    10  // NewMockFS creates an FS where each method can be mocked.
    11  // To be used in tests.
    12  func NewMockFS() *MockFS {
    13  	return &MockFS{}
    14  }
    15  
    16  type MockFS struct {
    17  	mock.Mock
    18  }
    19  
    20  func (m *MockFS) Walk(ctx context.Context, path string, fn WalkFn) error {
    21  	args := m.Called(ctx, path, fn)
    22  
    23  	return args.Error(0)
    24  }
    25  
    26  func (m *MockFS) Open(ctx context.Context, path string, options *ReaderOptions) (*File, error) {
    27  	args := m.Called(ctx, path, options)
    28  	file := args.Get(0)
    29  	err := args.Error(1)
    30  	if file == nil {
    31  		return nil, err
    32  	}
    33  
    34  	return file.(*File), err
    35  }
    36  
    37  func (m *MockFS) Attributes(ctx context.Context, path string, options *ReaderOptions) (*Attributes, error) {
    38  	args := m.Called(ctx, path, options)
    39  	attrs := args.Get(0)
    40  	err := args.Error(1)
    41  	if attrs == nil {
    42  		return nil, err
    43  	}
    44  
    45  	return attrs.(*Attributes), err
    46  }
    47  
    48  func (m *MockFS) Create(ctx context.Context, path string, options *WriterOptions) (io.WriteCloser, error) {
    49  	args := m.Called(ctx, path, options)
    50  	w := args.Get(0)
    51  	err := args.Error(1)
    52  	if w == nil {
    53  		return nil, err
    54  	}
    55  
    56  	return w.(io.WriteCloser), err
    57  }
    58  
    59  func (m *MockFS) Delete(ctx context.Context, path string) error {
    60  	args := m.Called(ctx, path)
    61  
    62  	return args.Error(0)
    63  }
    64  
    65  func (m *MockFS) URL(ctx context.Context, path string, options *SignedURLOptions) (string, error) {
    66  	args := m.Called(ctx, path, options)
    67  	url := args.String(0)
    68  	err := args.Error(1)
    69  
    70  	return url, err
    71  }
    72  

View as plain text