@@ -205,6 +205,74 @@ func TestFullReloadFlow(t *testing.T) {
205205 })
206206}
207207
208+ func TestReloadWithCloudConfig (t * testing.T ) {
209+ logger := logging .NewTestLogger (t )
210+
211+ manifestPath := createTestManifest (t , "" , nil )
212+ confStruct , err := structpb .NewStruct (map [string ]any {
213+ "modules" : []any {},
214+ })
215+ test .That (t , err , test .ShouldBeNil )
216+
217+ // Create a temporary cloud config file
218+ cloudConfigPath := filepath .Join (t .TempDir (), "viam.json" )
219+ cloudConfigFile , err := os .Create (cloudConfigPath )
220+ test .That (t , err , test .ShouldBeNil )
221+ _ , err = cloudConfigFile .WriteString (`{"cloud":{"app_address":"https://app.viam.com:443","id":"cloud-config-part-id","secret":"SECRET"}}` )
222+ test .That (t , err , test .ShouldBeNil )
223+ test .That (t , cloudConfigFile .Close (), test .ShouldBeNil )
224+
225+ t .Run ("reloadWithCloudConfigLocal" , func (t * testing.T ) {
226+ updateCount := 0
227+ cCtx , vc , _ , _ := setup (
228+ mockFullAppServiceClient (confStruct , nil , & updateCount ),
229+ nil ,
230+ & inject.BuildServiceClient {},
231+ map [string ]any {
232+ moduleFlagPath : manifestPath ,
233+ moduleBuildFlagCloudConfig : cloudConfigPath ,
234+ moduleBuildFlagNoBuild : true ,
235+ moduleFlagLocal : true ,
236+ generalFlagNoProgress : true , // Disable progress spinner to avoid race conditions in tests
237+ },
238+ "token" ,
239+ )
240+ test .That (t , vc .loginAction (cCtx ), test .ShouldBeNil )
241+
242+ // Test that reloadModuleActionInner correctly uses cloud-config to resolve part ID
243+ err = reloadModuleActionInner (cCtx , vc , parseStructFromCtx [reloadModuleArgs ](cCtx ), logger , false )
244+ test .That (t , err , test .ShouldBeNil )
245+ test .That (t , updateCount , test .ShouldEqual , 1 )
246+ })
247+
248+ t .Run ("verifyPartIDResolution" , func (t * testing.T ) {
249+ // Test that the part ID is correctly resolved from cloud-config
250+ // and that args.PartID remains empty when only cloud-config is provided
251+ cCtx , _ , _ , _ := setup (
252+ mockFullAppServiceClient (confStruct , nil , nil ),
253+ nil ,
254+ & inject.BuildServiceClient {},
255+ map [string ]any {
256+ moduleFlagPath : manifestPath ,
257+ moduleBuildFlagCloudConfig : cloudConfigPath ,
258+ moduleBuildFlagNoBuild : true ,
259+ moduleFlagLocal : true ,
260+ },
261+ "token" ,
262+ )
263+
264+ args := parseStructFromCtx [reloadModuleArgs ](cCtx )
265+ // Verify that args.PartID is empty (not set via --part-id flag) and CloudConfig is set
266+ test .That (t , args .PartID , test .ShouldBeEmpty )
267+ test .That (t , args .CloudConfig , test .ShouldEqual , cloudConfigPath )
268+
269+ // Verify that resolvePartID correctly extracts the part ID from the cloud config
270+ partID , err := resolvePartID (args .PartID , args .CloudConfig )
271+ test .That (t , err , test .ShouldBeNil )
272+ test .That (t , partID , test .ShouldEqual , "cloud-config-part-id" )
273+ })
274+ }
275+
208276func TestRestartModule (t * testing.T ) {
209277 t .Skip ("restartModule test requires fake robot client" )
210278}
0 commit comments