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

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/state/status_volume_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
package state_test
5
5
 
6
6
import (
7
 
        "time"
8
 
 
9
7
        jc "github.com/juju/testing/checkers"
10
8
        gc "gopkg.in/check.v1"
11
9
 
12
10
        "github.com/juju/juju/state"
13
11
        "github.com/juju/juju/status"
 
12
        "github.com/juju/juju/testing"
14
13
)
15
14
 
16
15
type VolumeStatusSuite struct {
53
52
func (s *VolumeStatusSuite) checkInitialStatus(c *gc.C) {
54
53
        statusInfo, err := s.volume.Status()
55
54
        c.Check(err, jc.ErrorIsNil)
56
 
        c.Check(statusInfo.Status, gc.Equals, status.StatusPending)
 
55
        c.Check(statusInfo.Status, gc.Equals, status.Pending)
57
56
        c.Check(statusInfo.Message, gc.Equals, "")
58
57
        c.Check(statusInfo.Data, gc.HasLen, 0)
59
58
        c.Check(statusInfo.Since, gc.NotNil)
60
59
}
61
60
 
62
61
func (s *VolumeStatusSuite) TestSetErrorStatusWithoutInfo(c *gc.C) {
63
 
        now := time.Now()
 
62
        now := testing.ZeroTime()
64
63
        sInfo := status.StatusInfo{
65
 
                Status:  status.StatusError,
 
64
                Status:  status.Error,
66
65
                Message: "",
67
66
                Since:   &now,
68
67
        }
73
72
}
74
73
 
75
74
func (s *VolumeStatusSuite) TestSetUnknownStatus(c *gc.C) {
76
 
        now := time.Now()
 
75
        now := testing.ZeroTime()
77
76
        sInfo := status.StatusInfo{
78
77
                Status:  status.Status("vliegkat"),
79
78
                Message: "orville",
86
85
}
87
86
 
88
87
func (s *VolumeStatusSuite) TestSetOverwritesData(c *gc.C) {
89
 
        now := time.Now()
 
88
        now := testing.ZeroTime()
90
89
        sInfo := status.StatusInfo{
91
 
                Status:  status.StatusAttaching,
 
90
                Status:  status.Attaching,
92
91
                Message: "blah",
93
92
                Data: map[string]interface{}{
94
93
                        "pew.pew": "zap",
98
97
        err := s.volume.SetStatus(sInfo)
99
98
        c.Check(err, jc.ErrorIsNil)
100
99
 
101
 
        s.checkGetSetStatus(c, status.StatusAttaching)
 
100
        s.checkGetSetStatus(c, status.Attaching)
102
101
}
103
102
 
104
103
func (s *VolumeStatusSuite) TestGetSetStatusAlive(c *gc.C) {
105
104
        validStatuses := []status.Status{
106
 
                status.StatusAttaching, status.StatusAttached, status.StatusDetaching,
107
 
                status.StatusDetached, status.StatusDestroying,
 
105
                status.Attaching, status.Attached, status.Detaching,
 
106
                status.Detached, status.Destroying,
108
107
        }
109
108
        for _, status := range validStatuses {
110
109
                s.checkGetSetStatus(c, status)
112
111
}
113
112
 
114
113
func (s *VolumeStatusSuite) checkGetSetStatus(c *gc.C, volumeStatus status.Status) {
115
 
        now := time.Now()
 
114
        now := testing.ZeroTime()
116
115
        sInfo := status.StatusInfo{
117
116
                Status:  volumeStatus,
118
117
                Message: "blah",
145
144
        err := s.State.DestroyVolume(s.volume.VolumeTag())
146
145
        c.Assert(err, jc.ErrorIsNil)
147
146
 
148
 
        s.checkGetSetStatus(c, status.StatusAttaching)
 
147
        s.checkGetSetStatus(c, status.Attaching)
149
148
}
150
149
 
151
150
func (s *VolumeStatusSuite) TestGetSetStatusDead(c *gc.C) {
163
162
        // NOTE: it would be more technically correct to reject status updates
164
163
        // while Dead, but it's easier and clearer, not to mention more efficient,
165
164
        // to just depend on status doc existence.
166
 
        s.checkGetSetStatus(c, status.StatusAttaching)
 
165
        s.checkGetSetStatus(c, status.Attaching)
167
166
}
168
167
 
169
168
func (s *VolumeStatusSuite) TestGetSetStatusGone(c *gc.C) {
170
169
        s.obliterateVolume(c, s.volume.VolumeTag())
171
170
 
172
 
        now := time.Now()
 
171
        now := testing.ZeroTime()
173
172
        sInfo := status.StatusInfo{
174
 
                Status:  status.StatusAttaching,
 
173
                Status:  status.Attaching,
175
174
                Message: "not really",
176
175
                Since:   &now,
177
176
        }
184
183
}
185
184
 
186
185
func (s *VolumeStatusSuite) TestSetStatusPendingUnprovisioned(c *gc.C) {
187
 
        now := time.Now()
 
186
        now := testing.ZeroTime()
188
187
        sInfo := status.StatusInfo{
189
 
                Status:  status.StatusPending,
 
188
                Status:  status.Pending,
190
189
                Message: "still",
191
190
                Since:   &now,
192
191
        }
199
198
                VolumeId: "vol-ume",
200
199
        })
201
200
        c.Assert(err, jc.ErrorIsNil)
202
 
        now := time.Now()
 
201
        now := testing.ZeroTime()
203
202
        sInfo := status.StatusInfo{
204
 
                Status:  status.StatusPending,
 
203
                Status:  status.Pending,
205
204
                Message: "",
206
205
                Since:   &now,
207
206
        }