github.com/mwhudson/juju@v0.0.0-20160512215208-90ff01f3497f/upgrades/preupgradesteps_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package upgrades_test 5 6 import ( 7 "os/exec" 8 9 "github.com/dustin/go-humanize" 10 jc "github.com/juju/testing/checkers" 11 pkgmgr "github.com/juju/utils/packaging/manager" 12 gc "gopkg.in/check.v1" 13 14 "github.com/juju/juju/testing" 15 "github.com/juju/juju/upgrades" 16 ) 17 18 type preupgradechecksSuite struct { 19 testing.BaseSuite 20 } 21 22 var _ = gc.Suite(&preupgradechecksSuite{}) 23 24 func (s *preupgradechecksSuite) TestCheckFreeDiskSpace(c *gc.C) { 25 // Expect an impossibly large amount of free disk. 26 s.PatchValue(&upgrades.MinDiskSpaceMib, uint64(humanize.PiByte/humanize.MiByte)) 27 err := upgrades.PreUpgradeSteps(nil, &mockAgentConfig{dataDir: "/"}, false, false) 28 c.Assert(err, gc.ErrorMatches, "not enough free disk space for upgrade: .*") 29 } 30 31 func (s *preupgradechecksSuite) TestUpdateDistroInfo(c *gc.C) { 32 s.PatchValue(&upgrades.MinDiskSpaceMib, uint64(0)) 33 expectedAptCommandArgs := [][]string{ 34 {"update"}, 35 {"install", "distro-info"}, 36 } 37 38 commandChan := s.HookCommandOutput(&pkgmgr.CommandOutput, nil, nil) 39 err := upgrades.PreUpgradeSteps(nil, &mockAgentConfig{dataDir: "/"}, true, false) 40 c.Assert(err, jc.ErrorIsNil) 41 42 var commands []*exec.Cmd 43 for i := 0; i < cap(expectedAptCommandArgs)+1; i++ { 44 select { 45 case cmd := <-commandChan: 46 commands = append(commands, cmd) 47 default: 48 break 49 } 50 } 51 if len(commands) != len(expectedAptCommandArgs) { 52 c.Fatalf("expected %d commands, got %d", len(expectedAptCommandArgs), len(commands)) 53 } 54 55 assertAptCommand := func(cmd *exec.Cmd, tailArgs ...string) { 56 args := cmd.Args 57 c.Assert(len(args), jc.GreaterThan, len(tailArgs)) 58 c.Assert(args[0], gc.Equals, "apt-get") 59 c.Assert(args[len(args)-len(tailArgs):], gc.DeepEquals, tailArgs) 60 } 61 assertAptCommand(commands[0], "update") 62 assertAptCommand(commands[1], "install", "distro-info") 63 }