@@ -104,24 +104,12 @@ var _ = Describe("DevWorkspace Controller", func() {
104104 Context ("Workspace Objects creation" , func () {
105105
106106 BeforeEach (func () {
107- By ("Reading DevWorkspace from testdata file" )
108- devworkspace := & dw.DevWorkspace {}
109- err := loadObjectFromFile (devWorkspaceName , devworkspace , "test-devworkspace.yaml" )
110- Expect (err ).NotTo (HaveOccurred ())
111-
112- By ("Creating a new DevWorkspace" )
113- Expect (k8sClient .Create (ctx , devworkspace )).Should (Succeed ())
114- createdDW := & dw.DevWorkspace {}
115- Eventually (func () bool {
116- if err := k8sClient .Get (ctx , types.NamespacedName {Name : devWorkspaceName , Namespace : testNamespace }, createdDW ); err != nil {
117- return false
118- }
119- return createdDW .Status .DevWorkspaceId != ""
120- }, timeout , interval ).Should (BeTrue ())
107+ createDevWorkspace ("test-devworkspace.yaml" )
121108 })
122109
123110 AfterEach (func () {
124111 deleteDevWorkspace (devWorkspaceName )
112+ workspacecontroller .SetupHttpClientsForTesting (getBasicTestHttpClient ())
125113 })
126114
127115 It ("Creates roles and rolebindings" , func () {
@@ -152,11 +140,8 @@ var _ = Describe("DevWorkspace Controller", func() {
152140 })
153141
154142 It ("Creates DevWorkspaceRouting" , func () {
155- By ("Getting existing DevWorkspace from cluster" )
156- devworkspace := & dw.DevWorkspace {}
157- Expect (k8sClient .Get (ctx , types.NamespacedName {Name : devWorkspaceName , Namespace : testNamespace }, devworkspace )).Should (Succeed ())
143+ devworkspace := getExistingDevWorkspace ()
158144 workspaceID := devworkspace .Status .DevWorkspaceId
159- Expect (workspaceID ).ShouldNot (BeEmpty (), "DevWorkspaceID not set" )
160145
161146 By ("Checking that DevWorkspaceRouting is created" )
162147 dwr := & controllerv1alpha1.DevWorkspaceRouting {}
@@ -172,11 +157,8 @@ var _ = Describe("DevWorkspace Controller", func() {
172157 })
173158
174159 It ("Syncs Routing mainURL to DevWorkspace" , func () {
175- By ("Getting existing DevWorkspace from cluster" )
176- devworkspace := & dw.DevWorkspace {}
177- Expect (k8sClient .Get (ctx , types.NamespacedName {Name : devWorkspaceName , Namespace : testNamespace }, devworkspace )).Should (Succeed ())
160+ devworkspace := getExistingDevWorkspace ()
178161 workspaceID := devworkspace .Status .DevWorkspaceId
179- Expect (workspaceID ).ShouldNot (BeEmpty (), "DevWorkspaceID not set" )
180162
181163 By ("Manually making Routing ready to continue" )
182164 markRoutingReady ("test-url" , common .DevWorkspaceRoutingName (workspaceID ))
@@ -191,11 +173,8 @@ var _ = Describe("DevWorkspace Controller", func() {
191173 })
192174
193175 It ("Creates workspace metadata configmap" , func () {
194- By ("Getting existing DevWorkspace from cluster" )
195- devworkspace := & dw.DevWorkspace {}
196- Expect (k8sClient .Get (ctx , types.NamespacedName {Name : devWorkspaceName , Namespace : testNamespace }, devworkspace )).Should (Succeed ())
176+ devworkspace := getExistingDevWorkspace ()
197177 workspaceID := devworkspace .Status .DevWorkspaceId
198- Expect (workspaceID ).ShouldNot (BeEmpty (), "DevWorkspaceID not set" )
199178
200179 By ("Manually making Routing ready to continue" )
201180 markRoutingReady ("test-url" , common .DevWorkspaceRoutingName (workspaceID ))
@@ -224,11 +203,8 @@ var _ = Describe("DevWorkspace Controller", func() {
224203 })
225204
226205 It ("Syncs the DevWorkspace ServiceAccount" , func () {
227- By ("Getting existing DevWorkspace from cluster" )
228- devworkspace := & dw.DevWorkspace {}
229- Expect (k8sClient .Get (ctx , types.NamespacedName {Name : devWorkspaceName , Namespace : testNamespace }, devworkspace )).Should (Succeed ())
206+ devworkspace := getExistingDevWorkspace ()
230207 workspaceID := devworkspace .Status .DevWorkspaceId
231- Expect (workspaceID ).ShouldNot (BeEmpty (), "DevWorkspaceID not set" )
232208
233209 By ("Manually making Routing ready to continue" )
234210 markRoutingReady ("test-url" , common .DevWorkspaceRoutingName (workspaceID ))
@@ -249,11 +225,8 @@ var _ = Describe("DevWorkspace Controller", func() {
249225 })
250226
251227 It ("Syncs DevWorkspace Deployment" , func () {
252- By ("Getting existing DevWorkspace from cluster" )
253- devworkspace := & dw.DevWorkspace {}
254- Expect (k8sClient .Get (ctx , types.NamespacedName {Name : devWorkspaceName , Namespace : testNamespace }, devworkspace )).Should (Succeed ())
228+ devworkspace := getExistingDevWorkspace ()
255229 workspaceID := devworkspace .Status .DevWorkspaceId
256- Expect (workspaceID ).ShouldNot (BeEmpty (), "DevWorkspaceID not set" )
257230
258231 By ("Manually making Routing ready to continue" )
259232 markRoutingReady ("test-url" , common .DevWorkspaceRoutingName (workspaceID ))
@@ -274,12 +247,8 @@ var _ = Describe("DevWorkspace Controller", func() {
274247 })
275248
276249 It ("Marks DevWorkspace as Running" , func () {
277- By ("Getting existing DevWorkspace from cluster" )
278- devworkspace := & dw.DevWorkspace {}
279- dwNN := types.NamespacedName {Name : devWorkspaceName , Namespace : testNamespace }
280- Expect (k8sClient .Get (ctx , dwNN , devworkspace )).Should (Succeed ())
250+ devworkspace := getExistingDevWorkspace ()
281251 workspaceID := devworkspace .Status .DevWorkspaceId
282- Expect (workspaceID ).ShouldNot (BeEmpty (), "DevWorkspaceID not set" )
283252
284253 workspacecontroller .SetupHttpClientsForTesting (& http.Client {
285254 Transport : & testutil.TestRoundTripper {
@@ -298,7 +267,10 @@ var _ = Describe("DevWorkspace Controller", func() {
298267
299268 currDW := & dw.DevWorkspace {}
300269 Eventually (func () (dw.DevWorkspacePhase , error ) {
301- err := k8sClient .Get (ctx , dwNN , currDW )
270+ err := k8sClient .Get (ctx , types.NamespacedName {
271+ Name : devworkspace .Name ,
272+ Namespace : devworkspace .Namespace ,
273+ }, currDW )
302274 if err != nil {
303275 return "" , err
304276 }
0 commit comments