@@ -42,7 +42,7 @@ func TestMPRMetadata(t *testing.T) {
4242
4343func TestMPRUnits (t * testing.T ) {
4444 t .Run ("single-mpr" , func (t * testing.T ) {
45- if err := exportUnits ("./../resources/app-mpr-v1" , "./../tmp" , false , "basic" ); err != nil {
45+ if err := exportUnits ("./../resources/app-mpr-v1" , "./../tmp" , false , "basic" , "" ); err != nil {
4646 t .Errorf ("Failed to export units from MPR file" )
4747 }
4848 })
@@ -51,7 +51,7 @@ func TestMPRUnits(t *testing.T) {
5151func TestIDAttributesExclusion (t * testing.T ) {
5252 t .Run ("verify-id-attributes-excluded" , func (t * testing.T ) {
5353 // Export units with ID attributes excluded
54- if err := exportUnits ("./../resources/app-mpr-v1" , "./../tmp" , false , "basic" ); err != nil {
54+ if err := exportUnits ("./../resources/app-mpr-v1" , "./../tmp" , false , "basic" , "" ); err != nil {
5555 t .Errorf ("Failed to export units from MPR file: %v" , err )
5656 return
5757 }
@@ -98,3 +98,86 @@ func TestIDAttributesExclusion(t *testing.T) {
9898 }
9999 })
100100}
101+
102+ func TestFilterMetadataOnly (t * testing.T ) {
103+ t .Run ("filter-metadata-exact-match" , func (t * testing.T ) {
104+ // Clean up test directory
105+ testDir := "./../tmp-filter-metadata"
106+ os .RemoveAll (testDir )
107+ defer os .RemoveAll (testDir )
108+
109+ // Export with filter ^Metadata$
110+ // According to the code, when filter is "^Metadata$", only metadata is exported, no units
111+ if err := ExportModel ("./../resources/app-mpr-v1" , testDir , false , "basic" , false , "^Metadata$" ); err != nil {
112+ t .Errorf ("Failed to export with Metadata filter: %v" , err )
113+ return
114+ }
115+
116+ // Check that Metadata.yaml exists
117+ metadataPath := filepath .Join (testDir , "Metadata.yaml" )
118+ if _ , err := os .Stat (metadataPath ); os .IsNotExist (err ) {
119+ t .Errorf ("Metadata.yaml was not created" )
120+ return
121+ }
122+
123+ // Check that no other files/directories were created (since filter is ^Metadata$ and units are skipped)
124+ entries , err := os .ReadDir (testDir )
125+ if err != nil {
126+ t .Errorf ("Failed to read test directory: %v" , err )
127+ return
128+ }
129+
130+ // Should only have Metadata.yaml
131+ if len (entries ) != 1 {
132+ t .Errorf ("Expected only Metadata.yaml, but found %d entries" , len (entries ))
133+ return
134+ }
135+
136+ if entries [0 ].Name () != "Metadata.yaml" {
137+ t .Errorf ("Expected Metadata.yaml, but found %s" , entries [0 ].Name ())
138+ }
139+ })
140+ }
141+
142+ func TestFilterConstantPattern (t * testing.T ) {
143+ t .Run ("filter-constant-pattern" , func (t * testing.T ) {
144+ // Clean up test directory
145+ testDir := "./../tmp-filter-constant"
146+ os .RemoveAll (testDir )
147+ defer os .RemoveAll (testDir )
148+
149+ // Export with filter ^Constant.*
150+ // This pattern won't match any documents in the test data, so we should get only metadata
151+ if err := ExportModel ("./../resources/app-mpr-v1" , testDir , false , "basic" , false , "^Constant.*" ); err != nil {
152+ t .Errorf ("Failed to export with Constant filter: %v" , err )
153+ return
154+ }
155+
156+ // Check that Metadata.yaml exists (always exported)
157+ metadataPath := filepath .Join (testDir , "Metadata.yaml" )
158+ if _ , err := os .Stat (metadataPath ); os .IsNotExist (err ) {
159+ t .Errorf ("Metadata.yaml was not created" )
160+ return
161+ }
162+
163+ // Check that no module directories were created (since no documents match the filter)
164+ entries , err := os .ReadDir (testDir )
165+ if err != nil {
166+ t .Errorf ("Failed to read test directory: %v" , err )
167+ return
168+ }
169+
170+ // Should only have Metadata.yaml since no documents match ^Constant.*
171+ if len (entries ) != 1 {
172+ t .Errorf ("Expected only Metadata.yaml when no documents match filter, but found %d entries" , len (entries ))
173+ for _ , entry := range entries {
174+ t .Logf ("Found entry: %s" , entry .Name ())
175+ }
176+ return
177+ }
178+
179+ if entries [0 ].Name () != "Metadata.yaml" {
180+ t .Errorf ("Expected Metadata.yaml, but found %s" , entries [0 ].Name ())
181+ }
182+ })
183+ }
0 commit comments