1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
7
"github.com/juju/errors"
8
jc "github.com/juju/testing/checkers"
11
"github.com/juju/juju/apiserver/params"
12
"github.com/juju/juju/state"
15
type filesystemSuite struct {
19
var _ = gc.Suite(&filesystemSuite{})
21
func (s *filesystemSuite) expectedFilesystemDetails() params.FilesystemDetails {
22
return params.FilesystemDetails{
23
FilesystemTag: s.filesystemTag.String(),
24
Status: params.EntityStatus{
27
MachineAttachments: map[string]params.FilesystemAttachmentInfo{
28
s.machineTag.String(): params.FilesystemAttachmentInfo{},
30
Storage: ¶ms.StorageDetails{
31
StorageTag: "storage-data-0",
32
OwnerTag: "unit-mysql-0",
33
Kind: params.StorageKindFilesystem,
34
Status: params.EntityStatus{
37
Attachments: map[string]params.StorageAttachmentDetails{
38
"unit-mysql-0": params.StorageAttachmentDetails{
39
StorageTag: "storage-data-0",
40
UnitTag: "unit-mysql-0",
41
MachineTag: "machine-66",
48
func (s *filesystemSuite) TestListFilesystemsEmptyFilter(c *gc.C) {
49
found, err := s.api.ListFilesystems(params.FilesystemFilters{
50
[]params.FilesystemFilter{{}},
52
c.Assert(err, jc.ErrorIsNil)
53
c.Assert(found.Results, gc.HasLen, 1)
54
c.Assert(found.Results[0].Result, gc.HasLen, 1)
55
c.Assert(found.Results[0].Result[0], gc.DeepEquals, s.expectedFilesystemDetails())
58
func (s *filesystemSuite) TestListFilesystemsError(c *gc.C) {
59
msg := "inventing error"
60
s.state.allFilesystems = func() ([]state.Filesystem, error) {
61
return nil, errors.New(msg)
63
results, err := s.api.ListFilesystems(params.FilesystemFilters{
64
[]params.FilesystemFilter{{}},
66
c.Assert(err, jc.ErrorIsNil)
67
c.Assert(results.Results, gc.HasLen, 1)
68
c.Assert(results.Results[0].Error, gc.ErrorMatches, msg)
71
func (s *filesystemSuite) TestListFilesystemsNoFilesystems(c *gc.C) {
72
s.state.allFilesystems = func() ([]state.Filesystem, error) {
75
results, err := s.api.ListFilesystems(params.FilesystemFilters{})
76
c.Assert(err, jc.ErrorIsNil)
77
c.Assert(results.Results, gc.HasLen, 0)
80
func (s *filesystemSuite) TestListFilesystemsFilter(c *gc.C) {
81
filters := []params.FilesystemFilter{{
82
Machines: []string{s.machineTag.String()},
84
found, err := s.api.ListFilesystems(params.FilesystemFilters{filters})
85
c.Assert(err, jc.ErrorIsNil)
86
c.Assert(found.Results, gc.HasLen, 1)
87
c.Assert(found.Results[0].Result, gc.HasLen, 1)
88
c.Assert(found.Results[0].Result[0], jc.DeepEquals, s.expectedFilesystemDetails())
91
func (s *filesystemSuite) TestListFilesystemsFilterNonMatching(c *gc.C) {
92
filters := []params.FilesystemFilter{{
93
Machines: []string{"machine-42"},
95
found, err := s.api.ListFilesystems(params.FilesystemFilters{filters})
96
c.Assert(err, jc.ErrorIsNil)
97
c.Assert(found.Results, gc.HasLen, 1)
98
c.Assert(found.Results[0].Error, gc.IsNil)
99
c.Assert(found.Results[0].Result, gc.HasLen, 0)
102
func (s *filesystemSuite) TestListFilesystemsFilesystemInfo(c *gc.C) {
103
s.filesystem.info = &state.FilesystemInfo{
106
expected := s.expectedFilesystemDetails()
107
expected.Info.Size = 123
108
found, err := s.api.ListFilesystems(params.FilesystemFilters{
109
[]params.FilesystemFilter{{}},
111
c.Assert(err, jc.ErrorIsNil)
112
c.Assert(found.Results, gc.HasLen, 1)
113
c.Assert(found.Results[0].Result, gc.HasLen, 1)
114
c.Assert(found.Results[0].Result[0], jc.DeepEquals, expected)
117
func (s *filesystemSuite) TestListFilesystemsAttachmentInfo(c *gc.C) {
118
s.filesystemAttachment.info = &state.FilesystemAttachmentInfo{
122
expected := s.expectedFilesystemDetails()
123
expected.MachineAttachments[s.machineTag.String()] = params.FilesystemAttachmentInfo{
127
expectedStorageAttachmentDetails := expected.Storage.Attachments["unit-mysql-0"]
128
expectedStorageAttachmentDetails.Location = "/tmp"
129
expected.Storage.Attachments["unit-mysql-0"] = expectedStorageAttachmentDetails
130
found, err := s.api.ListFilesystems(params.FilesystemFilters{
131
[]params.FilesystemFilter{{}},
133
c.Assert(err, jc.ErrorIsNil)
134
c.Assert(found.Results, gc.HasLen, 1)
135
c.Assert(found.Results[0].Result, gc.HasLen, 1)
136
c.Assert(found.Results[0].Result[0], jc.DeepEquals, expected)
139
func (s *filesystemSuite) TestListFilesystemsVolumeBacked(c *gc.C) {
140
s.filesystem.volume = &s.volumeTag
141
expected := s.expectedFilesystemDetails()
142
expected.VolumeTag = s.volumeTag.String()
143
found, err := s.api.ListFilesystems(params.FilesystemFilters{
144
[]params.FilesystemFilter{{}},
146
c.Assert(err, jc.ErrorIsNil)
147
c.Assert(found.Results, gc.HasLen, 1)
148
c.Assert(found.Results[0].Result, gc.HasLen, 1)
149
c.Assert(found.Results[0].Result[0], jc.DeepEquals, expected)