@@ -16,25 +16,37 @@ import (
1616 "github.com/bcmi-labs/orchestrator/internal/e2e/client"
1717)
1818
19- func TestGetAppBrickInstances (t * testing.T ) {
20-
19+ func setupTestApp (t * testing.T ) (* client.CreateAppResp , * client.ClientWithResponses ) {
2120 httpClient := GetHttpclient (t )
22- var actualBody models.ErrorResponse
23-
2421 createResp , err := httpClient .CreateAppWithResponse (
2522 t .Context (),
2623 & client.CreateAppParams {SkipSketch : f .Ptr (true )},
2724 client.CreateAppRequest {
28- Icon : f .Ptr ("💻" ),
29- Name : "test-app" ,
30- Bricks : & []string {ImageClassifactionBrickID },
25+ Icon : f .Ptr ("💻" ),
26+ Name : "test-app" ,
3127 },
3228 func (ctx context.Context , req * http.Request ) error { return nil },
3329 )
3430 require .NoError (t , err )
3531 require .Equal (t , http .StatusCreated , createResp .StatusCode ())
3632 require .NotNil (t , createResp .JSON201 )
3733
34+ resp , err := httpClient .UpsertAppBrickInstanceWithResponse (
35+ t .Context (),
36+ * createResp .JSON201 .Id ,
37+ ImageClassifactionBrickID ,
38+ client.BrickCreateUpdateRequest {Model : f .Ptr ("mobilenet-image-classification" )},
39+ func (ctx context.Context , req * http.Request ) error { return nil },
40+ )
41+ require .NoError (t , err )
42+ require .Equal (t , http .StatusOK , resp .StatusCode ())
43+
44+ return createResp , httpClient
45+ }
46+
47+ func TestGetAppBrickInstances (t * testing.T ) {
48+ var actualBody models.ErrorResponse
49+ createResp , httpClient := setupTestApp (t )
3850 t .Run ("GetAppBrickInstances_Success" , func (t * testing.T ) {
3951 brickInstances , err := httpClient .GetAppBrickInstancesWithResponse (t .Context (), * createResp .JSON201 .Id , func (ctx context.Context , req * http.Request ) error { return nil })
4052 require .NoError (t , err )
@@ -71,23 +83,8 @@ func TestGetAppBrickInstances(t *testing.T) {
7183
7284func TestGetAppBrickInstanceById (t * testing.T ) {
7385
74- httpClient := GetHttpclient (t )
75-
7686 var actualBody models.ErrorResponse
77-
78- createResp , err := httpClient .CreateAppWithResponse (
79- t .Context (),
80- & client.CreateAppParams {SkipSketch : f .Ptr (true )},
81- client.CreateAppRequest {
82- Icon : f .Ptr ("💻" ),
83- Name : "test-app" ,
84- Bricks : & []string {ImageClassifactionBrickID },
85- },
86- func (ctx context.Context , req * http.Request ) error { return nil },
87- )
88- require .NoError (t , err )
89- require .Equal (t , http .StatusCreated , createResp .StatusCode ())
90- require .NotNil (t , createResp .JSON201 )
87+ createResp , httpClient := setupTestApp (t )
9188
9289 t .Run ("GetAppBrickInstanceByBrickID_Success" , func (t * testing.T ) {
9390 brickInstance , err := httpClient .GetAppBrickInstanceByBrickIDWithResponse (
@@ -138,34 +135,7 @@ func TestGetAppBrickInstanceById(t *testing.T) {
138135
139136func TestUpsertAppBrickInstance (t * testing.T ) {
140137 var actualResponseBody models.ErrorResponse
141- httpClient := GetHttpclient (t )
142-
143- createResp , err := httpClient .CreateAppWithResponse (
144- t .Context (),
145- & client.CreateAppParams {SkipSketch : f .Ptr (true )},
146- client.CreateAppRequest {
147- Icon : f .Ptr ("💻" ),
148- Name : "test-app" ,
149- },
150- func (ctx context.Context , req * http.Request ) error { return nil },
151- )
152- require .NoError (t , err )
153- require .Equal (t , http .StatusCreated , createResp .StatusCode ())
154- require .NotNil (t , createResp .JSON201 )
155-
156- // Create the brick instance
157- resp , err := httpClient .UpsertAppBrickInstanceWithResponse (
158- t .Context (),
159- * createResp .JSON201 .Id ,
160- ImageClassifactionBrickID ,
161- client.BrickCreateUpdateRequest {
162- Model : f .Ptr ("person-classification" ),
163- Variables : & map [string ]string {"CUSTOM_MODEL_PATH" : "overidden" },
164- },
165- func (ctx context.Context , req * http.Request ) error { return nil },
166- )
167- require .NoError (t , err )
168- require .Equal (t , http .StatusOK , resp .StatusCode ())
138+ createResp , httpClient := setupTestApp (t )
169139
170140 // Verify the brick instance was updated
171141 brickInstance , err := httpClient .GetAppBrickInstanceByBrickIDWithResponse (
@@ -176,8 +146,8 @@ func TestUpsertAppBrickInstance(t *testing.T) {
176146 require .NoError (t , err )
177147 require .NotEmpty (t , brickInstance .JSON200 )
178148 require .Equal (t , ImageClassifactionBrickID , * brickInstance .JSON200 .Id )
179- require .Equal (t , "overidden " , (* brickInstance .JSON200 .Variables )["CUSTOM_MODEL_PATH" ])
180- require .Equal (t , "person -classification" , * brickInstance .JSON200 .Model )
149+ require .Equal (t , "/models/custom/ei/ " , (* brickInstance .JSON200 .Variables )["CUSTOM_MODEL_PATH" ])
150+ require .Equal (t , "mobilenet-image -classification" , * brickInstance .JSON200 .Model )
181151
182152 t .Run ("OverrideBrickInstance" , func (t * testing.T ) {
183153 resp , err := httpClient .UpsertAppBrickInstanceWithResponse (
@@ -300,21 +270,8 @@ func TestUpsertAppBrickInstance(t *testing.T) {
300270
301271func TestUpdateAppBrickInstance (t * testing.T ) {
302272 var actualResponseBody models.ErrorResponse
303- httpClient := GetHttpclient (t )
273+ createResp , httpClient := setupTestApp (t )
304274
305- createResp , err := httpClient .CreateAppWithResponse (
306- t .Context (),
307- & client.CreateAppParams {SkipSketch : f .Ptr (true )},
308- client.CreateAppRequest {
309- Icon : f .Ptr ("💻" ),
310- Name : "test-app" ,
311- Bricks : & []string {ImageClassifactionBrickID },
312- },
313- func (ctx context.Context , req * http.Request ) error { return nil },
314- )
315- require .NoError (t , err )
316- require .Equal (t , http .StatusCreated , createResp .StatusCode ())
317- require .NotNil (t , createResp .JSON201 )
318275 t .Run ("UpdateAppBrickInstance" , func (t * testing.T ) {
319276 resp , err := httpClient .UpdateAppBrickInstanceWithResponse (
320277 t .Context (),
@@ -480,21 +437,7 @@ func TestUpdateAppBrickInstance(t *testing.T) {
480437
481438func TestDeleteAppBrickInstance (t * testing.T ) {
482439
483- httpClient := GetHttpclient (t )
484-
485- createResp , err := httpClient .CreateAppWithResponse (
486- t .Context (),
487- & client.CreateAppParams {SkipSketch : f .Ptr (true )},
488- client.CreateAppRequest {
489- Icon : f .Ptr ("💻" ),
490- Name : "test-app" ,
491- Bricks : & []string {ImageClassifactionBrickID },
492- },
493- func (ctx context.Context , req * http.Request ) error { return nil },
494- )
495- require .NoError (t , err )
496- require .Equal (t , http .StatusCreated , createResp .StatusCode ())
497- require .NotNil (t , createResp .JSON201 )
440+ createResp , httpClient := setupTestApp (t )
498441
499442 t .Run ("DeleteAppBrickInstance_NoExistingAppId_fail" , func (t * testing.T ) {
500443 var actualResponseBody models.ErrorResponse
0 commit comments