Skip to content

Commit ea83597

Browse files
committed
exclude ID attribute and update reference model source
1 parent 3f869d8 commit ea83597

42 files changed

Lines changed: 8440 additions & 6496 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎mpr/mpr_test.go‎

Lines changed: 0 additions & 46 deletions
This file was deleted.

‎mpr/mpr_v1_test.go‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// mpr_test.go
2+
package mpr
3+
4+
import (
5+
"fmt"
6+
"os"
7+
"path/filepath"
8+
"strings"
9+
"testing"
10+
11+
"gopkg.in/yaml.v3"
12+
)
13+
14+
// TestAdd tests the Add function to ensure it returns correct results.
15+
func TestMPRMetadata(t *testing.T) {
16+
t.Run("single-mpr", func(t *testing.T) {
17+
if err := exportMetadata("./../resources/app-mpr-v1", "./../tmp", nil); err != nil {
18+
t.Errorf("Failed to export metadata from MPR file")
19+
}
20+
21+
// open metadata file
22+
metadataFile, err := os.ReadFile("./../tmp/Metadata.yaml")
23+
if err != nil {
24+
t.Errorf("Failed to read metadata file")
25+
}
26+
// read metadata file
27+
var metadataObj MxMetadata
28+
var node yaml.Node
29+
if err := yaml.Unmarshal(metadataFile, &node); err != nil {
30+
t.Errorf("Failed to unmarshal metadata file: %v", err)
31+
}
32+
if err := node.Decode(&metadataObj); err != nil {
33+
t.Errorf("Failed to decode metadata file: %v", err)
34+
}
35+
// check metadata
36+
expectedProductVersion := "10.18.3.58900"
37+
if metadataObj.ProductVersion != expectedProductVersion {
38+
t.Errorf("ProductVersion is incorrect. Expected: %s, Got: %s", expectedProductVersion, metadataObj.ProductVersion)
39+
}
40+
})
41+
}
42+
43+
func TestMPRUnits(t *testing.T) {
44+
t.Run("single-mpr", func(t *testing.T) {
45+
if err := exportUnits("./../resources/app-mpr-v1", "./../tmp", false, "basic"); err != nil {
46+
t.Errorf("Failed to export units from MPR file")
47+
}
48+
})
49+
}
50+
51+
func TestIDAttributesExclusion(t *testing.T) {
52+
t.Run("verify-id-attributes-excluded", func(t *testing.T) {
53+
// Export units with ID attributes excluded
54+
if err := exportUnits("./../resources/app-mpr-v1", "./../tmp", false, "basic"); err != nil {
55+
t.Errorf("Failed to export units from MPR file: %v", err)
56+
return
57+
}
58+
59+
// Read a sample unit file
60+
files, err := os.ReadDir("./../tmp/MyFirstModule")
61+
if err != nil {
62+
t.Errorf("Failed to read directory: %v", err)
63+
return
64+
}
65+
66+
// Find a file to test
67+
var filePath string
68+
for _, file := range files {
69+
if !file.IsDir() && strings.HasSuffix(file.Name(), ".yaml") {
70+
filePath = filepath.Join("./../tmp/MyFirstModule", file.Name())
71+
break
72+
}
73+
}
74+
75+
if filePath == "" {
76+
t.Errorf("No unit files found to test")
77+
return
78+
}
79+
80+
// Read the file content
81+
content, err := os.ReadFile(filePath)
82+
if err != nil {
83+
t.Errorf("Failed to read file %s: %v", filePath, err)
84+
return
85+
}
86+
87+
// Check that ID attributes are excluded
88+
contentStr := string(content)
89+
if strings.Contains(contentStr, "\"ID\":") || strings.Contains(contentStr, "\"$ID\":") {
90+
t.Errorf("ID attributes were not excluded from unit document: %s", filePath)
91+
}
92+
93+
// Also check for other ignored attributes
94+
for _, attr := range ignoredAttributes {
95+
if strings.Contains(contentStr, fmt.Sprintf("\"%s\":", attr)) {
96+
t.Errorf("Ignored attribute '%s' was not excluded from unit document: %s", attr, filePath)
97+
}
98+
}
99+
})
100+
}

‎mpr/utils.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func SetLogger(logger *logrus.Logger) {
1717
log = logger
1818
}
1919

20-
var ignoredAttributes = []string{"$ID", "Flows", "OriginPointer", "Type", "LineType", "DestinationPointer", "Image", "ImageData", "GUID", "StableId", "Size", "RelativeMiddlePoint", "Location", "OriginBezierVector", "DestinationBezierVector", "OriginConnectionIndex", "DestinationConnectionIndex"}
20+
var ignoredAttributes = []string{"ID", "$ID", "Flows", "OriginPointer", "Type", "LineType", "DestinationPointer", "Image", "ImageData", "GUID", "StableId", "Size", "RelativeMiddlePoint", "Location", "OriginBezierVector", "DestinationBezierVector", "OriginConnectionIndex", "DestinationConnectionIndex"}
2121

2222
func Contains(slice []string, str string) bool {
2323
for _, item := range slice {

0 commit comments

Comments
 (0)