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
|
package parser
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseFile(t *testing.T) {
services, err := File("test.proto", "")
assert.NoError(t, err)
assert.Len(t, services, 2)
assert.Equal(t, "app.namespace", services[0].Package)
}
func TestParseFileWithImportsNestedFolder(t *testing.T) {
services, err := File("./test_nested/test_import.proto", "./test_nested")
assert.NoError(t, err)
assert.Len(t, services, 2)
assert.Equal(t, "app.namespace", services[0].Package)
}
func TestParseFileWithImports(t *testing.T) {
services, err := File("test_import.proto", ".")
assert.NoError(t, err)
assert.Len(t, services, 2)
assert.Equal(t, "app.namespace", services[0].Package)
}
func TestParseNotFound(t *testing.T) {
_, err := File("test2.proto", "")
assert.Error(t, err)
}
func TestParseBytes(t *testing.T) {
services, err := Bytes([]byte{})
assert.NoError(t, err)
assert.Len(t, services, 0)
}
func TestParseString(t *testing.T) {
services, err := Bytes([]byte(`
syntax = "proto3";
package app.namespace;
// Ping Service.
service PingService {
// Ping Method.
rpc Ping (Message) returns (Message) {
}
}
// Pong service.
service PongService {
rpc Pong (stream Message) returns (stream Message) {
}
}
message Message {
string msg = 1;
int64 value = 2;
}
`))
assert.NoError(t, err)
assert.Len(t, services, 2)
assert.Equal(t, "app.namespace", services[0].Package)
}
|