github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/api/backups/restore_test.go (about) 1 // Copyright 2018 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package backups_test 5 6 import ( 7 gc "gopkg.in/check.v1" 8 9 "github.com/golang/mock/gomock" 10 "github.com/juju/juju/api/backups" 11 12 "github.com/juju/juju/api/base/mocks" 13 "github.com/juju/juju/apiserver/params" 14 ) 15 16 type restoreSuite struct { 17 } 18 19 var _ = gc.Suite(&restoreSuite{}) 20 21 func (s *restoreSuite) TestRestoreFromFileBackupExistsOnController(c *gc.C) { 22 mockController := gomock.NewController(c) 23 mockBackupFacadeCaller := mocks.NewMockFacadeCaller(mockController) 24 mockBackupClientFacade := mocks.NewMockClientFacade(mockController) 25 mockBackupClientFacade.EXPECT().Close().AnyTimes() 26 27 // testBackupResults represents the parameters passed in by the client. 28 testBackupResults := params.BackupsMetadataResult{ 29 Checksum: "testCheckSum", 30 } 31 32 // This listBackupResults represents what is passed back from server. 33 testBackupsListResults := params.BackupsListResult{ 34 List: []params.BackupsMetadataResult{testBackupResults}, 35 } 36 37 // resultBackupList is an out param 38 resultBackupList := ¶ms.BackupsListResult{} 39 args := params.BackupsListArgs{} 40 41 // Upload should never be called. If it is the test will fail. 42 gomock.InOrder( 43 mockBackupFacadeCaller.EXPECT().FacadeCall("PrepareRestore", nil, gomock.Any()), 44 mockBackupFacadeCaller.EXPECT().FacadeCall("List", args, resultBackupList).SetArg(2, testBackupsListResults), 45 mockBackupFacadeCaller.EXPECT().FacadeCall("Restore", gomock.Any(), gomock.Any()).Times(1), 46 mockBackupFacadeCaller.EXPECT().FacadeCall("FinishRestore", gomock.Any(), gomock.Any()).Times(1), 47 ) 48 49 connFunc := func() (*backups.Client, error) { 50 return backups.MakeClient(mockBackupClientFacade, mockBackupFacadeCaller, nil), nil 51 } 52 mockBackupsClient, _ := connFunc() 53 mockBackupsClient.RestoreReader(nil, &testBackupResults, connFunc) 54 }