github.com/jchengjr77/canaveral@v1.0.1-0.20200715160102-ea9245d1a2fb/nativestore/credentials_mock.go (about)

     1  package nativestore
     2  
     3  import (
     4  	"github.com/docker/docker-credential-helpers/credentials"
     5  )
     6  
     7  type mockstorage struct {
     8  	creds map[string]*credentials.Credentials
     9  }
    10  
    11  func newMockstorage() *mockstorage {
    12  	return &mockstorage{
    13  		creds: make(map[string]*credentials.Credentials),
    14  	}
    15  }
    16  
    17  func (m *mockstorage) Add(creds *credentials.Credentials) error {
    18  	m.creds[creds.ServerURL] = creds
    19  	return nil
    20  }
    21  
    22  func (m *mockstorage) Delete(serverURL string) error {
    23  	if _, found := m.creds[serverURL]; found {
    24  		delete(m.creds, serverURL)
    25  		return nil
    26  	}
    27  	return credentials.NewErrCredentialsNotFound()
    28  }
    29  
    30  func (m *mockstorage) Get(serverURL string) (string, string, error) {
    31  	cred, found := m.creds[serverURL]
    32  	if !found {
    33  		return "", "", credentials.NewErrCredentialsNotFound()
    34  	}
    35  	return cred.Username, cred.Secret, nil
    36  }
    37  
    38  var mockStore = newMockstorage()