github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/backups/download_test.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package backups_test 5 6 import ( 7 "github.com/juju/cmd" 8 "github.com/juju/errors" 9 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 12 "github.com/juju/juju/cmd/juju/backups" 13 "github.com/juju/juju/testing" 14 ) 15 16 type downloadSuite struct { 17 BaseBackupsSuite 18 wrappedCommand cmd.Command 19 command *backups.DownloadCommand 20 } 21 22 var _ = gc.Suite(&downloadSuite{}) 23 24 func (s *downloadSuite) SetUpTest(c *gc.C) { 25 s.BaseBackupsSuite.SetUpTest(c) 26 s.wrappedCommand, s.command = backups.NewDownloadCommandForTest() 27 } 28 29 func (s *downloadSuite) TearDownTest(c *gc.C) { 30 filename := s.command.ResolveFilename() 31 if s.command.Filename == "" { 32 filename = s.filename 33 } 34 35 if s.filename == "" { 36 s.filename = filename 37 } else { 38 c.Check(filename, gc.Equals, s.filename) 39 } 40 41 s.BaseBackupsSuite.TearDownTest(c) 42 } 43 44 func (s *downloadSuite) setSuccess() *fakeAPIClient { 45 client := s.BaseBackupsSuite.setDownload() 46 return client 47 } 48 49 func (s *downloadSuite) TestOkay(c *gc.C) { 50 s.setSuccess() 51 ctx, err := testing.RunCommand(c, s.wrappedCommand, s.metaresult.ID) 52 c.Check(err, jc.ErrorIsNil) 53 54 s.filename = "juju-backup-" + s.metaresult.ID + ".tar.gz" 55 s.checkStd(c, ctx, s.filename+"\n", "") 56 s.checkArchive(c) 57 } 58 59 func (s *downloadSuite) TestFilename(c *gc.C) { 60 s.setSuccess() 61 ctx, err := testing.RunCommand(c, s.wrappedCommand, s.metaresult.ID, "--filename", "backup.tar.gz") 62 c.Check(err, jc.ErrorIsNil) 63 64 s.filename = "backup.tar.gz" 65 s.checkStd(c, ctx, s.filename+"\n", "") 66 s.checkArchive(c) 67 } 68 69 func (s *downloadSuite) TestError(c *gc.C) { 70 s.setFailure("failed!") 71 _, err := testing.RunCommand(c, s.wrappedCommand, s.metaresult.ID) 72 c.Check(errors.Cause(err), gc.ErrorMatches, "failed!") 73 }