github.com/turingchain2020/turingchain@v1.1.21/client/mock_consensus_test.go (about)

     1  // Copyright Turing Corp. 2018 All Rights Reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package client_test
     6  
     7  import (
     8  	"github.com/turingchain2020/turingchain/queue"
     9  	"github.com/turingchain2020/turingchain/types"
    10  )
    11  
    12  type mockConsensus struct {
    13  }
    14  
    15  func (m *mockConsensus) SetQueueClient(q queue.Queue) {
    16  	go func() {
    17  		consensusKey := "consensus"
    18  		client := q.Client()
    19  		client.Sub(consensusKey)
    20  		for msg := range client.Recv() {
    21  			switch msg.Ty {
    22  			case types.EventGetTicketCount:
    23  				msg.Reply(client.NewMessage(consensusKey, types.EventReplyGetTicketCount, &types.Int64{}))
    24  			case types.EventConsensusQuery:
    25  				msg.Reply(client.NewMessage(consensusKey, types.EventReplyQuery, &types.Reply{}))
    26  			default:
    27  				msg.ReplyErr("Do not support", types.ErrNotSupport)
    28  			}
    29  		}
    30  	}()
    31  }
    32  
    33  func (m *mockConsensus) Close() {
    34  }