@voxgig/create-sdkgen 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/run-create-sdkgen.js~ +1 -0
- package/package.json +3 -1
- package/tm/standard/.env.local +2 -0
- package/tm/standard/build/sdk.js +25 -0
- package/tm/standard/def/DEFINITION.md +2 -0
- package/tm/standard/model/.model-config/model-config.jsonic +13 -0
- package/tm/standard/model/go.jsonic +6 -0
- package/tm/standard/model/js.jsonic +6 -0
- package/tm/standard/model/php.jsonic +6 -0
- package/tm/standard/model/py.jsonic +7 -0
- package/tm/standard/model/rb.jsonic +6 -0
- package/tm/standard/model/sdk.jsonic.off +60 -0
- package/tm/standard/package.json +30 -0
- package/tm/standard/src/Root.ts +60 -0
- package/tm/standard/src/go/Entity_go.ts +226 -0
- package/tm/standard/src/go/MainEntity_go.ts +26 -0
- package/tm/standard/src/go/Main_go.ts +168 -0
- package/tm/standard/src/go/Quick_go.ts +108 -0
- package/tm/standard/src/go/ReadmeInstall_go.ts +19 -0
- package/tm/standard/src/go/ReadmeQuick_go.ts +45 -0
- package/tm/standard/src/go/TestAcceptEntity_go.ts +219 -0
- package/tm/standard/src/go/TestAccept_go.ts +38 -0
- package/tm/standard/src/go/TestEntity_go.ts +79 -0
- package/tm/standard/src/go/TestMain_go.ts +61 -0
- package/tm/standard/src/go/Test_go.ts +20 -0
- package/tm/standard/src/js/Entity_js.ts +135 -0
- package/tm/standard/src/js/MainEntity_js.ts +22 -0
- package/tm/standard/src/js/Main_js.ts +128 -0
- package/tm/standard/src/js/Quick_js.ts +72 -0
- package/tm/standard/src/js/ReadmeInstall_js.ts +19 -0
- package/tm/standard/src/js/ReadmeQuick_js.ts +27 -0
- package/tm/standard/src/js/TestAcceptEntity_js.ts +101 -0
- package/tm/standard/src/js/TestAccept_js.ts +60 -0
- package/tm/standard/src/js/TestEntity_js.ts +24 -0
- package/tm/standard/src/js/TestMain_js.ts +123 -0
- package/tm/standard/src/js/Test_js.ts +24 -0
- package/tm/standard/src/php/Entity_php.ts +97 -0
- package/tm/standard/src/php/MainEntity_php.ts +43 -0
- package/tm/standard/src/php/Main_php.ts +50 -0
- package/tm/standard/src/php/Quick_php.ts +59 -0
- package/tm/standard/src/php/TestAcceptEntity_php.ts +81 -0
- package/tm/standard/src/php/TestAccept_php.ts +33 -0
- package/tm/standard/src/php/TestEntity_php.ts +64 -0
- package/tm/standard/src/php/TestMain_php.ts +120 -0
- package/tm/standard/src/php/Test_php.ts +21 -0
- package/tm/standard/src/py/Entity_py.ts +98 -0
- package/tm/standard/src/py/MainEntity_py.ts +19 -0
- package/tm/standard/src/py/Main_py.ts +211 -0
- package/tm/standard/src/py/Quick_py.ts +133 -0
- package/tm/standard/src/py/TestAcceptEntity_py.ts +47 -0
- package/tm/standard/src/py/TestAccept_py.ts +77 -0
- package/tm/standard/src/py/TestEntity_py.ts +50 -0
- package/tm/standard/src/py/TestMain_py.ts +103 -0
- package/tm/standard/src/py/Test_py.ts +28 -0
- package/tm/standard/src/rb/Client_rb.ts +142 -0
- package/tm/standard/src/rb/Entity_rb.ts +153 -0
- package/tm/standard/src/rb/Error_rb.ts +56 -0
- package/tm/standard/src/rb/MainEntity_rb.ts +16 -0
- package/tm/standard/src/rb/Main_rb.ts +55 -0
- package/tm/standard/src/rb/Quick_rb.ts +65 -0
- package/tm/standard/src/rb/ReadmeInstall_rb.ts +19 -0
- package/tm/standard/src/rb/ReadmeQuick_rb.ts +30 -0
- package/tm/standard/src/rb/TestAcceptEntity_rb.ts +83 -0
- package/tm/standard/src/rb/TestAccept_rb.ts +45 -0
- package/tm/standard/src/rb/TestEntity_rb.ts +82 -0
- package/tm/standard/src/rb/TestMain_rb.ts +67 -0
- package/tm/standard/src/rb/Test_rb.ts +27 -0
- package/tm/standard/src/tsconfig.json +15 -0
- package/tm/standard/tm/go/.env.example +2 -0
- package/tm/standard/tm/go/LICENSE +22 -0
- package/tm/standard/tm/go/go.mod +5 -0
- package/tm/standard/tm/go/go.sum +2 -0
- package/tm/standard/tm/js/LICENSE +22 -0
- package/tm/standard/tm/js/package.json +17 -0
- package/tm/standard/tm/php/LICENSE +22 -0
- package/tm/standard/tm/py/LICENSE +22 -0
- package/tm/standard/tm/py/MANIFEST.in +4 -0
- package/tm/standard/tm/py/Makefile +14 -0
- package/tm/standard/tm/py/pyproject.toml +4 -0
- package/tm/standard/tm/py/pytest.ini +3 -0
- package/tm/standard/tm/py/requirements.txt +4 -0
- package/tm/standard/tm/py/setup.cfg +2 -0
- package/tm/standard/tm/py/setup.py +82 -0
- package/tm/standard/tm/rb/.rspec +1 -0
- package/tm/standard/tm/rb/Gemfile +21 -0
- package/tm/standard/tm/rb/LICENSE +22 -0
- package/tm/standard/tm/rb/Rakefile +6 -0
- package/tm/standard/tm/rb/spec/spec_helper.rb +22 -0
- package/tm/standard/tm/rb/tm.gemspec +39 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, File, Content } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const Quick = cmp(function Quick(props: any) {
|
|
6
|
+
const { build } = props
|
|
7
|
+
const { model } = props.ctx$
|
|
8
|
+
|
|
9
|
+
File({ name: 'quick_test.' + build.name }, () => {
|
|
10
|
+
|
|
11
|
+
Content(`
|
|
12
|
+
package ${model.name}sdk
|
|
13
|
+
|
|
14
|
+
import (
|
|
15
|
+
"log"
|
|
16
|
+
"os"
|
|
17
|
+
"strings"
|
|
18
|
+
"testing"
|
|
19
|
+
|
|
20
|
+
"github.com/joho/godotenv"
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
func TestQuick(t *testing.T) {
|
|
24
|
+
err := godotenv.Load()
|
|
25
|
+
if err != nil {
|
|
26
|
+
t.Fatal("Error loading .env file for Quick test")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
endpoint := os.Getenv("${model.NAME}_ENDPOINT")
|
|
30
|
+
apikey := os.Getenv("${model.NAME}_APIKEY")
|
|
31
|
+
|
|
32
|
+
var options Options
|
|
33
|
+
options.Apikey = apikey
|
|
34
|
+
options.Endpoint = endpoint
|
|
35
|
+
client, err := Make(options)
|
|
36
|
+
if err != nil {
|
|
37
|
+
t.Fatalf("Error creating a new client Quick: %q", err)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
data := GeofenceData{
|
|
41
|
+
Id: "CF49B47C-317B-4387-83C3-4A23715B1C45",
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
out, err := client.Geofence().Load(data)
|
|
45
|
+
if err != nil {
|
|
46
|
+
t.Fatalf("Error running Quick load method: %q", err)
|
|
47
|
+
}
|
|
48
|
+
log.Print("Geofence.load", out.Data)
|
|
49
|
+
|
|
50
|
+
out2, err := client.Geofence().List()
|
|
51
|
+
if err != nil {
|
|
52
|
+
t.Fatalf("Error running Quick list method: %q", err)
|
|
53
|
+
}
|
|
54
|
+
log.Print("Geofence.list", out2[0].Data, out2[1].Data)
|
|
55
|
+
|
|
56
|
+
if strings.Contains(endpoint, "localhost") {
|
|
57
|
+
//Create Quick Test
|
|
58
|
+
data := GeofenceData{
|
|
59
|
+
Name: "Geofence 1",
|
|
60
|
+
Desc: "Geofence 1 description",
|
|
61
|
+
Extent_id: "CF49B47C-317B-4387-83C3-4A23715B1C45",
|
|
62
|
+
Custom: map[string]any{
|
|
63
|
+
"foo": "bar",
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
out, err := client.Geofence().Create(data)
|
|
67
|
+
if err != nil {
|
|
68
|
+
t.Fatalf("Error running Quick create method: %q", err)
|
|
69
|
+
}
|
|
70
|
+
log.Print("Geofence.create", out.Data)
|
|
71
|
+
|
|
72
|
+
//Save Quick Test
|
|
73
|
+
data = GeofenceData{
|
|
74
|
+
Id: "CF49B47C-317B-4387-83C3-4A23715B1C45",
|
|
75
|
+
Name: "Geofence 1",
|
|
76
|
+
Desc: "Geofence 1 description",
|
|
77
|
+
Extent_id: "CF49B47C-317B-4387-83C3-4A23715B1C45",
|
|
78
|
+
Custom: map[string]any{
|
|
79
|
+
"foo": "bar",
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
out, err = client.Geofence().Save(data)
|
|
83
|
+
if err != nil {
|
|
84
|
+
t.Fatalf("Error running Quick save method: %q", err)
|
|
85
|
+
}
|
|
86
|
+
log.Print("Geofence.save", out.Data)
|
|
87
|
+
|
|
88
|
+
//Remove Quick Test
|
|
89
|
+
data = GeofenceData{
|
|
90
|
+
Id: "CF49B47C-317B-4387-83C3-4A23715B1C45",
|
|
91
|
+
}
|
|
92
|
+
out, err = client.Geofence().Remove(data)
|
|
93
|
+
if err != nil {
|
|
94
|
+
t.Fatalf("Error running Quick remove method: %q", err)
|
|
95
|
+
}
|
|
96
|
+
log.Print("Geofence.remove ", out)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
`)
|
|
100
|
+
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
export {
|
|
106
|
+
Quick
|
|
107
|
+
}
|
|
108
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, Content } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const ReadmeInstall = cmp(function ReadmeInstall(props: any) {
|
|
6
|
+
const { build } = props
|
|
7
|
+
|
|
8
|
+
Content('```go')
|
|
9
|
+
Content(`
|
|
10
|
+
go get ${build.module.name}
|
|
11
|
+
`)
|
|
12
|
+
Content('```')
|
|
13
|
+
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
ReadmeInstall
|
|
19
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, Content } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const ReadmeQuick = cmp(function ReadmeQuick(props: any) {
|
|
6
|
+
const { build, ctx$: { model } } = props
|
|
7
|
+
|
|
8
|
+
Content('```go')
|
|
9
|
+
Content(`
|
|
10
|
+
package main
|
|
11
|
+
|
|
12
|
+
import (
|
|
13
|
+
"log"
|
|
14
|
+
"os"
|
|
15
|
+
|
|
16
|
+
"${build.module.name}"
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
func main() {
|
|
20
|
+
var options ${model.name}sdk.Options
|
|
21
|
+
options.Apikey = os.Getenv("${model.NAME}_APIKEY")
|
|
22
|
+
options.Endpoint = os.Getenv("${model.NAME}_ENDPOINT")
|
|
23
|
+
|
|
24
|
+
client, err := ${model.name}sdk.Make(options)
|
|
25
|
+
if err != nil {
|
|
26
|
+
log.Fatal(err)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
buildings, err := client.Building().List()
|
|
30
|
+
if err != nil {
|
|
31
|
+
log.Println("Error running building list:", err)
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
log.Println("Buildings", buildings)
|
|
36
|
+
}
|
|
37
|
+
`)
|
|
38
|
+
Content('```')
|
|
39
|
+
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
ReadmeQuick
|
|
45
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, each, camelify, Content } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const TestAcceptEntity = cmp(function TestAcceptEntity(props: any) {
|
|
6
|
+
const { model, entity } = props
|
|
7
|
+
|
|
8
|
+
entity.Name = camelify(entity.name)
|
|
9
|
+
|
|
10
|
+
const valueMap: Record<string, any> = {
|
|
11
|
+
"custom": "map[string]any{\"test\": \"test\"}",
|
|
12
|
+
"xval": "rand.Float64()",
|
|
13
|
+
"yval": "rand.Float64()",
|
|
14
|
+
"zval": "rand.Float64()",
|
|
15
|
+
"xlen": "rand.Int()",
|
|
16
|
+
"ylen": "rand.Int()",
|
|
17
|
+
"parent_xlen": "rand.Int()",
|
|
18
|
+
"parent_xval": "rand.Float64()",
|
|
19
|
+
"parent_xyangle": "rand.Float64()",
|
|
20
|
+
"parent_ylen": "rand.Int()",
|
|
21
|
+
"parent_yval": "rand.Float64()",
|
|
22
|
+
"parent_zval": "rand.Float64()",
|
|
23
|
+
"polygon": "struct{Points [][]float64}{[][]float64{{ 1.34},{12.33}}}",
|
|
24
|
+
"has_parent": true,
|
|
25
|
+
"primary": true,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
Content(`
|
|
29
|
+
func Test${entity.Name}AcceptList(t *testing.T) {
|
|
30
|
+
err := godotenv.Load()
|
|
31
|
+
if err != nil {
|
|
32
|
+
t.Fatal("Error loading .env file for Test${entity.Name}AcceptList")
|
|
33
|
+
}
|
|
34
|
+
endpoint := os.Getenv("${model.NAME}_ENDPOINT")
|
|
35
|
+
apikey := os.Getenv("${model.NAME}_APIKEY")
|
|
36
|
+
|
|
37
|
+
var options ${model.name}sdk.Options
|
|
38
|
+
options.Apikey = apikey
|
|
39
|
+
options.Endpoint = endpoint
|
|
40
|
+
client, err := ${model.name}sdk.Make(options)
|
|
41
|
+
if err != nil {
|
|
42
|
+
t.Fatalf("Error creating a new client ${entity.name} list: %q", err)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
entities, err := client.${entity.Name}().List()
|
|
46
|
+
if err != nil {
|
|
47
|
+
t.Fatalf("Error running ${entity.name} list method: %v", err)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if len(entities) == 0 {
|
|
51
|
+
t.Fatalf("Error getting ${entity.name} accept list length == 0 and got %v",
|
|
52
|
+
len(entities))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
got := entities[0].Data
|
|
56
|
+
|
|
57
|
+
if got.Id == "" {
|
|
58
|
+
t.Fatal("Error getting ${entity.name} accept list - id equal to empty string")
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
func Test${entity.Name}AcceptLoad(t *testing.T) {
|
|
64
|
+
err := godotenv.Load()
|
|
65
|
+
if err != nil {
|
|
66
|
+
t.Fatal("Error loading .env file for Test${entity.Name}AcceptLoad")
|
|
67
|
+
}
|
|
68
|
+
endpoint := os.Getenv("${model.NAME}_ENDPOINT")
|
|
69
|
+
apikey := os.Getenv("${model.NAME}_APIKEY")
|
|
70
|
+
|
|
71
|
+
var options ${model.name}sdk.Options
|
|
72
|
+
options.Apikey = apikey
|
|
73
|
+
options.Endpoint = endpoint
|
|
74
|
+
client, err := ${model.name}sdk.Make(options)
|
|
75
|
+
if err != nil {
|
|
76
|
+
t.Fatalf("Error creating a new client ${entity.name} load: %q", err)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
data := ${model.name}sdk.${entity.Name}Data{
|
|
80
|
+
Id: "t01",
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
client${entity.Name}, err := client.${entity.Name}().Load(data)
|
|
84
|
+
if err != nil {
|
|
85
|
+
t.Fatalf("Error running ${entity.name} load method: %v", err)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
got := client${entity.Name}.Data
|
|
89
|
+
|
|
90
|
+
if got.Id == "" {
|
|
91
|
+
t.Fatal("Error getting ${entity.name} accept load - id equal to empty string")
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
func Test${entity.Name}AcceptCreate(t *testing.T) {
|
|
96
|
+
err := godotenv.Load()
|
|
97
|
+
if err != nil {
|
|
98
|
+
t.Fatal("Error loading .env file for Test${entity.Name}AcceptCreate")
|
|
99
|
+
}
|
|
100
|
+
endpoint := os.Getenv("${model.NAME}_ENDPOINT")
|
|
101
|
+
apikey := os.Getenv("${model.NAME}_APIKEY")
|
|
102
|
+
|
|
103
|
+
var options ${model.name}sdk.Options
|
|
104
|
+
options.Apikey = apikey
|
|
105
|
+
options.Endpoint = endpoint
|
|
106
|
+
client, err := ${model.name}sdk.Make(options)
|
|
107
|
+
if err != nil {
|
|
108
|
+
t.Fatalf("Error creating a new client ${entity.name} create: %q", err)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
data := ${model.name}sdk.${entity.Name}Data{
|
|
112
|
+
`)
|
|
113
|
+
each(entity.field, (field: any) => {
|
|
114
|
+
const value = valueMap[field.name] ? valueMap[field.name] : field.type
|
|
115
|
+
|
|
116
|
+
if (value == "string") {
|
|
117
|
+
Content(`
|
|
118
|
+
${field.Name}: "test",
|
|
119
|
+
`)
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
Content(`
|
|
123
|
+
${field.Name}: ${value},
|
|
124
|
+
`)
|
|
125
|
+
})
|
|
126
|
+
Content(`
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
client${entity.Name}, err := client.${entity.Name}().Create(data)
|
|
130
|
+
if err != nil {
|
|
131
|
+
t.Fatalf("Error running ${entity.name} create method: %v", err)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
got := client${entity.Name}.Data
|
|
135
|
+
|
|
136
|
+
if got.Id == "" {
|
|
137
|
+
t.Fatal("Error getting ${entity.name} accept create - id equal to empty string")
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
func Test${entity.Name}AcceptSave(t *testing.T) {
|
|
143
|
+
err := godotenv.Load()
|
|
144
|
+
if err != nil {
|
|
145
|
+
t.Fatal("Error loading .env file for Test${entity.Name}AcceptSave")
|
|
146
|
+
}
|
|
147
|
+
endpoint := os.Getenv("${model.NAME}_ENDPOINT")
|
|
148
|
+
apikey := os.Getenv("${model.NAME}_APIKEY")
|
|
149
|
+
|
|
150
|
+
var options ${model.name}sdk.Options
|
|
151
|
+
options.Apikey = apikey
|
|
152
|
+
options.Endpoint = endpoint
|
|
153
|
+
client, err := ${model.name}sdk.Make(options)
|
|
154
|
+
if err != nil {
|
|
155
|
+
t.Fatalf("Error creating a new client ${entity.name} save: %q", err)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
data := ${model.name}sdk.${entity.Name}Data{
|
|
159
|
+
`)
|
|
160
|
+
each(entity.field, (field: any) => {
|
|
161
|
+
const value = valueMap[field.name] ? valueMap[field.name] : field.type
|
|
162
|
+
|
|
163
|
+
if (value == "string") {
|
|
164
|
+
Content(`
|
|
165
|
+
${field.Name}: "test",
|
|
166
|
+
`)
|
|
167
|
+
return
|
|
168
|
+
}
|
|
169
|
+
Content(`
|
|
170
|
+
${field.Name}: ${value},
|
|
171
|
+
`)
|
|
172
|
+
})
|
|
173
|
+
Content(`
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
client${entity.Name}, err := client.${entity.Name}().Save(data)
|
|
177
|
+
if err != nil {
|
|
178
|
+
t.Fatalf("Error running ${entity.name} save method: %v", err)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
got := client${entity.Name}.Data
|
|
182
|
+
|
|
183
|
+
if got.Id == "" {
|
|
184
|
+
t.Fatal("Error getting ${entity.name} accept create - id equal to empty string")
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
func Test${entity.Name}AcceptRemove(t *testing.T) {
|
|
189
|
+
err := godotenv.Load()
|
|
190
|
+
if err != nil {
|
|
191
|
+
t.Fatal("Error loading .env file for Test${entity.Name}AcceptRemove")
|
|
192
|
+
}
|
|
193
|
+
endpoint := os.Getenv("${model.NAME}_ENDPOINT")
|
|
194
|
+
apikey := os.Getenv("${model.NAME}_APIKEY")
|
|
195
|
+
|
|
196
|
+
var options ${model.name}sdk.Options
|
|
197
|
+
options.Apikey = apikey
|
|
198
|
+
options.Endpoint = endpoint
|
|
199
|
+
client, err := ${model.name}sdk.Make(options)
|
|
200
|
+
if err != nil {
|
|
201
|
+
t.Fatalf("Error creating a new client ${entity.name} remove: %q", err)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
data := ${model.name}sdk.${entity.Name}Data{
|
|
205
|
+
Id: "t01",
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
_, err = client.${entity.Name}().Remove(data)
|
|
209
|
+
if err != nil {
|
|
210
|
+
t.Fatalf("Error running ${entity.name} remove method: %v", err)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
`);
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
export {
|
|
218
|
+
TestAcceptEntity
|
|
219
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, each, File, Content } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
import { TestAcceptEntity } from './TestAcceptEntity_go'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const TestAccept = cmp(function TestAccept(props: any) {
|
|
8
|
+
const { build } = props
|
|
9
|
+
const { model } = props.ctx$
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
File({ name: model.name + 'sdk_accept_test.' + build.name }, () => {
|
|
13
|
+
|
|
14
|
+
Content(`
|
|
15
|
+
package ${model.name}sdk_test
|
|
16
|
+
|
|
17
|
+
import (
|
|
18
|
+
"math/rand"
|
|
19
|
+
"testing"
|
|
20
|
+
"os"
|
|
21
|
+
|
|
22
|
+
"github.com/joho/godotenv"
|
|
23
|
+
"github.com/${model.name}/${model.name}-sdk"
|
|
24
|
+
)
|
|
25
|
+
`)
|
|
26
|
+
|
|
27
|
+
each(model.main.sdk.entity, (entity: any) => {
|
|
28
|
+
TestAcceptEntity({ model, build, entity })
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
TestAccept
|
|
37
|
+
}
|
|
38
|
+
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, camelify, Content } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const TestEntity = cmp(function TestEntity(props: any) {
|
|
6
|
+
const { entity } = props
|
|
7
|
+
|
|
8
|
+
entity.Name = camelify(entity.name)
|
|
9
|
+
|
|
10
|
+
Content(`
|
|
11
|
+
func Test${entity.Name}List(t *testing.T) {
|
|
12
|
+
endpoint := "http://test.com"
|
|
13
|
+
apikey := "apikey"
|
|
14
|
+
want := ${entity.Name}Data{
|
|
15
|
+
Id: "${entity.name}t01",
|
|
16
|
+
Name: "${entity.Name}T01",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var options Options
|
|
20
|
+
options.Apikey = apikey
|
|
21
|
+
options.Endpoint = endpoint
|
|
22
|
+
client, err := Make(options)
|
|
23
|
+
if err != nil {
|
|
24
|
+
t.Fatalf("Error creating a new client ${entity.name} list: %q", err)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
respData := strings.NewReader(\`{"list":[{"id":"${entity.name}t01"},
|
|
28
|
+
{"id":"${entity.name}t02"}]}\`)
|
|
29
|
+
httpClientMock := createHttpClientMock(respData)
|
|
30
|
+
client.httpClient = *httpClientMock
|
|
31
|
+
|
|
32
|
+
entities, err := client.${entity.Name}().List()
|
|
33
|
+
if err != nil {
|
|
34
|
+
t.Fatalf("Error running ${entity.name} list method: %q", err)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
got := entities[0].Data
|
|
38
|
+
if got.Id != want.Id {
|
|
39
|
+
t.Fatalf("Error getting ${entity.name} list want %v and got %v", want, got)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
func Test${entity.Name}Load(t *testing.T) {
|
|
44
|
+
endpoint := "http://test.com"
|
|
45
|
+
apikey := "apikey"
|
|
46
|
+
want := ${entity.Name}Data{
|
|
47
|
+
Id: "${entity.name}t01",
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
var options Options
|
|
51
|
+
options.Apikey = apikey
|
|
52
|
+
options.Endpoint = endpoint
|
|
53
|
+
client, err := Make(options)
|
|
54
|
+
if err != nil {
|
|
55
|
+
t.Fatalf("Error creating a new client ${entity.name} load: %q", err)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
respData := strings.NewReader(fmt.Sprintf(\`{"id":"${entity.name}t01"}\`))
|
|
59
|
+
httpClientMock := createHttpClientMock(respData)
|
|
60
|
+
client.httpClient = *httpClientMock
|
|
61
|
+
|
|
62
|
+
data := want
|
|
63
|
+
client${entity.Name}, err := client.${entity.Name}().Load(data)
|
|
64
|
+
if err != nil {
|
|
65
|
+
t.Fatalf("Error running ${entity.name} load method: %q", err)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
got := client${entity.Name}.Data
|
|
69
|
+
if got.Id != want.Id {
|
|
70
|
+
t.Fatalf("Error getting ${entity.name} load want %v and got %v", want.Id, got.Id)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
`)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
TestEntity
|
|
79
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, each, File, Content } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import { TestEntity } from './TestEntity_go'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const TestMain = cmp(function TestMain(props: any) {
|
|
9
|
+
const { build } = props
|
|
10
|
+
const { model } = props.ctx$
|
|
11
|
+
|
|
12
|
+
File({ name: model.name + 'sdk_test.' + build.name }, () => {
|
|
13
|
+
|
|
14
|
+
Content(`
|
|
15
|
+
package ${model.name}sdk
|
|
16
|
+
|
|
17
|
+
import (
|
|
18
|
+
"fmt"
|
|
19
|
+
"testing"
|
|
20
|
+
"net/http"
|
|
21
|
+
"io"
|
|
22
|
+
"strings"
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
// Mock HTTP Client Transport type.
|
|
26
|
+
// For more info, please see: https://pkg.go.dev/net/http#Client
|
|
27
|
+
// And: https://pkg.go.dev/net/http#RoundTripper
|
|
28
|
+
type fakeService func(*http.Request) (*http.Response, error)
|
|
29
|
+
|
|
30
|
+
func (s fakeService) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
31
|
+
return s(req)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
func createHttpClientMock(respData *strings.Reader) *http.Client {
|
|
35
|
+
return &http.Client{
|
|
36
|
+
Transport: fakeService(func(*http.Request) (*http.Response, error) {
|
|
37
|
+
return &http.Response{
|
|
38
|
+
StatusContent: http.StatusOK,
|
|
39
|
+
Header: http.Header{
|
|
40
|
+
"Content-Type": []string{"application/json"},
|
|
41
|
+
},
|
|
42
|
+
Body: io.NopCloser(respData),
|
|
43
|
+
}, nil
|
|
44
|
+
}),
|
|
45
|
+
}}
|
|
46
|
+
`)
|
|
47
|
+
|
|
48
|
+
each(model.main.sdk.entity, (entity: any) => {
|
|
49
|
+
TestEntity({ model, build, entity })
|
|
50
|
+
})
|
|
51
|
+
Content(`
|
|
52
|
+
`)
|
|
53
|
+
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
export {
|
|
59
|
+
TestMain
|
|
60
|
+
}
|
|
61
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
import { Quick } from './Quick_go'
|
|
5
|
+
import { TestMain } from './TestMain_go'
|
|
6
|
+
import { TestAccept } from './TestAccept_go'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const Test = cmp(function Test(props: any) {
|
|
10
|
+
const { build } = props
|
|
11
|
+
|
|
12
|
+
Quick({ build })
|
|
13
|
+
TestMain({ build })
|
|
14
|
+
TestAccept({ build })
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
Test
|
|
20
|
+
}
|