-
Notifications
You must be signed in to change notification settings - Fork 6
/
generator_test.go
109 lines (98 loc) · 2.75 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
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
package generator
import (
assert2 "github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"testing"
)
var (
txt = `
// You use definitions from old.proto and new.proto, but not other.proto
option java_package = "com.example.foo";
//go_package_prefix
option go_package = "com.example.foo";
option cc_enable_arenas = true;
import "myproject/other_protos.proto";
message SearchRequest {
extend Foo {
optional int32 bar = 126;
}
repeated int32 bar = 126;
required string query = 1;
// You use definitions from old.proto and new.proto, but not other.proto
optional int32 page_number = 2 [packed=true];
optional int32 result_per_page = 3 [packed=true];
float d1=4;
message MiddleAA { // Level 1
float d1=4;
}
message MiddleBB { // Level 1
}
message MiddleCC { // Level 1
}
extensions 100 to 199;
oneof test_oneof {
string name = 4;
SubMessage sub_message = 9;
}
}
oneof test_oneof {
string name = 4;
SubMessage sub_message = 9;
}
message OutDD { // Level 1
}
service CollaborativeMutationService {
rpc GetUidMutation(CollaborativeMutationRequest) returns (CollaborativeMutationResponse);
rpc GetUidMutationCategory(CollaborativeMutationRequest) returns (CollaborativeMutationResponse);
}
`
)
func TestProtoToBreeze(t *testing.T) {
assert := assert2.New(t)
txt = protoToBreeze(txt)
for _, v := range []string{
"double", "float ", "uint32", "uint64", "sint32", "sint64", "fixed32", "fixed64", "sfixed32", "sfixed64",
"oneof", "extensions", "MiddleCC", "MiddleBB", "MiddleAA", "optional", "required", "//", "extend", "import",
} {
assert.NotContains(txt, v)
}
for _, v := range []string{
"message OutDD {", "message SearchRequest {", "}", "go_package_prefix","CollaborativeMutationRequest request",
} {
assert.Contains(txt, v)
}
//fmt.Println(txt)
}
func TestProtoToBreeze_1(t *testing.T) {
assert := assert2.New(t)
root := ".test_ProtoToBreeze_1"
src := root + "/src"
dest := root + "/dest"
os.RemoveAll(root)
os.MkdirAll(src, 0755)
os.MkdirAll(dest, 0755)
ioutil.WriteFile(src+"/any.proto",[]byte(txt),0755)
assert.DirExists(src)
assert.DirExists(dest)
assert.FileExists(src+"/any.proto")
ProtoToBreeze(src,dest)
assert.FileExists(dest+"/any.breeze")
os.RemoveAll(root)
}
//func TestProtoToBreeze_2(t *testing.T) {
// root := ".test_ProtoToBreeze_1"
// src := "/Users/user/Desktop/test/proto"
// dest := root + "/dest"
// os.RemoveAll(root)
// os.MkdirAll(dest, 0755)
// ProtoToBreeze(src,dest)
//}
//
//func TestProtoToBreeze_3(t *testing.T) {
// os.RemoveAll("auto")
// config := &Config{WritePath: "auto", CodeTemplates: "all", Options: make(map[string]string)}
// config.Options[core.WithPackageDir] = "true"
// _,err:=GeneratePath(".test_ProtoToBreeze_1/dest", config)
// fmt.Println(err)
//}