1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
11
jc "github.com/juju/testing/checkers"
12
gc "gopkg.in/check.v1"
13
"gopkg.in/juju/names.v2"
15
"github.com/juju/juju/apiserver/params"
16
"github.com/juju/juju/cmd/juju/storage"
17
_ "github.com/juju/juju/provider/dummy"
18
"github.com/juju/juju/testing"
21
// epoch is the time we use for "since" in statuses. The time
22
// is always shown as a local time, so we override the local
23
// location to be UTC+8.
24
var epoch = time.Unix(0, 0)
26
type ShowSuite struct {
31
var _ = gc.Suite(&ShowSuite{})
33
func (s *ShowSuite) SetUpTest(c *gc.C) {
34
s.SubStorageSuite.SetUpTest(c)
36
s.mockAPI = &mockShowAPI{}
37
s.PatchValue(&time.Local, time.FixedZone("Australia/Perth", 3600*8))
40
func (s *ShowSuite) runShow(c *gc.C, args []string) (*cmd.Context, error) {
41
return testing.RunCommand(c, storage.NewShowCommandForTest(s.mockAPI, s.store), args...)
44
func (s *ShowSuite) TestShowNoMatch(c *gc.C) {
45
s.mockAPI.noMatch = true
55
func (s *ShowSuite) TestShow(c *gc.C) {
58
[]string{"shared-fs/0"},
59
// Default format is yaml
65
since: 01 Jan 1970 08:00:00\+08:00
79
func (s *ShowSuite) TestShowInvalidId(c *gc.C) {
80
_, err := s.runShow(c, []string{"foo"})
81
c.Assert(err, gc.ErrorMatches, ".*invalid storage id foo.*")
84
func (s *ShowSuite) TestShowJSON(c *gc.C) {
87
[]string{"shared-fs/0", "--format", "json"},
88
`{"shared-fs/0":{"kind":"filesystem","status":{"current":"attached","since":"01 Jan 1970 08:00:00\+08:00"},"persistent":true,"attachments":{"units":{"transcode/0":{"machine":"1","location":"a location"},"transcode/1":{"machine":"2","location":"b location"}}}}}
93
func (s *ShowSuite) TestShowMultipleReturn(c *gc.C) {
96
[]string{"shared-fs/0", "db-dir/1000"},
111
since: 01 Jan 1970 08:00:00\+08:00
125
func (s *ShowSuite) assertValidShow(c *gc.C, args []string, expected string) {
126
context, err := s.runShow(c, args)
127
c.Assert(err, jc.ErrorIsNil)
129
obtained := testing.Stdout(context)
130
c.Assert(obtained, gc.Matches, expected)
133
type mockShowAPI struct {
137
func (s mockShowAPI) Close() error {
141
func (s mockShowAPI) StorageDetails(tags []names.StorageTag) ([]params.StorageDetailsResult, error) {
145
all := make([]params.StorageDetailsResult, len(tags))
146
for i, tag := range tags {
147
if strings.Contains(tag.String(), "shared") {
148
all[i].Result = ¶ms.StorageDetails{
149
StorageTag: tag.String(),
150
OwnerTag: "application-transcode",
151
Kind: params.StorageKindFilesystem,
152
Status: params.EntityStatus{
157
Attachments: map[string]params.StorageAttachmentDetails{
158
"unit-transcode-0": params.StorageAttachmentDetails{
159
MachineTag: "machine-1",
160
Location: "a location",
162
"unit-transcode-1": params.StorageAttachmentDetails{
163
MachineTag: "machine-2",
164
Location: "b location",
169
all[i].Result = ¶ms.StorageDetails{
170
StorageTag: tag.String(),
171
Kind: params.StorageKindBlock,
172
Status: params.EntityStatus{
176
Attachments: map[string]params.StorageAttachmentDetails{
177
"unit-postgresql-0": params.StorageAttachmentDetails{},
181
all[i].Result.Persistent = true