github.com/xmidt-org/webpa-common@v1.11.9/secure/key/mocks.go (about)

     1  package key
     2  
     3  import (
     4  	"github.com/stretchr/testify/mock"
     5  )
     6  
     7  // MockResolver is a stretchr mock for Resolver.  It's exposed for other package tests.
     8  type MockResolver struct {
     9  	mock.Mock
    10  }
    11  
    12  func (resolver *MockResolver) ResolveKey(keyId string) (Pair, error) {
    13  	arguments := resolver.Called(keyId)
    14  	if pair, ok := arguments.Get(0).(Pair); ok {
    15  		return pair, arguments.Error(1)
    16  	} else {
    17  		return nil, arguments.Error(1)
    18  	}
    19  }
    20  
    21  // MockCache is a stretchr mock for Cache.  It's exposed for other package tests.
    22  type MockCache struct {
    23  	mock.Mock
    24  }
    25  
    26  func (cache *MockCache) ResolveKey(keyId string) (Pair, error) {
    27  	arguments := cache.Called(keyId)
    28  	if pair, ok := arguments.Get(0).(Pair); ok {
    29  		return pair, arguments.Error(1)
    30  	} else {
    31  		return nil, arguments.Error(1)
    32  	}
    33  }
    34  
    35  func (cache *MockCache) UpdateKeys() (int, []error) {
    36  	arguments := cache.Called()
    37  	if errors, ok := arguments.Get(1).([]error); ok {
    38  		return arguments.Int(0), errors
    39  	} else {
    40  		return arguments.Int(0), nil
    41  	}
    42  }
    43  
    44  // MockPair is a stretchr mock for Pair.  It's exposed for other package tests.
    45  type MockPair struct {
    46  	mock.Mock
    47  }
    48  
    49  func (pair *MockPair) Purpose() Purpose {
    50  	arguments := pair.Called()
    51  	return arguments.Get(0).(Purpose)
    52  }
    53  
    54  func (pair *MockPair) Public() interface{} {
    55  	arguments := pair.Called()
    56  	return arguments.Get(0)
    57  }
    58  
    59  func (pair *MockPair) HasPrivate() bool {
    60  	arguments := pair.Called()
    61  	return arguments.Bool(0)
    62  }
    63  
    64  func (pair *MockPair) Private() interface{} {
    65  	arguments := pair.Called()
    66  	return arguments.Get(0)
    67  }
    68  
    69  type MockParser struct {
    70  	mock.Mock
    71  }
    72  
    73  func (parser *MockParser) ParseKey(purpose Purpose, data []byte) (Pair, error) {
    74  	arguments := parser.Called(purpose, data)
    75  	if pair, ok := arguments.Get(0).(Pair); ok {
    76  		return pair, arguments.Error(1)
    77  	}
    78  
    79  	return nil, arguments.Error(1)
    80  }