@@ -9,17 +9,19 @@ import (
99
1010 "github.com/bcmi-labs/orchestrator/internal/orchestrator/app"
1111 "github.com/bcmi-labs/orchestrator/internal/orchestrator/bricksindex"
12+ "github.com/bcmi-labs/orchestrator/internal/store"
1213
1314 yaml "github.com/goccy/go-yaml"
1415
15- "github.com/stretchr/testify/assert"
1616 "github.com/stretchr/testify/require"
1717)
1818
1919func TestProvisionAppWithOverrides (t * testing.T ) {
2020 cfg := setTestOrchestratorConfig (t )
2121 tempDirectory := t .TempDir ()
2222
23+ staticStore := store .NewStaticStore (cfg .AssetsDir ().String ())
24+
2325 // Define a mock app with bricks that require overrides
2426 app := app.ArduinoApp {
2527 Name : "TestApp" ,
@@ -36,10 +38,10 @@ func TestProvisionAppWithOverrides(t *testing.T) {
3638 },
3739 FullPath : paths .New (tempDirectory ),
3840 }
41+ require .NoError (t , app .ProvisioningStateDir ().MkdirAll ())
3942 // Add compose files for the bricks - video object detection
40- videoObjectDetectionComposePath := paths .New (tempDirectory ).Join (".cache" ).Join ("compose" ).Join ("arduino" ).Join ("video_object_detection" )
41- err := videoObjectDetectionComposePath .MkdirAll ()
42- assert .Nil (t , err , "Failed to create compose directory for video object detection" )
43+ videoObjectDetectionComposePath := cfg .AssetsDir ().Join ("compose" , "arduino" , "video_object_detection" )
44+ require .NoError (t , videoObjectDetectionComposePath .MkdirAll ())
4345 composeForVideoObjectDetection := `
4446version: '3.8'
4547services:
@@ -48,8 +50,8 @@ services:
4850 ports:
4951 - "8080:8080"
5052`
51- err = videoObjectDetectionComposePath .Join ("brick_compose.yaml" ).WriteFile ([]byte (composeForVideoObjectDetection ))
52- assert . Nil (t , err , "Failed to write compose file for video object detection" )
53+ err : = videoObjectDetectionComposePath .Join ("brick_compose.yaml" ).WriteFile ([]byte (composeForVideoObjectDetection ))
54+ require . NoError (t , err )
5355
5456 bricksIndexContent := []byte (`
5557bricks:
@@ -80,40 +82,40 @@ bricks:
8082 - name: EI_OBJ_DETECTION_MODEL
8183 default_value: /models/ootb/ei/yolo-x-nano.eim
8284 description: path to the model file` )
83- err = paths . New ( tempDirectory , "bricks-list.yaml" ).WriteFile (bricksIndexContent )
85+ err = cfg . AssetsDir (). Join ( "bricks-list.yaml" ).WriteFile (bricksIndexContent )
8486 require .NoError (t , err )
8587
8688 // Override brick index with custom test content
87- bricksIndex , err := bricksindex .GenerateBricksIndexFromFile (paths . New ( tempDirectory ))
88- assert .Nil (t , err , "Failed to load bricks index with custom content" )
89+ bricksIndex , err := bricksindex .GenerateBricksIndexFromFile (cfg . AssetsDir ( ))
90+ require .Nil (t , err , "Failed to load bricks index with custom content" )
8991
9092 br , ok := bricksIndex .FindBrickByID ("arduino:video_object_detection" )
91- assert .True (t , ok , "Brick arduino:video_object_detection should exist in the index" )
92- assert .NotNil (t , br , "Brick arduino:video_object_detection should not be nil" )
93- assert .Equal (t , "Object Detection" , br .Name , "Brick name should match" )
93+ require .True (t , ok , "Brick arduino:video_object_detection should exist in the index" )
94+ require .NotNil (t , br , "Brick arduino:video_object_detection should not be nil" )
95+ require .Equal (t , "Object Detection" , br .Name , "Brick name should match" )
9496
9597 // Run the provision function to generate the main compose file
9698 env := map [string ]string {}
97- err = generateMainComposeFile (& app , bricksIndex , "arduino:appslab-python-apps-base:dev-latest" , cfg , env )
99+ err = generateMainComposeFile (& app , bricksIndex , "arduino:appslab-python-apps-base:dev-latest" , cfg , env , staticStore )
98100
99101 // Validate that the main compose file and overrides are created
100- assert . Nil (t , err , "Failed to generate main compose file" )
102+ require . NoError (t , err , "Failed to generate main compose file" )
101103 composeFilePath := paths .New (tempDirectory ).Join (".cache" ).Join ("app-compose.yaml" )
102- assert .True (t , composeFilePath .Exist (), "Main compose file should exist" )
104+ require .True (t , composeFilePath .Exist (), "Main compose file should exist" )
103105 overridesFilePath := paths .New (tempDirectory ).Join (".cache" ).Join ("app-compose-overrides.yaml" )
104- assert .True (t , overridesFilePath .Exist (), "Override compose file should exist" )
106+ require .True (t , overridesFilePath .Exist (), "Override compose file should exist" )
105107
106108 // Open override file and check for the expected override
107109 overridesContent , err := overridesFilePath .ReadFile ()
108- assert .Nil (t , err , "Failed to read overrides file" )
110+ require .Nil (t , err , "Failed to read overrides file" )
109111 type services struct {
110112 Services map [string ]map [string ]interface {} `yaml:"services"`
111113 }
112114 content := services {}
113115 err = yaml .Unmarshal (overridesContent , & content )
114- assert .Nil (t , err , "Failed to unmarshal overrides content" )
115- assert .NotNil (t , content .Services ["ei-video-obj-detection-runner" ], "Override for ei-video-obj-detection-runner should exist" )
116- assert .NotNil (t , content .Services ["ei-video-obj-detection-runner" ]["devices" ], "Override for ei-video-obj-detection-runner devices should exist" )
116+ require .Nil (t , err , "Failed to unmarshal overrides content" )
117+ require .NotNil (t , content .Services ["ei-video-obj-detection-runner" ], "Override for ei-video-obj-detection-runner should exist" )
118+ require .NotNil (t , content .Services ["ei-video-obj-detection-runner" ]["devices" ], "Override for ei-video-obj-detection-runner devices should exist" )
117119}
118120
119121func TestVolumeParser (t * testing.T ) {
@@ -145,9 +147,9 @@ services:
145147 "CUSTOM_PATH" : tempDirectory ,
146148 }
147149 volumes , err := extractVolumesFromComposeFile (volumesFromFile .String ())
148- assert .Nil (t , err , "Failed to extract volumes from compose file" )
150+ require .Nil (t , err , "Failed to extract volumes from compose file" )
149151 provisionComposeVolumes (volumesFromFile .String (), volumes , app , env )
150- assert .True (t , app .FullPath .Join ("data" ).Join ("influx-data" ).Exist (), "Volume directory should exist" )
152+ require .True (t , app .FullPath .Join ("data" ).Join ("influx-data" ).Exist (), "Volume directory should exist" )
151153 })
152154
153155 t .Run ("TestPreProvsionVolumesCustomEnvUsingDefault" , func (t * testing.T ) {
@@ -178,9 +180,9 @@ services:
178180 // No env, use macro default value
179181 env := map [string ]string {}
180182 volumes , err := extractVolumesFromComposeFile (volumesFromFile .String ())
181- assert .Nil (t , err , "Failed to extract volumes from compose file" )
183+ require .Nil (t , err , "Failed to extract volumes from compose file" )
182184 provisionComposeVolumes (volumesFromFile .String (), volumes , app , env )
183- assert .True (t , app .FullPath .Join ("customized" ).Join ("data" ).Join ("influx-data" ).Exist (), "Volume directory should exist" )
185+ require .True (t , app .FullPath .Join ("customized" ).Join ("data" ).Join ("influx-data" ).Exist (), "Volume directory should exist" )
184186 })
185187
186188 t .Run ("TestPreProvsionVolumesAsStructure" , func (t * testing.T ) {
@@ -210,9 +212,9 @@ services:
210212 }
211213 env := map [string ]string {}
212214 volumes , err := extractVolumesFromComposeFile (volumesFromFile .String ())
213- assert .Nil (t , err , "Failed to extract volumes from compose file" )
215+ require .Nil (t , err , "Failed to extract volumes from compose file" )
214216 provisionComposeVolumes (volumesFromFile .String (), volumes , app , env )
215- assert .True (t , app .FullPath .Join ("data" ).Join ("influx-data" ).Exist (), "Volume directory should exist" )
217+ require .True (t , app .FullPath .Join ("data" ).Join ("influx-data" ).Exist (), "Volume directory should exist" )
216218 })
217219
218220 t .Run ("TestPreProvsionVolumes" , func (t * testing.T ) {
@@ -240,9 +242,9 @@ services:
240242 }
241243 env := map [string ]string {}
242244 volumes , err := extractVolumesFromComposeFile (volumesFromFile .String ())
243- assert .Nil (t , err , "Failed to extract volumes from compose file" )
245+ require .Nil (t , err , "Failed to extract volumes from compose file" )
244246 provisionComposeVolumes (volumesFromFile .String (), volumes , app , env )
245- assert .True (t , app .FullPath .Join ("data" ).Join ("influx-data" ).Exist (), "Volume directory should exist" )
247+ require .True (t , app .FullPath .Join ("data" ).Join ("influx-data" ).Exist (), "Volume directory should exist" )
246248 })
247249
248250}
0 commit comments