github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/pkg/fftypes/batch_test.go (about) 1 // Copyright © 2021 Kaleido, Inc. 2 // 3 // SPDX-License-Identifier: Apache-2.0 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 package fftypes 18 19 import ( 20 "encoding/json" 21 "testing" 22 23 "github.com/stretchr/testify/assert" 24 ) 25 26 func TestSQLSerializedMessageArray(t *testing.T) { 27 28 msgID1 := NewUUID() 29 msgID2 := NewUUID() 30 batchPayload := BatchPayload{ 31 Messages: []*Message{ 32 {Header: MessageHeader{ID: msgID1}}, 33 {Header: MessageHeader{ID: msgID2}}, 34 }, 35 } 36 37 b, err := batchPayload.Value() 38 assert.NoError(t, err) 39 assert.IsType(t, []byte{}, b) 40 41 var batchPayloadRead BatchPayload 42 err = batchPayloadRead.Scan(b) 43 assert.NoError(t, err) 44 45 j1, err := json.Marshal(&batchPayload) 46 assert.NoError(t, err) 47 j2, err := json.Marshal(&batchPayloadRead) 48 assert.NoError(t, err) 49 assert.Equal(t, string(j1), string(j2)) 50 51 err = batchPayloadRead.Scan("") 52 assert.NoError(t, err) 53 54 err = batchPayloadRead.Scan(nil) 55 assert.NoError(t, err) 56 57 var wrongType int 58 err = batchPayloadRead.Scan(&wrongType) 59 assert.Error(t, err) 60 61 hash := batchPayload.Hash() 62 assert.NotNil(t, hash) 63 64 }