github.com/defanghe/fabric@v2.1.1+incompatible/discovery/protoext/querytype_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package protoext_test 8 9 import ( 10 "strconv" 11 "testing" 12 13 "github.com/hyperledger/fabric-protos-go/discovery" 14 "github.com/hyperledger/fabric/discovery/protoext" 15 "github.com/stretchr/testify/assert" 16 ) 17 18 func TestGetQueryType(t *testing.T) { 19 tests := []struct { 20 q *discovery.Query 21 expected protoext.QueryType 22 }{ 23 {q: &discovery.Query{Query: &discovery.Query_PeerQuery{PeerQuery: &discovery.PeerMembershipQuery{}}}, expected: protoext.PeerMembershipQueryType}, 24 {q: &discovery.Query{Query: &discovery.Query_ConfigQuery{ConfigQuery: &discovery.ConfigQuery{}}}, expected: protoext.ConfigQueryType}, 25 {q: &discovery.Query{Query: &discovery.Query_CcQuery{CcQuery: &discovery.ChaincodeQuery{}}}, expected: protoext.ChaincodeQueryType}, 26 {q: &discovery.Query{Query: &discovery.Query_LocalPeers{LocalPeers: &discovery.LocalPeerQuery{}}}, expected: protoext.LocalMembershipQueryType}, 27 {q: &discovery.Query{Query: &discovery.Query_CcQuery{}}, expected: protoext.InvalidQueryType}, 28 {q: nil, expected: protoext.InvalidQueryType}, 29 } 30 31 for i, tt := range tests { 32 t.Run(strconv.Itoa(i), func(t *testing.T) { 33 assert.Equal(t, tt.expected, protoext.GetQueryType(tt.q)) 34 }) 35 } 36 }