1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-02 23:47:07 -05:00
v2fly/common/protoext/testing/extension_test.go

31 lines
773 B
Go
Raw Normal View History

2021-06-23 04:52:33 -04:00
package testing
import (
2021-10-28 06:34:19 -04:00
"testing"
2021-06-23 04:52:33 -04:00
"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/reflect/protoreflect"
2021-10-28 06:34:19 -04:00
"github.com/v2fly/v2ray-core/v5/common/protoext"
2021-06-23 04:52:33 -04:00
)
func TestMessageOpt(t *testing.T) {
msg := TestingMessage{}
opt, err := protoext.GetMessageOptions(msg.ProtoReflect().Descriptor())
assert.Nil(t, err)
assert.EqualValues(t, []string{"demo", "demo2"}, opt.Type)
}
func TestFieldOpt(t *testing.T) {
msg := TestingMessage{
TestField: "Test",
}
msgreflect := msg.ProtoReflect()
msgreflect.Range(func(descriptor protoreflect.FieldDescriptor, value protoreflect.Value) bool {
opt, err := protoext.GetFieldOptions(descriptor)
assert.Nil(t, err)
assert.EqualValues(t, []string{"test", "test2"}, opt.AllowedValues)
return true
})
}