@@ -13,33 +13,34 @@ import (
13
13
// todo: add generator.options.Output for generate to actual directory. Now it generate in expected dir where located .mfd
14
14
// todo: not generate if *.vt.xml not exists, but err == nil
15
15
func TestGenerator_Generate (t * testing.T ) {
16
- err := prepareFiles ()
16
+ actualDir := t .TempDir ()
17
+ err := prepareFiles (actualDir )
17
18
if err != nil {
18
19
t .Fatal (err )
19
20
}
21
+ mfdPathInActual := filepath .Join (actualDir , filepath .Base (testdata .PathExpectedMFD ))
20
22
21
23
Convey ("TestGenerator_Generate" , t , func () {
22
24
Convey ("Generate with Entity flag" , func () {
23
25
generator := New ()
24
- generator .options .MFDPath = filepath . Join ( testdata . PathActualMFD )
26
+ generator .options .MFDPath = mfdPathInActual
25
27
generator .options .Entities = []string {"category" }
26
28
27
29
t .Log ("Generate only entity news xml-vt" )
28
30
err = generator .Generate ()
29
31
So (err , ShouldBeNil )
30
32
31
33
t .Logf ("Check %s file" , "en-one-entity.xml" )
32
- content , err := os .ReadFile (filepath .Join (testdata . PathActual , "en.xml" ))
34
+ content , err := os .ReadFile (filepath .Join (actualDir , "en.xml" ))
33
35
So (err , ShouldBeNil )
34
36
expectedContent , err := os .ReadFile (filepath .Join (testdata .PathExpected , "en-one-entity.xml" ))
35
37
So (err , ShouldBeNil )
36
38
So (content , ShouldResemble , expectedContent )
37
-
38
39
})
39
40
40
41
Convey ("Check correct generate" , func () {
41
42
generator := New ()
42
- generator .options .MFDPath = testdata . PathActualMFD
43
+ generator .options .MFDPath = mfdPathInActual
43
44
44
45
t .Log ("Generate xml-vt" )
45
46
err = generator .Generate ()
@@ -53,7 +54,7 @@ func TestGenerator_Generate(t *testing.T) {
53
54
54
55
for f := range expectedFilenames {
55
56
t .Logf ("Check %s file" , f )
56
- content , err := os .ReadFile (filepath .Join (testdata . PathActual , f ))
57
+ content , err := os .ReadFile (filepath .Join (actualDir , f ))
57
58
So (err , ShouldBeNil )
58
59
expectedContent , err := os .ReadFile (filepath .Join (testdata .PathExpected , f ))
59
60
So (err , ShouldBeNil )
@@ -63,29 +64,18 @@ func TestGenerator_Generate(t *testing.T) {
63
64
})
64
65
}
65
66
66
- func prepareFiles () error {
67
- // clearing actual test data
68
- err := os .RemoveAll (testdata .PathActual )
69
- if err != nil {
70
- return err
71
- }
72
-
73
- err = os .MkdirAll (testdata .PathActual , 0775 )
74
- if err != nil {
75
- return err
76
- }
77
-
78
- err = os .Link (testdata .PathExpectedMFD , testdata .PathActualMFD )
67
+ func prepareFiles (actualPath string ) error {
68
+ err := os .Link (testdata .PathExpectedMFD , filepath .Join (actualPath , filepath .Base (testdata .PathExpectedMFD )))
79
69
if err != nil && ! os .IsExist (err ) {
80
70
return err
81
71
}
82
72
83
- err = os .Link (filepath .Join (testdata .PathExpected , testdata .FilenameXML ), filepath .Join (testdata . PathActual , testdata .FilenameXML ))
73
+ err = os .Link (filepath .Join (testdata .PathExpected , testdata .FilenameXML ), filepath .Join (actualPath , testdata .FilenameXML ))
84
74
if err != nil && ! os .IsExist (err ) {
85
75
return err
86
76
}
87
77
88
- err = os .Link (filepath .Join (testdata .PathExpected , testdata .FilenameVTXML ), filepath .Join (testdata . PathActual , testdata .FilenameVTXML ))
78
+ err = os .Link (filepath .Join (testdata .PathExpected , testdata .FilenameVTXML ), filepath .Join (actualPath , testdata .FilenameVTXML ))
89
79
if err != nil && ! os .IsExist (err ) {
90
80
return err
91
81
}
0 commit comments