@@ -21,6 +21,7 @@ import (
2121
2222 "github.com/golang/mock/gomock"
2323 "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/mocks"
24+ "github.com/stretchr/testify/require"
2425 atlasv2 "go.mongodb.org/atlas-sdk/v20241113004/admin"
2526)
2627
@@ -39,15 +40,44 @@ func TestStart_Run(t *testing.T) {
3940 targetProjectID : "1" ,
4041 }
4142
43+ expectedError := & atlasv2.GenericOpenAPIError {}
44+ expectedError .SetModel (atlasv2.ApiError {ErrorCode : cannotUseNotFlexWithFlexApisErrorCode })
45+
46+ mockStore .
47+ EXPECT ().
48+ CreateRestoreFlexClusterJobs (listOpts .ProjectID , "Cluster0" , listOpts .newFlexBackupRestoreJobCreate ()).
49+ Return (nil , expectedError ).
50+ Times (1 )
51+
4252 mockStore .
4353 EXPECT ().
4454 CreateRestoreJobs (listOpts .ProjectID , "Cluster0" , listOpts .newCloudProviderSnapshotRestoreJob ()).
4555 Return (expected , nil ).
4656 Times (1 )
4757
48- if err := listOpts .Run (); err != nil {
49- t .Fatalf ("Run() unexpected error: %v" , err )
58+ require .NoError (t , listOpts .Run ())
59+ })
60+
61+ t .Run ("Flex Cluster automated restore job" , func (t * testing.T ) {
62+ listOpts := & StartOpts {
63+ store : mockStore ,
64+ method : automatedRestore ,
65+ clusterName : "Cluster0" ,
66+ targetClusterName : "Cluster1" ,
67+ targetProjectID : "1" ,
5068 }
69+
70+ expectedFlex := & atlasv2.FlexBackupRestoreJob20241113 {}
71+ expectedError := & atlasv2.GenericOpenAPIError {}
72+ expectedError .SetModel (atlasv2.ApiError {ErrorCode : cannotUseNotFlexWithFlexApisErrorCode })
73+
74+ mockStore .
75+ EXPECT ().
76+ CreateRestoreFlexClusterJobs (listOpts .ProjectID , "Cluster0" , listOpts .newFlexBackupRestoreJobCreate ()).
77+ Return (expectedFlex , nil ).
78+ Times (1 )
79+
80+ require .NoError (t , listOpts .Run ())
5181 })
5282
5383 t .Run (pointInTimeRestore , func (t * testing.T ) {
@@ -59,15 +89,22 @@ func TestStart_Run(t *testing.T) {
5989 targetProjectID : "1" ,
6090 }
6191
92+ expectedError := & atlasv2.GenericOpenAPIError {}
93+ expectedError .SetModel (atlasv2.ApiError {ErrorCode : cannotUseNotFlexWithFlexApisErrorCode })
94+
95+ mockStore .
96+ EXPECT ().
97+ CreateRestoreFlexClusterJobs (listOpts .ProjectID , "Cluster0" , listOpts .newFlexBackupRestoreJobCreate ()).
98+ Return (nil , expectedError ).
99+ Times (1 )
100+
62101 mockStore .
63102 EXPECT ().
64103 CreateRestoreJobs (listOpts .ProjectID , "Cluster0" , listOpts .newCloudProviderSnapshotRestoreJob ()).
65104 Return (expected , nil ).
66105 Times (1 )
67106
68- if err := listOpts .Run (); err != nil {
69- t .Fatalf ("Run() unexpected error: %v" , err )
70- }
107+ require .NoError (t , listOpts .Run ())
71108 })
72109
73110 t .Run (downloadRestore , func (t * testing.T ) {
@@ -77,14 +114,21 @@ func TestStart_Run(t *testing.T) {
77114 clusterName : "Cluster0" ,
78115 }
79116
117+ expectedError := & atlasv2.GenericOpenAPIError {}
118+ expectedError .SetModel (atlasv2.ApiError {ErrorCode : cannotUseNotFlexWithFlexApisErrorCode })
119+
120+ mockStore .
121+ EXPECT ().
122+ CreateRestoreFlexClusterJobs (listOpts .ProjectID , "Cluster0" , listOpts .newFlexBackupRestoreJobCreate ()).
123+ Return (nil , expectedError ).
124+ Times (1 )
125+
80126 mockStore .
81127 EXPECT ().
82128 CreateRestoreJobs (listOpts .ProjectID , "Cluster0" , listOpts .newCloudProviderSnapshotRestoreJob ()).
83129 Return (expected , nil ).
84130 Times (1 )
85131
86- if err := listOpts .Run (); err != nil {
87- t .Fatalf ("Run() unexpected error: %v" , err )
88- }
132+ require .NoError (t , listOpts .Run ())
89133 })
90134}
0 commit comments