github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/resource/cmd/stub_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package cmd
     5  
     6  import (
     7  	"io"
     8  
     9  	"github.com/juju/errors"
    10  	"github.com/juju/juju/charmstore"
    11  	"github.com/juju/testing"
    12  	charmresource "gopkg.in/juju/charm.v6-unstable/resource"
    13  )
    14  
    15  type stubCharmStore struct {
    16  	stub *testing.Stub
    17  
    18  	ReturnListResources [][]charmresource.Resource
    19  }
    20  
    21  func (s *stubCharmStore) ListResources(charms []charmstore.CharmID) ([][]charmresource.Resource, error) {
    22  	s.stub.AddCall("ListResources", charms)
    23  	if err := s.stub.NextErr(); err != nil {
    24  		return nil, errors.Trace(err)
    25  	}
    26  
    27  	return s.ReturnListResources, nil
    28  }
    29  
    30  type stubAPIClient struct {
    31  	stub *testing.Stub
    32  }
    33  
    34  func (s *stubAPIClient) Upload(service, name, filename string, resource io.ReadSeeker) error {
    35  	s.stub.AddCall("Upload", service, name, filename, resource)
    36  	if err := s.stub.NextErr(); err != nil {
    37  		return errors.Trace(err)
    38  	}
    39  
    40  	return nil
    41  }
    42  
    43  func (s *stubAPIClient) Close() error {
    44  	s.stub.AddCall("Close")
    45  	if err := s.stub.NextErr(); err != nil {
    46  		return errors.Trace(err)
    47  	}
    48  
    49  	return nil
    50  }
    51  
    52  type stubFile struct {
    53  	// No one actually tries to read from this during tests.
    54  	io.ReadSeeker
    55  	stub *testing.Stub
    56  }
    57  
    58  func (s *stubFile) Close() error {
    59  	s.stub.AddCall("FileClose")
    60  	return errors.Trace(s.stub.NextErr())
    61  }