-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools_test.go
81 lines (67 loc) · 1.94 KB
/
tools_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package state_test
import (
"fmt"
"github.com/juju/errors"
jc "github.com/juju/testing/checkers"
gc "launchpad.net/gocheck"
"github.com/juju/juju/state"
"github.com/juju/juju/tools"
"github.com/juju/juju/version"
)
type tooler interface {
AgentTools() (*tools.Tools, error)
SetAgentVersion(v version.Binary) error
Life() state.Life
Refresh() error
Destroy() error
EnsureDead() error
}
var _ = gc.Suite(&ToolsSuite{})
type ToolsSuite struct {
ConnSuite
}
func newTools(vers, url string) *tools.Tools {
return &tools.Tools{
Version: version.MustParseBinary(vers),
URL: url,
Size: 10,
SHA256: "1234",
}
}
func testAgentTools(c *gc.C, obj tooler, agent string) {
// object starts with zero'd tools.
t, err := obj.AgentTools()
c.Assert(t, gc.IsNil)
c.Assert(err, jc.Satisfies, errors.IsNotFound)
err = obj.SetAgentVersion(version.Binary{})
c.Assert(err, gc.ErrorMatches, fmt.Sprintf("cannot set agent version for %s: empty series or arch", agent))
v2 := version.MustParseBinary("7.8.9-foo-bar")
err = obj.SetAgentVersion(v2)
c.Assert(err, gc.IsNil)
t3, err := obj.AgentTools()
c.Assert(err, gc.IsNil)
c.Assert(t3.Version, gc.DeepEquals, v2)
err = obj.Refresh()
c.Assert(err, gc.IsNil)
t3, err = obj.AgentTools()
c.Assert(err, gc.IsNil)
c.Assert(t3.Version, gc.DeepEquals, v2)
testWhenDying(c, obj, noErr, deadErr, func() error {
return obj.SetAgentVersion(v2)
})
}
func (s *ToolsSuite) TestMachineAgentTools(c *gc.C) {
m, err := s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, gc.IsNil)
testAgentTools(c, m, "machine 0")
}
func (s *ToolsSuite) TestUnitAgentTools(c *gc.C) {
charm := s.AddTestingCharm(c, "dummy")
svc := s.AddTestingService(c, "wordpress", charm)
unit, err := svc.AddUnit()
c.Assert(err, gc.IsNil)
preventUnitDestroyRemove(c, unit)
testAgentTools(c, unit, `unit "wordpress/0"`)
}