github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/apiserver/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/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.ResultFromMetadata(s.meta)
    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  	result, err := s.api.Create(args)
    38  	c.Assert(err, jc.ErrorIsNil)
    39  	expected := backups.ResultFromMetadata(s.meta)
    40  	expected.Notes = "this backup is important"
    41  
    42  	c.Check(result, gc.DeepEquals, expected)
    43  }
    44  
    45  func (s *backupsSuite) TestCreateError(c *gc.C) {
    46  	s.setBackups(c, nil, "failed!")
    47  	s.PatchValue(backups.WaitUntilReady,
    48  		func(*mgo.Session, int) error { return nil },
    49  	)
    50  	var args params.BackupsCreateArgs
    51  	_, err := s.api.Create(args)
    52  
    53  	c.Logf("%v", err)
    54  	c.Check(err, gc.ErrorMatches, "failed!")
    55  }