github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/grpc/internal/proto/grpc_service_config/example_test.go (about)

     1  /*
     2   *
     3   * Copyright 2019 gRPC authors.
     4   *
     5   * Licensed under the Apache License, Version 2.0 (the "License");
     6   * you may not use this file except in compliance with the License.
     7   * You may obtain a copy of the License at
     8   *
     9   *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  
    18  package grpc_service_config_test
    19  
    20  import (
    21  	"testing"
    22  
    23  	"github.com/golang/protobuf/jsonpb"
    24  	wrapperspb "github.com/golang/protobuf/ptypes/wrappers"
    25  	"github.com/hxx258456/ccgo/grpc/internal/grpctest"
    26  	scpb "github.com/hxx258456/ccgo/grpc/internal/proto/grpc_service_config"
    27  )
    28  
    29  type s struct {
    30  	grpctest.Tester
    31  }
    32  
    33  func Test(t *testing.T) {
    34  	grpctest.RunSubTests(t, s{})
    35  }
    36  
    37  // TestXdsConfigMarshalToJSON is an example to print json format of xds_config.
    38  func (s) TestXdsConfigMarshalToJSON(t *testing.T) {
    39  	c := &scpb.XdsConfig{
    40  		ChildPolicy: []*scpb.LoadBalancingConfig{
    41  			{Policy: &scpb.LoadBalancingConfig_Grpclb{
    42  				Grpclb: &scpb.GrpcLbConfig{},
    43  			}},
    44  			{Policy: &scpb.LoadBalancingConfig_RoundRobin{
    45  				RoundRobin: &scpb.RoundRobinConfig{},
    46  			}},
    47  		},
    48  		FallbackPolicy: []*scpb.LoadBalancingConfig{
    49  			{Policy: &scpb.LoadBalancingConfig_Grpclb{
    50  				Grpclb: &scpb.GrpcLbConfig{},
    51  			}},
    52  			{Policy: &scpb.LoadBalancingConfig_PickFirst{
    53  				PickFirst: &scpb.PickFirstConfig{},
    54  			}},
    55  		},
    56  		EdsServiceName: "eds.service.name",
    57  		LrsLoadReportingServerName: &wrapperspb.StringValue{
    58  			Value: "lrs.server.name",
    59  		},
    60  	}
    61  	j, err := (&jsonpb.Marshaler{}).MarshalToString(c)
    62  	if err != nil {
    63  		t.Fatalf("failed to marshal proto to json: %v", err)
    64  	}
    65  	t.Logf(j)
    66  }