@@ -5,6 +5,7 @@ package executor
55import (
66 "testing"
77
8+ "github.com/mendixlabs/mxcli/mdl/ast"
89 "github.com/mendixlabs/mxcli/mdl/backend/mock"
910 "github.com/mendixlabs/mxcli/mdl/types"
1011 "github.com/mendixlabs/mxcli/model"
@@ -33,3 +34,68 @@ func TestShowJsonStructures_Mock(t *testing.T) {
3334 assertContainsStr (t , out , "json Structure" )
3435 assertContainsStr (t , out , "OrderMgmt.OrderSchema" )
3536}
37+
38+ func TestShowJsonStructures_FilterByModule (t * testing.T ) {
39+ mod1 := mkModule ("OrderMgmt" )
40+ mod2 := mkModule ("Other" )
41+ js1 := & types.JsonStructure {
42+ BaseElement : model.BaseElement {ID : nextID ("js" )},
43+ ContainerID : mod1 .ID ,
44+ Name : "OrderSchema" ,
45+ }
46+ js2 := & types.JsonStructure {
47+ BaseElement : model.BaseElement {ID : nextID ("js" )},
48+ ContainerID : mod2 .ID ,
49+ Name : "OtherSchema" ,
50+ }
51+
52+ h := mkHierarchy (mod1 , mod2 )
53+ withContainer (h , js1 .ContainerID , mod1 .ID )
54+ withContainer (h , js2 .ContainerID , mod2 .ID )
55+
56+ mb := & mock.MockBackend {
57+ IsConnectedFunc : func () bool { return true },
58+ ListJsonStructuresFunc : func () ([]* types.JsonStructure , error ) { return []* types.JsonStructure {js1 , js2 }, nil },
59+ }
60+
61+ ctx , buf := newMockCtx (t , withBackend (mb ), withHierarchy (h ))
62+ assertNoError (t , listJsonStructures (ctx , "OrderMgmt" ))
63+
64+ out := buf .String ()
65+ assertContainsStr (t , out , "OrderMgmt.OrderSchema" )
66+ assertNotContainsStr (t , out , "Other.OtherSchema" )
67+ }
68+
69+ func TestDescribeJsonStructure_Mock (t * testing.T ) {
70+ mod := mkModule ("OrderMgmt" )
71+ js := & types.JsonStructure {
72+ BaseElement : model.BaseElement {ID : nextID ("js" )},
73+ ContainerID : mod .ID ,
74+ Name : "OrderSchema" ,
75+ }
76+
77+ h := mkHierarchy (mod )
78+ withContainer (h , js .ContainerID , mod .ID )
79+
80+ mb := & mock.MockBackend {
81+ IsConnectedFunc : func () bool { return true },
82+ ListJsonStructuresFunc : func () ([]* types.JsonStructure , error ) { return []* types.JsonStructure {js }, nil },
83+ }
84+
85+ ctx , buf := newMockCtx (t , withBackend (mb ), withHierarchy (h ))
86+ assertNoError (t , describeJsonStructure (ctx , ast.QualifiedName {Module : "OrderMgmt" , Name : "OrderSchema" }))
87+ assertContainsStr (t , buf .String (), "create or replace json structure" )
88+ }
89+
90+ func TestDescribeJsonStructure_NotFound (t * testing.T ) {
91+ mod := mkModule ("OrderMgmt" )
92+ h := mkHierarchy (mod )
93+
94+ mb := & mock.MockBackend {
95+ IsConnectedFunc : func () bool { return true },
96+ ListJsonStructuresFunc : func () ([]* types.JsonStructure , error ) { return nil , nil },
97+ }
98+
99+ ctx , _ := newMockCtx (t , withBackend (mb ), withHierarchy (h ))
100+ assertError (t , describeJsonStructure (ctx , ast.QualifiedName {Module : "OrderMgmt" , Name : "NoSuch" }))
101+ }
0 commit comments