github.com/IBM-Cloud/bluemix-go@v0.0.0-20240314082800-4e02a69b84b2/api/schematics/workspace_test.go (about) 1 package schematics 2 3 import ( 4 "log" 5 "net/http" 6 7 bluemix "github.com/IBM-Cloud/bluemix-go" 8 "github.com/IBM-Cloud/bluemix-go/client" 9 bluemixHttp "github.com/IBM-Cloud/bluemix-go/http" 10 "github.com/IBM-Cloud/bluemix-go/session" 11 12 "github.com/onsi/gomega/ghttp" 13 14 . "github.com/onsi/ginkgo" 15 . "github.com/onsi/gomega" 16 ) 17 18 var _ = Describe("workspaces", func() { 19 var server *ghttp.Server 20 AfterEach(func() { 21 server.Close() 22 }) 23 24 //getworkspace 25 Describe("Get", func() { 26 Context("When Get workspace is successful", func() { 27 BeforeEach(func() { 28 server = ghttp.NewServer() 29 server.AppendHandlers( 30 ghttp.CombineHandlers( 31 ghttp.VerifyRequest(http.MethodGet, "/v1/workspaces/myworkspaceptab-bc54176d-bbcb-42"), 32 ghttp.RespondWith(http.StatusCreated, `{ 33 "catalog_ref": { 34 "item_icon_url": "string", 35 "item_id": "string", 36 "item_name": "string", 37 "item_readme_url": "string", 38 "item_url": "string", 39 "launch_url": "string", 40 "offering_version": "string" 41 }, 42 "created_at": "2019-11-12T17:56:31.081Z", 43 "created_by": "string", 44 "description": "string", 45 "id": "string", 46 "last_health_check_at": "2019-11-12T17:56:31.081Z", 47 "location": "string", 48 "name": "string", 49 "resource_group": "string", 50 "runtime_data": [ 51 { 52 "engine_cmd": "string", 53 "engine_name": "string", 54 "engine_version": "string", 55 "id": "string", 56 "log_store_url": "string", 57 "output_values": { 58 "additionalProp1": "string", 59 "additionalProp2": "string", 60 "additionalProp3": "string" 61 }, 62 "resources": [ 63 [ 64 {} 65 ] 66 ], 67 "state_store_url": "string" 68 } 69 ], 70 "shared_data": { 71 "cluster_id": "string", 72 "cluster_name": "string", 73 "entitlement_keys": [ 74 {} 75 ], 76 "namespace": "string", 77 "region": "string", 78 "resource_group_id": "string" 79 }, 80 "status": "string", 81 "tags": [ 82 "string" 83 ], 84 "template_data": [ 85 { 86 "env_values": [ 87 { 88 "hidden": true, 89 "name": "string", 90 "secure": true, 91 "value": "string" 92 } 93 ], 94 "folder": "string", 95 "id": "string", 96 "type": "string", 97 "uninstall_script_name": "string", 98 "values": "string", 99 "values_metadata": [ 100 {} 101 ], 102 "values_url": "string", 103 "variablestore": [ 104 { 105 "description": "string", 106 "name": "string", 107 "type": "string", 108 "value": "string" 109 } 110 ] 111 } 112 ], 113 "template_ref": "string", 114 "template_repo": { 115 "branch": "string", 116 "release": "string", 117 "repo_url": "string", 118 "url": "string" 119 }, 120 "type": [ 121 "string" 122 ], 123 "updated_at": "2019-11-12T17:56:31.081Z", 124 "updated_by": "string", 125 "workspace_status": { 126 "frozen": true, 127 "frozen_at": "2019-11-12T17:56:31.081Z", 128 "frozen_by": "string", 129 "locked": true, 130 "locked_by": "string", 131 "locked_time": "2019-11-12T17:56:31.081Z" 132 }, 133 "workspace_status_msg": { 134 "status_code": "string", 135 "status_msg": "string" 136 } 137 }`), 138 ), 139 ) 140 }) 141 142 It("should get Workspace", func() { 143 144 _, err := newWorkspace(server.URL()).GetWorkspaceByID("myworkspaceptab-bc54176d-bbcb-42") 145 Expect(err).NotTo(HaveOccurred()) 146 }) 147 }) 148 Context("When get workspace is unsuccessful", func() { 149 BeforeEach(func() { 150 server = ghttp.NewServer() 151 server.SetAllowUnhandledRequests(true) 152 server.AppendHandlers( 153 ghttp.CombineHandlers( 154 ghttp.VerifyRequest(http.MethodGet, "/v1/workspaces/myworkspaceptab-bc54176d-bbcb-42"), 155 ghttp.RespondWith(http.StatusInternalServerError, `Failed to get workerpool`), 156 ), 157 ) 158 }) 159 160 It("should return error during get workspace", func() { 161 _, err := newWorkspace(server.URL()).GetWorkspaceByID("myworkspaceptab-bc54176d-bbcb-42") 162 Expect(err).To(HaveOccurred()) 163 }) 164 }) 165 }) 166 167 //getStateStore 168 Describe("GetState", func() { 169 Context("When Get State store is successful", func() { 170 BeforeEach(func() { 171 server = ghttp.NewServer() 172 server.AppendHandlers( 173 ghttp.CombineHandlers( 174 ghttp.VerifyRequest(http.MethodGet, "/v1/workspaces/myworkspaceptab-bc54176d-bbcb-42/runtime_data/29291199-ca08-46/state_store"), 175 ghttp.RespondWith(http.StatusCreated, `{}`), 176 ), 177 ) 178 }) 179 180 It("should get State", func() { 181 182 _, err := newWorkspace(server.URL()).GetStateStore("myworkspaceptab-bc54176d-bbcb-42", "29291199-ca08-46") 183 Expect(err).NotTo(HaveOccurred()) 184 }) 185 }) 186 Context("When get state is unsuccessful", func() { 187 BeforeEach(func() { 188 server = ghttp.NewServer() 189 server.SetAllowUnhandledRequests(true) 190 server.AppendHandlers( 191 ghttp.CombineHandlers( 192 ghttp.VerifyRequest(http.MethodGet, "/v1/workspaces/myworkspaceptab-bc54176d-bbcb-42/runtime_data/29291199-ca08-46/state_store"), 193 ghttp.RespondWith(http.StatusInternalServerError, `Failed to get state`), 194 ), 195 ) 196 }) 197 198 It("should return error during get state", func() { 199 _, err := newWorkspace(server.URL()).GetStateStore("myworkspaceptab-bc54176d-bbcb-42", "29291199-ca08-46") 200 Expect(err).To(HaveOccurred()) 201 }) 202 }) 203 }) 204 205 //getStateStore 206 Describe("GetOutput Values", func() { 207 Context("When Get output is successful", func() { 208 BeforeEach(func() { 209 server = ghttp.NewServer() 210 server.AppendHandlers( 211 ghttp.CombineHandlers( 212 ghttp.VerifyRequest(http.MethodGet, "/v1/workspaces/myworkspaceptab-bc54176d-bbcb-42/output_values"), 213 ghttp.RespondWith(http.StatusCreated, `[{ 214 "folder": "string", 215 "id": "string", 216 "output_values": [ 217 {} 218 ], 219 "type": "string" 220 }]`), 221 ), 222 ) 223 }) 224 225 It("should get output values", func() { 226 227 _, err := newWorkspace(server.URL()).GetOutputValues("myworkspaceptab-bc54176d-bbcb-42") 228 Expect(err).NotTo(HaveOccurred()) 229 }) 230 }) 231 Context("When get output is unsuccessful", func() { 232 BeforeEach(func() { 233 server = ghttp.NewServer() 234 server.SetAllowUnhandledRequests(true) 235 server.AppendHandlers( 236 ghttp.CombineHandlers( 237 ghttp.VerifyRequest(http.MethodGet, "/v1/workspaces/myworkspaceptab-bc54176d-bbcb-42/output_values"), 238 ghttp.RespondWith(http.StatusInternalServerError, `Failed to get state`), 239 ), 240 ) 241 }) 242 243 It("should return error during get state", func() { 244 _, err := newWorkspace(server.URL()).GetOutputValues("myworkspaceptab-bc54176d-bbcb-42") 245 Expect(err).To(HaveOccurred()) 246 }) 247 }) 248 }) 249 250 }) 251 252 func newWorkspace(url string) Workspaces { 253 254 sess, err := session.New() 255 if err != nil { 256 log.Fatal(err) 257 } 258 conf := sess.Config.Copy() 259 conf.HTTPClient = bluemixHttp.NewHTTPClient(conf) 260 conf.Endpoint = &url 261 262 client := client.Client{ 263 Config: conf, 264 ServiceName: bluemix.SchematicsService, 265 } 266 return newWorkspaceAPI(&client) 267 }