Skip to content

Commit 96a5d9e

Browse files
authored
Merge pull request #254 from retran/test/handler-mock-expand
test: expand mock tests for 28 executor handler files
2 parents 3289265 + dccb33d commit 96a5d9e

29 files changed

Lines changed: 1482 additions & 7 deletions

mdl/executor/cmd_agenteditor_mock_test.go

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,3 +526,179 @@ func TestDescribeAgentEditorConsumedMCPService_Mock(t *testing.T) {
526526
assertContainsStr(t, out, "create consumed mcp service")
527527
assertContainsStr(t, out, "ProtocolVersion")
528528
}
529+
530+
// ---------------------------------------------------------------------------
531+
// DESCRIBE — Not Found
532+
// ---------------------------------------------------------------------------
533+
534+
func TestDescribeAgentEditorModel_Mock_NotFound(t *testing.T) {
535+
mod := mkModule("M")
536+
h := mkHierarchy(mod)
537+
538+
mb := &mock.MockBackend{
539+
IsConnectedFunc: func() bool { return true },
540+
ListAgentEditorModelsFunc: func() ([]*agenteditor.Model, error) { return nil, nil },
541+
}
542+
ctx, _ := newMockCtx(t, withBackend(mb), withHierarchy(h))
543+
assertError(t, describeAgentEditorModel(ctx, ast.QualifiedName{Module: "M", Name: "NonExistent"}))
544+
}
545+
546+
func TestDescribeAgentEditorAgent_Mock_NotFound(t *testing.T) {
547+
mod := mkModule("M")
548+
h := mkHierarchy(mod)
549+
550+
mb := &mock.MockBackend{
551+
IsConnectedFunc: func() bool { return true },
552+
ListAgentEditorAgentsFunc: func() ([]*agenteditor.Agent, error) { return nil, nil },
553+
}
554+
ctx, _ := newMockCtx(t, withBackend(mb), withHierarchy(h))
555+
assertError(t, describeAgentEditorAgent(ctx, ast.QualifiedName{Module: "M", Name: "NonExistent"}))
556+
}
557+
558+
func TestDescribeAgentEditorKnowledgeBase_Mock_NotFound(t *testing.T) {
559+
mod := mkModule("M")
560+
h := mkHierarchy(mod)
561+
562+
mb := &mock.MockBackend{
563+
IsConnectedFunc: func() bool { return true },
564+
ListAgentEditorKnowledgeBasesFunc: func() ([]*agenteditor.KnowledgeBase, error) { return nil, nil },
565+
}
566+
ctx, _ := newMockCtx(t, withBackend(mb), withHierarchy(h))
567+
assertError(t, describeAgentEditorKnowledgeBase(ctx, ast.QualifiedName{Module: "M", Name: "NonExistent"}))
568+
}
569+
570+
func TestDescribeAgentEditorConsumedMCPService_Mock_NotFound(t *testing.T) {
571+
mod := mkModule("M")
572+
h := mkHierarchy(mod)
573+
574+
mb := &mock.MockBackend{
575+
IsConnectedFunc: func() bool { return true },
576+
ListAgentEditorConsumedMCPServicesFunc: func() ([]*agenteditor.ConsumedMCPService, error) { return nil, nil },
577+
}
578+
ctx, _ := newMockCtx(t, withBackend(mb), withHierarchy(h))
579+
assertError(t, describeAgentEditorConsumedMCPService(ctx, ast.QualifiedName{Module: "M", Name: "NonExistent"}))
580+
}
581+
582+
// ---------------------------------------------------------------------------
583+
// DROP — Not Found
584+
// ---------------------------------------------------------------------------
585+
586+
func TestDropAgentEditorModel_Mock_NotFound(t *testing.T) {
587+
mod := mkModule("M")
588+
h := mkHierarchy(mod)
589+
590+
mb := &mock.MockBackend{
591+
IsConnectedFunc: func() bool { return true },
592+
ListAgentEditorModelsFunc: func() ([]*agenteditor.Model, error) { return nil, nil },
593+
}
594+
ctx, _ := newMockCtx(t, withBackend(mb), withHierarchy(h))
595+
assertError(t, execDropAgentEditorModel(ctx, &ast.DropModelStmt{
596+
Name: ast.QualifiedName{Module: "M", Name: "NonExistent"},
597+
}))
598+
}
599+
600+
func TestDropConsumedMCPService_Mock_NotFound(t *testing.T) {
601+
mod := mkModule("M")
602+
h := mkHierarchy(mod)
603+
604+
mb := &mock.MockBackend{
605+
IsConnectedFunc: func() bool { return true },
606+
ListAgentEditorConsumedMCPServicesFunc: func() ([]*agenteditor.ConsumedMCPService, error) { return nil, nil },
607+
}
608+
ctx, _ := newMockCtx(t, withBackend(mb), withHierarchy(h))
609+
assertError(t, execDropConsumedMCPService(ctx, &ast.DropConsumedMCPServiceStmt{
610+
Name: ast.QualifiedName{Module: "M", Name: "NonExistent"},
611+
}))
612+
}
613+
614+
func TestDropKnowledgeBase_Mock_NotFound(t *testing.T) {
615+
mod := mkModule("M")
616+
h := mkHierarchy(mod)
617+
618+
mb := &mock.MockBackend{
619+
IsConnectedFunc: func() bool { return true },
620+
ListAgentEditorKnowledgeBasesFunc: func() ([]*agenteditor.KnowledgeBase, error) { return nil, nil },
621+
}
622+
ctx, _ := newMockCtx(t, withBackend(mb), withHierarchy(h))
623+
assertError(t, execDropKnowledgeBase(ctx, &ast.DropKnowledgeBaseStmt{
624+
Name: ast.QualifiedName{Module: "M", Name: "NonExistent"},
625+
}))
626+
}
627+
628+
func TestDropAgent_Mock_NotFound(t *testing.T) {
629+
mod := mkModule("M")
630+
h := mkHierarchy(mod)
631+
632+
mb := &mock.MockBackend{
633+
IsConnectedFunc: func() bool { return true },
634+
ListAgentEditorAgentsFunc: func() ([]*agenteditor.Agent, error) { return nil, nil },
635+
}
636+
ctx, _ := newMockCtx(t, withBackend(mb), withHierarchy(h))
637+
assertError(t, execDropAgent(ctx, &ast.DropAgentStmt{
638+
Name: ast.QualifiedName{Module: "M", Name: "NonExistent"},
639+
}))
640+
}
641+
642+
// ---------------------------------------------------------------------------
643+
// LIST — Filter by Module
644+
// ---------------------------------------------------------------------------
645+
646+
func TestShowAgentEditorModels_Mock_FilterByModule(t *testing.T) {
647+
mod1 := mkModule("A")
648+
mod2 := mkModule("B")
649+
m1 := &agenteditor.Model{
650+
BaseElement: model.BaseElement{ID: nextID("aem")},
651+
ContainerID: mod1.ID,
652+
Name: "M1",
653+
}
654+
m2 := &agenteditor.Model{
655+
BaseElement: model.BaseElement{ID: nextID("aem")},
656+
ContainerID: mod2.ID,
657+
Name: "M2",
658+
}
659+
660+
h := mkHierarchy(mod1, mod2)
661+
withContainer(h, m1.ContainerID, mod1.ID)
662+
withContainer(h, m2.ContainerID, mod2.ID)
663+
664+
mb := &mock.MockBackend{
665+
IsConnectedFunc: func() bool { return true },
666+
ListAgentEditorModelsFunc: func() ([]*agenteditor.Model, error) { return []*agenteditor.Model{m1, m2}, nil },
667+
}
668+
ctx, buf := newMockCtx(t, withBackend(mb), withHierarchy(h))
669+
assertNoError(t, listAgentEditorModels(ctx, "B"))
670+
671+
out := buf.String()
672+
assertNotContainsStr(t, out, "A.M1")
673+
assertContainsStr(t, out, "B.M2")
674+
}
675+
676+
func TestShowAgentEditorAgents_Mock_FilterByModule(t *testing.T) {
677+
mod1 := mkModule("A")
678+
mod2 := mkModule("B")
679+
a1 := &agenteditor.Agent{
680+
BaseElement: model.BaseElement{ID: nextID("aea")},
681+
ContainerID: mod1.ID,
682+
Name: "Agent1",
683+
}
684+
a2 := &agenteditor.Agent{
685+
BaseElement: model.BaseElement{ID: nextID("aea")},
686+
ContainerID: mod2.ID,
687+
Name: "Agent2",
688+
}
689+
690+
h := mkHierarchy(mod1, mod2)
691+
withContainer(h, a1.ContainerID, mod1.ID)
692+
withContainer(h, a2.ContainerID, mod2.ID)
693+
694+
mb := &mock.MockBackend{
695+
IsConnectedFunc: func() bool { return true },
696+
ListAgentEditorAgentsFunc: func() ([]*agenteditor.Agent, error) { return []*agenteditor.Agent{a1, a2}, nil },
697+
}
698+
ctx, buf := newMockCtx(t, withBackend(mb), withHierarchy(h))
699+
assertNoError(t, listAgentEditorAgents(ctx, "B"))
700+
701+
out := buf.String()
702+
assertNotContainsStr(t, out, "A.Agent1")
703+
assertContainsStr(t, out, "B.Agent2")
704+
}

