...

Source file src/github.com/awslabs/amazon-ecr-credential-helper/ecr-login/mocks/ecr_mocks.go

Documentation: github.com/awslabs/amazon-ecr-credential-helper/ecr-login/mocks

     1  // Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"). You may
     4  // not use this file except in compliance with the License. A copy of the
     5  // License is located at
     6  //
     7  //     http://aws.amazon.com/apache2.0/
     8  //
     9  // or in the "license" file accompanying this file. This file is distributed
    10  // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
    11  // express or implied. See the License for the specific language governing
    12  // permissions and limitations under the License.
    13  
    14  package mock_api
    15  
    16  import (
    17  	"github.com/aws/aws-sdk-go-v2/aws"
    18  	"github.com/awslabs/amazon-ecr-credential-helper/ecr-login/api"
    19  )
    20  
    21  type MockClientFactory struct {
    22  	NewClientFn                 func(awsConfig aws.Config) api.Client
    23  	NewClientWithOptionsFn      func(opts api.Options) api.Client
    24  	NewClientFromRegionFn       func(region string) api.Client
    25  	NewClientWithFipsEndpointFn func(region string) (api.Client, error)
    26  	NewClientWithDefaultsFn     func() api.Client
    27  }
    28  
    29  func (m MockClientFactory) NewClient(awsConfig aws.Config) api.Client {
    30  	return m.NewClientFn(awsConfig)
    31  }
    32  
    33  func (m MockClientFactory) NewClientWithOptions(opts api.Options) api.Client {
    34  	return m.NewClientWithOptionsFn(opts)
    35  }
    36  
    37  func (m MockClientFactory) NewClientFromRegion(region string) api.Client {
    38  	return m.NewClientFromRegionFn(region)
    39  }
    40  
    41  func (m MockClientFactory) NewClientWithFipsEndpoint(region string) (api.Client, error) {
    42  	return m.NewClientWithFipsEndpointFn(region)
    43  }
    44  
    45  func (m MockClientFactory) NewClientWithDefaults() api.Client {
    46  	return m.NewClientWithDefaultsFn()
    47  }
    48  
    49  var _ api.ClientFactory = (*MockClientFactory)(nil)
    50  
    51  type MockClient struct {
    52  	GetCredentialsFn             func(serverURL string) (*api.Auth, error)
    53  	GetCredentialsByRegistryIDFn func(registryID string) (*api.Auth, error)
    54  	ListCredentialsFn            func() ([]*api.Auth, error)
    55  }
    56  
    57  var _ api.Client = (*MockClient)(nil)
    58  
    59  func (m *MockClient) GetCredentials(serverURL string) (*api.Auth, error) {
    60  	return m.GetCredentialsFn(serverURL)
    61  }
    62  
    63  func (m *MockClient) GetCredentialsByRegistryID(registryID string) (*api.Auth, error) {
    64  	return m.GetCredentialsByRegistryIDFn(registryID)
    65  }
    66  
    67  func (m *MockClient) ListCredentials() ([]*api.Auth, error) {
    68  	return m.ListCredentialsFn()
    69  }
    70  

View as plain text