-
Notifications
You must be signed in to change notification settings - Fork 5
/
asyncapi_test.go
125 lines (119 loc) · 2.38 KB
/
asyncapi_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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package main
import (
"io/ioutil"
"os"
"os/exec"
"testing"
)
func TestAsyncApi(t *testing.T) {
testAPI := func(file, role string) {
t.Log(file)
current, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
defer func() {
err = os.Chdir(current)
if err != nil {
t.Fatal(err)
}
}()
tmp, err := ioutil.TempDir("", "generate_api")
if err != nil {
t.Fatal(err)
}
t.Log(tmp)
cmd := exec.Command("./asyncapi", "-input", file, "-type", "flogoapiapp", "-role", role, "-output", tmp)
err = cmd.Run()
if err != nil {
t.Fatal(err)
}
err = os.Chdir(tmp)
if err != nil {
t.Fatal(err)
}
cmd = exec.Command("go", "build")
err = cmd.Run()
if err != nil {
t.Fatal(err)
}
err = os.RemoveAll(tmp)
if err != nil {
t.Fatal(err)
}
}
testJSON := func(file, role string) {
t.Log(file)
current, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
defer func() {
err = os.Chdir(current)
if err != nil {
t.Fatal(err)
}
}()
tmp, err := ioutil.TempDir("", "generate_json")
if err != nil {
t.Fatal(err)
}
t.Log(tmp)
cmd := exec.Command("./asyncapi", "-input", file, "-type", "flogodescriptor", "-role", role, "-output", tmp)
err = cmd.Run()
if err != nil {
t.Fatal(err)
}
err = os.Chdir(tmp)
if err != nil {
t.Fatal(err)
}
cmd = exec.Command("flogo", "create", "app")
err = cmd.Run()
if err != nil {
t.Fatal(err)
}
cmd = exec.Command("mv", "support.go", "app/src")
err = cmd.Run()
if err != nil {
t.Fatal(err)
}
err = os.Chdir("app")
if err != nil {
t.Fatal(err)
}
cmd = exec.Command("flogo", "build")
err = cmd.Run()
if err != nil {
t.Fatal(err)
}
err = os.RemoveAll(tmp)
if err != nil {
t.Fatal(err)
}
}
cmd := exec.Command("go", "build")
err := cmd.Run()
if err != nil {
t.Fatal(err)
}
files := [...]string{
"examples/eftl/asyncapi.yml",
"examples/eftl/asyncapi_secure.yml",
"examples/http/asyncapi.yml",
"examples/http/asyncapi_secure.yml",
"examples/kafka/asyncapi.yml",
"examples/kafka/asyncapi_secure.yml",
"examples/mqtt/asyncapi.yml",
"examples/mqtt/asyncapi_secure.yml",
"examples/websocket/asyncapi.yml",
"examples/websocket/asyncapi_secure.yml",
"examples/streetlights/streetlights.yml",
}
for _, file := range files {
testAPI(file, "server")
testJSON(file, "server")
testAPI(file, "client")
testJSON(file, "client")
}
}