github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/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  	"github.com/juju/mgo/v3"
     8  	jc "github.com/juju/testing/checkers"
     9  	gc "gopkg.in/check.v1"
    10  
    11  	"github.com/juju/juju/apiserver/facades/client/backups"
    12  	"github.com/juju/juju/rpc/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  }
    57  
    58  func (s *backupsSuite) TestCreateController(c *gc.C) {
    59  	s.PatchValue(backups.WaitUntilReady,
    60  		func(*mgo.Session, int) error { return nil },
    61  	)
    62  	s.meta.Controller.UUID = "controller-uuid"
    63  	s.meta.Controller.MachineID = "11"
    64  	s.meta.Controller.MachineInstanceID = "instance-12"
    65  	s.meta.Controller.HANodes = int64(3)
    66  	s.setBackups(c, s.meta, "")
    67  
    68  	result, err := s.api.Create(params.BackupsCreateArgs{})
    69  	c.Assert(err, jc.ErrorIsNil)
    70  	expected := backups.CreateResult(s.meta, "test-filename")
    71  	c.Check(result, gc.DeepEquals, expected)
    72  }