github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/apiserver/facades/client/backups/create_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 jc "github.com/juju/testing/checkers" 8 gc "gopkg.in/check.v1" 9 "gopkg.in/mgo.v2" 10 11 "github.com/juju/juju/apiserver/facades/client/backups" 12 "github.com/juju/juju/apiserver/params" 13 ) 14 15 func (s *backupsSuite) TestCreateOkay(c *gc.C) { 16 s.PatchValue(backups.WaitUntilReady, 17 func(*mgo.Session, int) error { return nil }, 18 ) 19 s.setBackups(c, s.meta, "") 20 var args params.BackupsCreateArgs 21 result, err := s.api.Create(args) 22 c.Assert(err, jc.ErrorIsNil) 23 expected := backups.CreateResult(s.meta, "test-filename") 24 25 c.Check(result, gc.DeepEquals, expected) 26 } 27 28 func (s *backupsSuite) TestCreateNotes(c *gc.C) { 29 s.PatchValue(backups.WaitUntilReady, 30 func(*mgo.Session, int) error { return nil }, 31 ) 32 s.meta.Notes = "this backup is important" 33 s.setBackups(c, s.meta, "") 34 args := params.BackupsCreateArgs{ 35 Notes: "this backup is important", 36 } 37 38 result, err := s.api.Create(args) 39 c.Assert(err, jc.ErrorIsNil) 40 expected := backups.CreateResult(s.meta, "test-filename") 41 expected.Notes = "this backup is important" 42 43 c.Check(result, gc.DeepEquals, expected) 44 } 45 46 func (s *backupsSuite) TestCreateError(c *gc.C) { 47 s.setBackups(c, nil, "failed!") 48 s.PatchValue(backups.WaitUntilReady, 49 func(*mgo.Session, int) error { return nil }, 50 ) 51 var args params.BackupsCreateArgs 52 _, err := s.api.Create(args) 53 54 c.Logf("%v", err) 55 c.Check(err, gc.ErrorMatches, "failed!") 56 }