mdl/executor/cmd_associations_mock_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package executor
44

55
import (
6+
"fmt"
67
"testing"
78

89
"github.com/mendixlabs/mxcli/mdl/backend/mock"
@@ -75,3 +76,40 @@ func TestShowAssociations_Mock_FilterByModule(t *testing.T) {
7576
assertContainsStr(t, out, "HR.Employee_Dept")
7677
assertContainsStr(t, out, "(1 associations)")
7778
}
79+
80+
// NOTE: listAssociations and describeAssociation have no Connected() guard.
81+
// They call backend directly — error propagation is the only failure mode.
82+
83+
func TestShowAssociations_BackendError(t *testing.T) {
84+
mb := &mock.MockBackend{
85+
IsConnectedFunc: func() bool { return true },
86+
ListModulesFunc: func() ([]*model.Module, error) { return nil, fmt.Errorf("connection lost") },
87+
}
88+
ctx, _ := newMockCtx(t, withBackend(mb))
89+
assertError(t, listAssociations(ctx, ""))
90+
}
91+
92+
func TestShowAssociations_JSON(t *testing.T) {
93+
mod := mkModule("App")
94+
ent1 := mkEntity(mod.ID, "A")
95+
ent2 := mkEntity(mod.ID, "B")
96+
assoc := mkAssociation(mod.ID, "A_B", ent1.ID, ent2.ID)
97+
98+
dm := &domainmodel.DomainModel{
99+
BaseElement: model.BaseElement{ID: nextID("dm")},
100+
ContainerID: mod.ID,
101+
Entities: []*domainmodel.Entity{ent1, ent2},
102+
Associations: []*domainmodel.Association{assoc},
103+
}
104+
105+
mb := &mock.MockBackend{
106+
IsConnectedFunc: func() bool { return true },
107+
ListModulesFunc: func() ([]*model.Module, error) { return []*model.Module{mod}, nil },
108+
ListDomainModelsFunc: func() ([]*domainmodel.DomainModel, error) { return []*domainmodel.DomainModel{dm}, nil },
109+
}
110+
111+
ctx, buf := newMockCtx(t, withBackend(mb), withFormat(FormatJSON))
112+
assertNoError(t, listAssociations(ctx, ""))
113+
assertValidJSON(t, buf.String())
114+
assertContainsStr(t, buf.String(), "A_B")
115+
}

mdl/executor/cmd_businessevents_mock_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,36 @@ func TestDescribeBusinessEventService_Mock(t *testing.T) {
7777
assertContainsStr(t, out, "create or replace business event service")
7878
assertContainsStr(t, out, "MyModule.OrderEvents")
7979
}
80+
81+
func TestDescribeBusinessEventService_NotFound(t *testing.T) {
82+
mb := &mock.MockBackend{
83+
IsConnectedFunc: func() bool { return true },
84+
ListBusinessEventServicesFunc: func() ([]*model.BusinessEventService, error) {
85+
return nil, nil
86+
},
87+
}
88+
ctx, _ := newMockCtx(t, withBackend(mb))
89+
assertError(t, describeBusinessEventService(ctx, ast.QualifiedName{Module: "X", Name: "NoSuch"}))
90+
}
91+
92+
func TestShowBusinessEventServices_FilterByModule(t *testing.T) {
93+
mod := mkModule("Orders")
94+
svc := &model.BusinessEventService{
95+
BaseElement: model.BaseElement{ID: nextID("bes")},
96+
ContainerID: mod.ID,
97+
Name: "OrderEvents",
98+
}
99+
h := mkHierarchy(mod)
100+
withContainer(h, svc.ContainerID, mod.ID)
101+
102+
mb := &mock.MockBackend{
103+
IsConnectedFunc: func() bool { return true },
104+
ListBusinessEventServicesFunc: func() ([]*model.BusinessEventService, error) {
105+
return []*model.BusinessEventService{svc}, nil
106+
},
107+
}
108+
109+
ctx, buf := newMockCtx(t, withBackend(mb), withHierarchy(h))
110+
assertNoError(t, listBusinessEventServices(ctx, "Orders"))
111+
assertContainsStr(t, buf.String(), "Orders.OrderEvents")
112+
}

mdl/executor/cmd_constants_mock_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,6 @@ func TestDescribeConstant_Mock_NotFound(t *testing.T) {
104104
err := describeConstant(ctx, ast.QualifiedName{Module: "MyModule", Name: "Missing"})
105105
assertError(t, err)
106106
}
107+
108+
// Backend error: cmd_error_mock_test.go (TestShowConstants_Mock_BackendError)
109+
// JSON: cmd_json_mock_test.go (TestShowConstants_Mock_JSON)

mdl/executor/cmd_datatransformer_mock_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,52 @@ func TestListDataTransformers_Mock(t *testing.T) {
3535
assertContainsStr(t, out, "ETL.TransformOrders")
3636
}
3737

38+
func TestListDataTransformers_FilterByModule(t *testing.T) {
39+
mod1 := mkModule("ETL")
40+
mod2 := mkModule("Other")
41+
dt1 := &model.DataTransformer{
42+
BaseElement: model.BaseElement{ID: nextID("dt")},
43+
ContainerID: mod1.ID,
44+
Name: "TransformOrders",
45+
SourceType: "Entity",
46+
}
47+
dt2 := &model.DataTransformer{
48+
BaseElement: model.BaseElement{ID: nextID("dt")},
49+
ContainerID: mod2.ID,
50+
Name: "TransformCustomers",
51+
SourceType: "Entity",
52+
}
53+
54+
h := mkHierarchy(mod1, mod2)
55+
withContainer(h, dt1.ContainerID, mod1.ID)
56+
withContainer(h, dt2.ContainerID, mod2.ID)
57+
58+
mb := &mock.MockBackend{
59+
IsConnectedFunc: func() bool { return true },
60+
ListDataTransformersFunc: func() ([]*model.DataTransformer, error) { return []*model.DataTransformer{dt1, dt2}, nil },
61+
}
62+
63+
ctx, buf := newMockCtx(t, withBackend(mb), withHierarchy(h))
64+
assertNoError(t, listDataTransformers(ctx, "ETL"))
65+
66+
out := buf.String()
67+
assertContainsStr(t, out, "ETL.TransformOrders")
68+
assertNotContainsStr(t, out, "Other.TransformCustomers")
69+
}
70+
71+
func TestDescribeDataTransformer_NotFound(t *testing.T) {
72+
mod := mkModule("ETL")
73+
h := mkHierarchy(mod)
74+
75+
mb := &mock.MockBackend{
76+
IsConnectedFunc: func() bool { return true },
77+
ListDataTransformersFunc: func() ([]*model.DataTransformer, error) { return nil, nil },
78+
}
79+
80+
ctx, _ := newMockCtx(t, withBackend(mb), withHierarchy(h))
81+
assertError(t, describeDataTransformer(ctx, ast.QualifiedName{Module: "ETL", Name: "NoSuch"}))
82+
}
83+
3884
func TestDescribeDataTransformer_Mock(t *testing.T) {
3985
mod := mkModule("ETL")
4086
dt := &model.DataTransformer{

mdl/executor/cmd_dbconnection_mock_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,52 @@ func TestShowDatabaseConnections_Mock(t *testing.T) {
3535
assertContainsStr(t, out, "DataMod.MyDB")
3636
}
3737

38+
func TestShowDatabaseConnections_FilterByModule(t *testing.T) {
39+
mod1 := mkModule("DataMod")
40+
mod2 := mkModule("Other")
41+
conn1 := &model.DatabaseConnection{
42+
BaseElement: model.BaseElement{ID: nextID("dbc")},
43+
ContainerID: mod1.ID,
44+
Name: "MyDB",
45+
DatabaseType: "PostgreSQL",
46+
}
47+
conn2 := &model.DatabaseConnection{
48+
BaseElement: model.BaseElement{ID: nextID("dbc")},
49+
ContainerID: mod2.ID,
50+
Name: "OtherDB",
51+
DatabaseType: "MySQL",
52+
}
53+
54+
h := mkHierarchy(mod1, mod2)
55+
withContainer(h, conn1.ContainerID, mod1.ID)
56+
withContainer(h, conn2.ContainerID, mod2.ID)
57+
58+
mb := &mock.MockBackend{
59+
IsConnectedFunc: func() bool { return true },
60+
ListDatabaseConnectionsFunc: func() ([]*model.DatabaseConnection, error) { return []*model.DatabaseConnection{conn1, conn2}, nil },
61+
}
62+
63+
ctx, buf := newMockCtx(t, withBackend(mb), withHierarchy(h))
64+
assertNoError(t, listDatabaseConnections(ctx, "DataMod"))
65+
66+
out := buf.String()
67+
assertContainsStr(t, out, "DataMod.MyDB")
68+
assertNotContainsStr(t, out, "Other.OtherDB")
69+
}
70+
71+
func TestDescribeDatabaseConnection_NotFound(t *testing.T) {
72+
mod := mkModule("DataMod")
73+
h := mkHierarchy(mod)
74+
75+
mb := &mock.MockBackend{
76+
IsConnectedFunc: func() bool { return true },
77+
ListDatabaseConnectionsFunc: func() ([]*model.DatabaseConnection, error) { return nil, nil },
78+
}
79+
80+
ctx, _ := newMockCtx(t, withBackend(mb), withHierarchy(h))
81+
assertError(t, describeDatabaseConnection(ctx, ast.QualifiedName{Module: "DataMod", Name: "NoSuch"}))
82+
}
83+
3884
func TestDescribeDatabaseConnection_Mock(t *testing.T) {
3985
mod := mkModule("DataMod")
4086
conn := &model.DatabaseConnection{

0 commit comments

Comments
 (0)