-
Notifications
You must be signed in to change notification settings - Fork 0
/
dependencymodel_test.go
96 lines (79 loc) · 1.92 KB
/
dependencymodel_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"bytes"
"os"
"testing"
)
/**/
var DMSecMofExample = "testdata/dependencymodels/secmof/example.dependencymodel"
var DMSecMofGraphML = "testdata/dependencymodels/secmof/example.graphml"
/**/
func TestDMParseFile(t *testing.T) {
}
/**/
func TestDMParseFileGraphML(t *testing.T) {
}
/**/
func TestDMConvertDMtoGraphML(t *testing.T) {
/* 1. Parse DM from SecMof */
dm := DependencyModel{}
if err := dm.ParseFile(DMSecMofExample); err != nil {
t.Fatal(err)
}
/* 2. Convert from DM to GraphML */
var buf bytes.Buffer
gml, err := dm.GraphML()
if err != nil {
t.Fatal(err)
}
if err := gml.Encode(&buf, true); err != nil {
t.Fatal(err)
}
/* 3. Load Golden File */
expected, err := os.ReadFile(DMSecMofGraphML)
if err != nil {
t.Fatal(err)
}
/* 4. Compare */
got := RemoveWS(buf.String())
exp := RemoveWS(string(expected))
if got != exp {
t.Errorf("Generated GraphML from '%s' does not match '%s':", DMSecMofExample, DMSecMofGraphML)
t.Error("Expected:\n", string(exp))
t.Error("Got:\n", buf.String())
}
}
/**/
func TestDMConvertGraphMLtoDM(t *testing.T) {
/* 1. Parse DM from Graphml */
dm := DependencyModel{}
if err := dm.ParseFileGraphML(DMSecMofGraphML); err != nil {
t.Fatal(err)
}
/* 2. Convert from DM to GraphML */
var buf bytes.Buffer
gml, err := dm.GraphML()
if err != nil {
t.Fatal(err)
}
if err := gml.Encode(&buf, true); err != nil {
t.Fatal(err)
}
/* TODO:
* Due to the way the GraphML is generated the order is not preserved.
* An in depth comparison needs to be performed.
*/
/* 3. Load Golden File */
// expected, err := os.ReadFile(DMSecMofGraphML)
// if err != nil {
// t.Fatal(err)
// }
// /* 4. Compare */
// got := len(RemoveWS(buf.String()))
// exp := len(RemoveWS(string(expected)))
// if got != exp {
// t.Error("Generated GraphML does not match:", DMSecMofGraphML)
// t.Error("Expected:\n", exp)
// t.Error("Got:\n", got)
// }
}