-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerator_proto2_test.go
74 lines (60 loc) · 1.53 KB
/
generator_proto2_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
package pbts
import (
"bytes"
"embed"
"testing"
"github.com/octavore/pbts/v2/internal/test"
"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/types/known/structpb"
)
//go:embed fixtures
var fixtures embed.FS
func loadFixture(name string) string {
data, err := fixtures.ReadFile("fixtures/" + name)
if err != nil {
panic(err)
}
return string(data)
}
func TestOutput(t *testing.T) {
buf := &bytes.Buffer{}
g := NewGenerator(buf)
g.RegisterMany(&test.TestMessage{})
g.Write()
expected := loadFixture("TestMessage.ts")
assert.Equal(t, expected, buf.String())
}
func TestEnumOutput(t *testing.T) {
buf := &bytes.Buffer{}
g := NewGenerator(buf)
g.RegisterMany(&test.TestEnumStruct{})
g.Write()
expected := loadFixture("TestEnumStruct.ts")
assert.Equal(t, expected, buf.String())
}
func TestNativeEnumOutput(t *testing.T) {
buf := &bytes.Buffer{}
g := NewGenerator(buf)
g.NativeEnums = true
g.RegisterMany(&test.TestEnumStruct{})
g.Write()
expected := loadFixture("TestNativeEnumStruct.ts")
assert.Equal(t, expected, buf.String())
}
func TestNewProtoStructOutput(t *testing.T) {
buf := &bytes.Buffer{}
g := NewGenerator(buf)
g.NativeEnums = true
g.RegisterMany(&structpb.Struct{})
g.Write()
expected := loadFixture("TestProtoStruct.ts")
assert.Equal(t, expected, buf.String())
}
func TestOneofOutput(t *testing.T) {
buf := &bytes.Buffer{}
g := NewGenerator(buf)
g.RegisterMany(&test.TestOneofStruct{})
g.Write()
expected := loadFixture("TestOneOfStruct.ts")
assert.Equal(t, expected, buf.String())
}