-
Notifications
You must be signed in to change notification settings - Fork 0
/
preupgradesteps_test.go
63 lines (52 loc) · 1.88 KB
/
preupgradesteps_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
// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package upgrades_test
import (
"os/exec"
"github.com/dustin/go-humanize"
pkgmgr "github.com/juju/packaging/manager"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/juju/testing"
"github.com/juju/juju/upgrades"
)
type preupgradechecksSuite struct {
testing.BaseSuite
}
var _ = gc.Suite(&preupgradechecksSuite{})
func (s *preupgradechecksSuite) TestCheckFreeDiskSpace(c *gc.C) {
// Expect an impossibly large amount of free disk.
s.PatchValue(&upgrades.MinDiskSpaceMib, uint64(humanize.PiByte/humanize.MiByte))
err := upgrades.PreUpgradeSteps(nil, &mockAgentConfig{dataDir: "/"}, false, false, false)
c.Assert(err, gc.ErrorMatches, `not enough free disk space on "/" for upgrade: .* available, require 1073741824MiB`)
}
func (s *preupgradechecksSuite) TestUpdateDistroInfo(c *gc.C) {
s.PatchValue(&upgrades.MinDiskSpaceMib, uint64(0))
expectedAptCommandArgs := [][]string{
{"update"},
{"install", "distro-info"},
}
commandChan := s.HookCommandOutput(&pkgmgr.CommandOutput, nil, nil)
err := upgrades.PreUpgradeSteps(nil, &mockAgentConfig{dataDir: "/"}, true, false, false)
c.Assert(err, jc.ErrorIsNil)
var commands []*exec.Cmd
for i := 0; i < cap(expectedAptCommandArgs)+1; i++ {
select {
case cmd := <-commandChan:
commands = append(commands, cmd)
default:
break
}
}
if len(commands) != len(expectedAptCommandArgs) {
c.Fatalf("expected %d commands, got %d", len(expectedAptCommandArgs), len(commands))
}
assertAptCommand := func(cmd *exec.Cmd, tailArgs ...string) {
args := cmd.Args
c.Assert(len(args), jc.GreaterThan, len(tailArgs))
c.Assert(args[0], gc.Equals, "apt-get")
c.Assert(args[len(args)-len(tailArgs):], gc.DeepEquals, tailArgs)
}
assertAptCommand(commands[0], "update")
assertAptCommand(commands[1], "install", "distro-info")
}