github.com/imannamdari/v2ray-core/v5@v5.0.5/common/protoext/testing/extension_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  	"google.golang.org/protobuf/reflect/protoreflect"
     8  
     9  	"github.com/imannamdari/v2ray-core/v5/common/protoext"
    10  )
    11  
    12  func TestMessageOpt(t *testing.T) {
    13  	msg := TestingMessage{}
    14  	opt, err := protoext.GetMessageOptions(msg.ProtoReflect().Descriptor())
    15  	assert.Nil(t, err)
    16  	assert.EqualValues(t, []string{"demo", "demo2"}, opt.Type)
    17  }
    18  
    19  func TestFieldOpt(t *testing.T) {
    20  	msg := TestingMessage{
    21  		TestField: "Test",
    22  	}
    23  	msgreflect := msg.ProtoReflect()
    24  	msgreflect.Range(func(descriptor protoreflect.FieldDescriptor, value protoreflect.Value) bool {
    25  		opt, err := protoext.GetFieldOptions(descriptor)
    26  		assert.Nil(t, err)
    27  		assert.EqualValues(t, []string{"test", "test2"}, opt.AllowedValues)
    28  		return true
    29  	})
    30  }