Skip to content

Commit dccb33d

Browse files
committed
test: expand mock tests for pages, security, write_handlers, agenteditor
1 parent b3f4ea0 commit dccb33d

6 files changed

Lines changed: 490 additions & 4 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_entities_mock_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,13 @@ func TestShowEntities_BackendError_Modules(t *testing.T) {
7070
}
7171

7272
func TestShowEntities_BackendError(t *testing.T) {
73+
mod := mkModule("Sales")
7374
mb := &mock.MockBackend{
74-
IsConnectedFunc: func() bool { return true },
75-
ListDomainModelsFunc: func() ([]*domainmodel.DomainModel, error) { return nil, fmt.Errorf("backend down") },
75+
IsConnectedFunc: func() bool { return true },
76+
ListModulesFunc: func() ([]*model.Module, error) { return []*model.Module{mod}, nil },
77+
ListDomainModelsFunc: func() ([]*domainmodel.DomainModel, error) {
78+
return nil, fmt.Errorf("backend down")
79+
},
7680
}
7781
ctx, _ := newMockCtx(t, withBackend(mb))
7882
assertError(t, listEntities(ctx, ""))

mdl/executor/cmd_lint_mock_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ func TestLint_NotConnected(t *testing.T) {
2626
// ---------------------------------------------------------------------------
2727
// listLintRules — ShowRules happy path
2828
//
29-
// The ShowRules=true path calls listLintRules which only needs ctx.Output.
30-
// It prints built-in rules (ID + Name + Description + Category + Severity).
29+
// Although listLintRules itself only writes to ctx.Output, execLint currently
30+
// checks ctx.Connected() before dispatching to the ShowRules branch, so this
31+
// test still needs a connected backend. It prints built-in rules
32+
// (ID + Name + Description + Category + Severity).
3133
// ---------------------------------------------------------------------------
3234

3335
func TestLint_ShowRules(t *testing.T) {

mdl/executor/cmd_pages_mock_test.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package executor
55
import (
66
"testing"
77

8+
"github.com/mendixlabs/mxcli/mdl/ast"
89
"github.com/mendixlabs/mxcli/mdl/backend/mock"
910
"github.com/mendixlabs/mxcli/sdk/pages"
1011
)
@@ -52,6 +53,91 @@ func TestShowPages_Mock_FilterByModule(t *testing.T) {
5253
assertContainsStr(t, out, "HR.EmployeeList")
5354
}
5455

56+
func TestShowSnippets_Mock_FilterByModule(t *testing.T) {
57+
mod1 := mkModule("Sales")
58+
mod2 := mkModule("HR")
59+
snp1 := mkSnippet(mod1.ID, "OrderHeader")
60+
snp2 := mkSnippet(mod2.ID, "EmployeeCard")
61+
62+
h := mkHierarchy(mod1, mod2)
63+
withContainer(h, snp1.ContainerID, mod1.ID)
64+
withContainer(h, snp2.ContainerID, mod2.ID)
65+
66+
mb := &mock.MockBackend{
67+
IsConnectedFunc: func() bool { return true },
68+
ListSnippetsFunc: func() ([]*pages.Snippet, error) { return []*pages.Snippet{snp1, snp2}, nil },
69+
}
70+
71+
ctx, buf := newMockCtx(t, withBackend(mb), withHierarchy(h))
72+
assertNoError(t, listSnippets(ctx, "HR"))
73+
74+
out := buf.String()
75+
assertNotContainsStr(t, out, "Sales.OrderHeader")
76+
assertContainsStr(t, out, "HR.EmployeeCard")
77+
}
78+
79+
func TestShowLayouts_Mock_FilterByModule(t *testing.T) {
80+
mod1 := mkModule("Sales")
81+
mod2 := mkModule("HR")
82+
lay1 := mkLayout(mod1.ID, "SalesLayout")
83+
lay2 := mkLayout(mod2.ID, "HRLayout")
84+
85+
h := mkHierarchy(mod1, mod2)
86+
withContainer(h, lay1.ContainerID, mod1.ID)
87+
withContainer(h, lay2.ContainerID, mod2.ID)
88+
89+
mb := &mock.MockBackend{
90+
IsConnectedFunc: func() bool { return true },
91+
ListLayoutsFunc: func() ([]*pages.Layout, error) { return []*pages.Layout{lay1, lay2}, nil },
92+
}
93+
94+
ctx, buf := newMockCtx(t, withBackend(mb), withHierarchy(h))
95+
assertNoError(t, listLayouts(ctx, "HR"))
96+
97+
out := buf.String()
98+
assertNotContainsStr(t, out, "Sales.SalesLayout")
99+
assertContainsStr(t, out, "HR.HRLayout")
100+
}
101+
102+
func TestDescribePage_Mock_NotFound(t *testing.T) {
103+
mod := mkModule("MyModule")
104+
h := mkHierarchy(mod)
105+
106+
mb := &mock.MockBackend{
107+
IsConnectedFunc: func() bool { return true },
108+
ListPagesFunc: func() ([]*pages.Page, error) { return []*pages.Page{}, nil },
109+
}
110+
111+
ctx, _ := newMockCtx(t, withBackend(mb), withHierarchy(h))
112+
assertError(t, describePage(ctx, ast.QualifiedName{Module: "MyModule", Name: "NonExistent"}))
113+
}
114+
115+
func TestDescribeSnippet_Mock_NotFound(t *testing.T) {
116+
mod := mkModule("MyModule")
117+
h := mkHierarchy(mod)
118+
119+
mb := &mock.MockBackend{
120+
IsConnectedFunc: func() bool { return true },
121+
ListSnippetsFunc: func() ([]*pages.Snippet, error) { return []*pages.Snippet{}, nil },
122+
}
123+
124+
ctx, _ := newMockCtx(t, withBackend(mb), withHierarchy(h))
125+
assertError(t, describeSnippet(ctx, ast.QualifiedName{Module: "MyModule", Name: "NonExistent"}))
126+
}
127+
128+
func TestDescribeLayout_Mock_NotFound(t *testing.T) {
129+
mod := mkModule("MyModule")
130+
h := mkHierarchy(mod)
131+
132+
mb := &mock.MockBackend{
133+
IsConnectedFunc: func() bool { return true },
134+
ListLayoutsFunc: func() ([]*pages.Layout, error) { return []*pages.Layout{}, nil },
135+
}
136+
137+
ctx, _ := newMockCtx(t, withBackend(mb), withHierarchy(h))
138+
assertError(t, describeLayout(ctx, ast.QualifiedName{Module: "MyModule", Name: "NonExistent"}))
139+
}
140+
55141
func TestShowSnippets_Mock(t *testing.T) {
56142
mod := mkModule("MyModule")
57143
snp := mkSnippet(mod.ID, "Header")

0 commit comments

Comments
 (0)