-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgenerator_test.go
55 lines (46 loc) · 1.35 KB
/
generator_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
package xml
import (
"os"
"path/filepath"
"testing"
"github.com/vmkteam/mfd-generator/generators/testdata"
. "github.com/smartystreets/goconvey/convey"
)
// todo: panic if ../testdata/actual/*.mfd exists and xml not exist
func TestGenerator_Generate(t *testing.T) {
// Store the PATH environment variable in a variable
dbdsn, exists := os.LookupEnv("DB_DSN")
if !exists {
dbdsn = "postgres://postgres:postgres@localhost:5432/newsportal?sslmode=disable"
}
Convey("TestGenerator_Generate", t, func() {
Convey("Check correct generate", func() {
generator := New()
generator.options.Def()
generator.options.URL = dbdsn
generator.options.Output = testdata.PathActualMFD
generator.options.Packages = parseNamespacesFlag("portal:news,categories,tags")
t.Log("Generate xml")
err := generator.Generate()
So(err, ShouldBeNil)
})
Convey("Check generated files", func() {
expectedFilenames := map[string]struct{}{
"portal.xml": {},
"newsportal.mfd": {},
}
for f := range expectedFilenames {
t.Logf("Check %s file", f)
content, err := os.ReadFile(filepath.Join(testdata.PathActual, f))
if err != nil {
t.Fatal(err)
}
expectedContent, err := os.ReadFile(filepath.Join(testdata.PathExpected, f))
if err != nil {
t.Fatal(err)
}
So(content, ShouldResemble, expectedContent)
}
})
})
}