33package executor
44
55import (
6+ "fmt"
67 "testing"
78
89 "github.com/mendixlabs/mxcli/mdl/backend/mock"
@@ -15,16 +16,12 @@ func TestShowModules_Mock(t *testing.T) {
1516 mod1 := mkModule ("MyModule" )
1617 mod2 := mkModule ("System" )
1718
18- // listModules uses ListUnits to count documents per module.
19- // Provide a unit belonging to mod1 so the count is non-zero.
2019 unitID := nextID ("unit" )
2120 units := []* types.UnitInfo {{ID : unitID , ContainerID : mod1 .ID }}
2221
23- // Need a hierarchy for getHierarchy — provide modules + units + folders
2422 h := mkHierarchy (mod1 , mod2 )
2523 withContainer (h , unitID , mod1 .ID )
2624
27- // Provide one domain model for mod1 with one entity
2825 ent := mkEntity (mod1 .ID , "Customer" )
2926 dm := mkDomainModel (mod1 .ID , ent )
3027
@@ -33,7 +30,6 @@ func TestShowModules_Mock(t *testing.T) {
3330 ListModulesFunc : func () ([]* model.Module , error ) { return []* model.Module {mod1 , mod2 }, nil },
3431 ListUnitsFunc : func () ([]* types.UnitInfo , error ) { return units , nil },
3532 ListDomainModelsFunc : func () ([]* domainmodel.DomainModel , error ) { return []* domainmodel.DomainModel {dm }, nil },
36- // All other list functions return nil (zero counts) via MockBackend defaults.
3733 }
3834
3935 ctx , buf := newMockCtx (t , withBackend (mb ), withHierarchy (h ))
@@ -44,3 +40,31 @@ func TestShowModules_Mock(t *testing.T) {
4440 assertContainsStr (t , out , "System" )
4541 assertContainsStr (t , out , "(2 modules)" )
4642}
43+
44+ // Not-connected covered in cmd_notconnected_mock_test.go
45+
46+ func TestShowModules_BackendError (t * testing.T ) {
47+ mb := & mock.MockBackend {
48+ IsConnectedFunc : func () bool { return true },
49+ ListModulesFunc : func () ([]* model.Module , error ) { return nil , fmt .Errorf ("connection lost" ) },
50+ }
51+ ctx , _ := newMockCtx (t , withBackend (mb ), withHierarchy (mkHierarchy ()))
52+ assertError (t , listModules (ctx ))
53+ }
54+
55+ func TestShowModules_JSON (t * testing.T ) {
56+ mod := mkModule ("App" )
57+ h := mkHierarchy (mod )
58+
59+ mb := & mock.MockBackend {
60+ IsConnectedFunc : func () bool { return true },
61+ ListModulesFunc : func () ([]* model.Module , error ) { return []* model.Module {mod }, nil },
62+ ListUnitsFunc : func () ([]* types.UnitInfo , error ) { return nil , nil },
63+ ListDomainModelsFunc : func () ([]* domainmodel.DomainModel , error ) { return nil , nil },
64+ }
65+
66+ ctx , buf := newMockCtx (t , withBackend (mb ), withHierarchy (h ), withFormat (FormatJSON ))
67+ assertNoError (t , listModules (ctx ))
68+ assertValidJSON (t , buf .String ())
69+ assertContainsStr (t , buf .String (), "App" )
70+ }
0 commit comments