~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/resource/resourceadapters/fakes.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2016 Canonical Ltd.
2
 
// Licensed under the AGPLv3, see LICENCE file for details.
3
 
 
4
 
package resourceadapters
5
 
 
6
 
import (
7
 
        "io"
8
 
 
9
 
        "github.com/juju/errors"
10
 
        "gopkg.in/juju/charm.v6-unstable"
11
 
        charmresource "gopkg.in/juju/charm.v6-unstable/resource"
12
 
 
13
 
        "github.com/juju/juju/cmd/juju/charmcmd"
14
 
        "github.com/juju/juju/resource/charmstore"
15
 
        "github.com/juju/juju/resource/cmd"
16
 
)
17
 
 
18
 
// TODO(ericsnow) Get rid of fakeCharmStoreClient once csclient.Client grows the methods.
19
 
 
20
 
type baseCharmStoreClient interface {
21
 
        io.Closer
22
 
}
23
 
 
24
 
func newFakeCharmStoreClient(base baseCharmStoreClient) charmstore.Client {
25
 
        return &fakeCharmStoreClient{base}
26
 
}
27
 
 
28
 
type fakeCharmStoreClient struct {
29
 
        baseCharmStoreClient
30
 
}
31
 
 
32
 
// ListResources implements resource/charmstore.Client as a noop.
33
 
func (fakeCharmStoreClient) ListResources(charmURLs []*charm.URL) ([][]charmresource.Resource, error) {
34
 
        res := make([][]charmresource.Resource, len(charmURLs))
35
 
        return res, nil
36
 
}
37
 
 
38
 
// GetResource implements resource/charmstore.Client as a noop.
39
 
func (fakeCharmStoreClient) GetResource(cURL *charm.URL, resourceName string, revision int) (io.ReadCloser, error) {
40
 
        return nil, errors.NotFoundf("resource %q", resourceName)
41
 
}
42
 
 
43
 
// Close implements io.Closer.
44
 
func (client fakeCharmStoreClient) Close() error {
45
 
        if client.baseCharmStoreClient == nil {
46
 
                return nil
47
 
        }
48
 
        return client.baseCharmStoreClient.Close()
49
 
}
50
 
 
51
 
// TODO(ericsnow) Get rid of fakeCharmCmdBase once csclient.Client grows the methods.
52
 
 
53
 
type fakeCharmCmdBase struct {
54
 
        *charmcmd.CommandBase
55
 
}
56
 
 
57
 
func NewFakeCharmCmdBase(base *charmcmd.CommandBase) cmd.CharmCommandBase {
58
 
        return &fakeCharmCmdBase{base}
59
 
}
60
 
 
61
 
// Connect implements cmd.CommandBase.
62
 
func (c *fakeCharmCmdBase) Connect() (cmd.CharmResourceLister, error) {
63
 
        client, err := c.CommandBase.Connect()
64
 
        if err != nil {
65
 
                return nil, errors.Trace(err)
66
 
        }
67
 
        return newFakeCharmStoreClient(client), nil
68
 
}