-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
executable file
·44 lines (37 loc) · 1010 Bytes
/
main_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
package main
import (
"github.com/stretchr/testify/assert"
"math"
"testing"
)
func TestGenerateProtobufDefinition(t *testing.T) {
filePath := "testdata/example.go"
structName := "MyStruct"
expected := `message MyStruct {
int32 field1 = 1;
string field2 = 2;
bool field3 = 3;
repeated int64 field4 = 4;
message NestedStruct {
int32 field1 = 1;
string field2 = 2;
bool field3 = 3;
repeated int64 field4 = 4;
}
NestedStruct nested = 5;
}`
result, err := generateProtobufDefinition(filePath, structName, 0, math.MaxInt)
if err != nil {
t.Fatalf("Error generating protobuf definition: %s", err)
}
if result != expected {
t.Errorf("Generated protobuf definition does not match.\nExpected:\n%s\nActual:\n%s", expected, result)
}
}
func TestGenerateProtobufDefinitionPanic(t *testing.T) {
filePath := "testdata/example.go"
structName := "MyStructRecursive"
assert.Panics(t, func() {
_, _ = generateProtobufDefinition(filePath, structName, 0, math.MaxInt)
})
}