github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/bfs/meta_block_test.go (about) 1 // Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn . 2 3 package bfs_test 4 5 import ( 6 "bytes" 7 "github.com/TeaOSLab/EdgeNode/internal/utils/bfs" 8 "github.com/iwind/TeaGo/assert" 9 "testing" 10 ) 11 12 func TestMetaBlock(t *testing.T) { 13 var a = assert.NewAssertion(t) 14 15 { 16 var srcHash = bfs.Hash("a") 17 b, err := bfs.EncodeMetaBlock(bfs.MetaActionNew, srcHash, []byte{1, 2, 3}) 18 if err != nil { 19 t.Fatal(err) 20 } 21 t.Log(b) 22 23 { 24 action, hash, data, decodeErr := bfs.DecodeMetaBlock(b) 25 if decodeErr != nil { 26 t.Fatal(err) 27 } 28 a.IsTrue(action == bfs.MetaActionNew) 29 a.IsTrue(hash == srcHash) 30 a.IsTrue(bytes.Equal(data, []byte{1, 2, 3})) 31 } 32 } 33 34 { 35 var srcHash = bfs.Hash("bcd") 36 37 b, err := bfs.EncodeMetaBlock(bfs.MetaActionRemove, srcHash, []byte{1, 2, 3}) 38 if err != nil { 39 t.Fatal(err) 40 } 41 t.Log(b) 42 { 43 action, hash, data, decodeErr := bfs.DecodeMetaBlock(b) 44 if decodeErr != nil { 45 t.Fatal(err) 46 } 47 a.IsTrue(action == bfs.MetaActionRemove) 48 a.IsTrue(hash == srcHash) 49 a.IsTrue(len(data) == 0) 50 } 51 } 52 }