@@ -12,6 +12,7 @@ import (
12
12
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/searchdeployment"
13
13
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mocksvc"
14
14
"github.com/stretchr/testify/assert"
15
+ "github.com/stretchr/testify/mock"
15
16
"go.mongodb.org/atlas-sdk/v20231115007/admin"
16
17
)
17
18
@@ -73,15 +74,16 @@ func TestSearchDeploymentStateTransition(t *testing.T) {
73
74
74
75
for _ , tc := range testCases {
75
76
t .Run (tc .name , func (t * testing.T ) {
76
- svc := mocksvc .NewDeploymentService (t )
77
- ctx := context .Background ()
77
+ m := mocksvc .NewAtlasSearchApi (t )
78
+ m .EXPECT ().GetAtlasSearchDeployment (mock .Anything , mock .Anything , mock .Anything ).Return (admin.GetAtlasSearchDeploymentApiRequest {ApiService : m })
79
+
78
80
for _ , resp := range tc .mockResponses {
79
- svc .On ("GetAtlasSearchDeployment" , ctx , dummyProjectID , clusterName ).Return (resp .get ()... ).Once ()
81
+ modelResp , httpResp , err := resp .get ()
82
+ m .EXPECT ().GetAtlasSearchDeploymentExecute (mock .Anything ).Return (modelResp , httpResp , err ).Once ()
80
83
}
81
- resp , err := searchdeployment .WaitSearchNodeStateTransition (ctx , dummyProjectID , "Cluster0" , svc , testTimeoutConfig )
84
+ resp , err := searchdeployment .WaitSearchNodeStateTransition (context . Background () , dummyProjectID , "Cluster0" , m , testTimeoutConfig )
82
85
assert .Equal (t , tc .expectedError , err != nil )
83
86
assert .Equal (t , responseWithState (tc .expectedState ), resp )
84
- svc .AssertExpectations (t )
85
87
})
86
88
}
87
89
}
@@ -115,14 +117,15 @@ func TestSearchDeploymentStateTransitionForDelete(t *testing.T) {
115
117
116
118
for _ , tc := range testCases {
117
119
t .Run (tc .name , func (t * testing.T ) {
118
- svc := mocksvc .NewDeploymentService (t )
119
- ctx := context .Background ()
120
+ m := mocksvc .NewAtlasSearchApi (t )
121
+ m .EXPECT ().GetAtlasSearchDeployment (mock .Anything , mock .Anything , mock .Anything ).Return (admin.GetAtlasSearchDeploymentApiRequest {ApiService : m })
122
+
120
123
for _ , resp := range tc .mockResponses {
121
- svc .On ("GetAtlasSearchDeployment" , ctx , dummyProjectID , clusterName ).Return (resp .get ()... ).Once ()
124
+ modelResp , httpResp , err := resp .get ()
125
+ m .EXPECT ().GetAtlasSearchDeploymentExecute (mock .Anything ).Return (modelResp , httpResp , err ).Once ()
122
126
}
123
- err := searchdeployment .WaitSearchNodeDelete (ctx , dummyProjectID , clusterName , svc , testTimeoutConfig )
127
+ err := searchdeployment .WaitSearchNodeDelete (context . Background () , dummyProjectID , clusterName , m , testTimeoutConfig )
124
128
assert .Equal (t , tc .expectedError , err != nil )
125
- svc .AssertExpectations (t )
126
129
})
127
130
}
128
131
}
@@ -156,10 +159,10 @@ type response struct {
156
159
err error
157
160
}
158
161
159
- func (r * response ) get () [] interface {} {
162
+ func (r * response ) get () ( * admin. ApiSearchDeploymentResponse , * http. Response , error ) {
160
163
var httpResp * http.Response
161
164
if r .statusCode != nil {
162
165
httpResp = & http.Response {StatusCode : * r .statusCode }
163
166
}
164
- return [] interface {}{ responseWithState (r .state ), httpResp , r .err }
167
+ return responseWithState (r .state ), httpResp , r .err
165
168
}
0 commit comments