github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/communication/codec_fake.go (about) 1 /* 2 * Copyright (C) 2017 The "MysteriumNetwork/node" Authors. 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 package communication 19 20 // NewCodecFake returns codec which: 21 // - allows to mock encoded/decoded payloads 22 func NewCodecFake() *codecFake { 23 return &codecFake{} 24 } 25 26 type codecFake struct { 27 PackLastPayload interface{} 28 packMock []byte 29 30 UnpackLastData []byte 31 unpackMock interface{} 32 } 33 34 func (codec *codecFake) MockPackResult(data []byte) { 35 codec.packMock = data 36 } 37 38 func (codec *codecFake) MockUnpackResult(payload interface{}) { 39 codec.unpackMock = payload 40 } 41 42 func (codec *codecFake) Pack(payloadPtr interface{}) ([]byte, error) { 43 codec.PackLastPayload = payloadPtr 44 45 return codec.packMock, nil 46 } 47 48 func (codec *codecFake) Unpack(data []byte, payloadPtr interface{}) error { 49 codec.UnpackLastData = data 50 51 payloadPtr = codec.unpackMock 52 return nil 53 }