github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/libkbfs/disk_block_cache_helper_test.go (about) 1 package libkbfs 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/keybase/client/go/kbfs/kbfscodec" 8 "github.com/keybase/client/go/kbfs/tlf" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func makeTime(data []byte) time.Time { 13 var t time.Time 14 err := t.UnmarshalBinary(data) 15 if err != nil { 16 panic(err) 17 } 18 return t 19 } 20 21 var testLRUTime = makeTime([]byte{ 22 // Version. 23 0x1, 24 // Seconds. 25 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 26 // Nanoseconds. 27 0xa, 0xb, 0xc, 0xd, 28 // Zone offset. 29 0xe, 0xf, 30 }) 31 32 var testMetaDb = DiskBlockCacheMetadata{ 33 TlfID: tlf.FakeID(1, tlf.Public), 34 LRUTime: legacyEncodedTime{testLRUTime}, 35 BlockSize: 0xface, 36 FinishedPrefetch: true, 37 Tag: "mark", 38 } 39 40 // This was generated by starting with []byte{} in 41 // TestDiskBlockCacheMetadataEncodeHardcoded and copying the data in 42 // the error message for its require.Equal. 43 var testMetaDbEncoded = []byte{ 44 0x86, 0xa9, 0x42, 0x6c, 0x6f, 0x63, 45 0x6b, 0x53, 0x69, 0x7a, 0x65, 0xcd, 0xfa, 0xce, 0xb0, 0x46, 46 0x69, 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x50, 0x72, 0x65, 47 0x66, 0x65, 0x74, 0x63, 0x68, 0xc3, 0xad, 0x48, 0x61, 0x73, 48 0x50, 0x72, 0x65, 0x66, 0x65, 0x74, 0x63, 0x68, 0x65, 0x64, 49 0xc2, 0xa7, 0x4c, 0x52, 0x55, 0x54, 0x69, 0x6d, 0x65, 0xc4, 50 0xf, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 51 0xc, 0xd, 0xe, 0xf, 0xa3, 0x54, 0x61, 0x67, 0xa4, 0x6d, 0x61, 52 0x72, 0x6b, 0xa5, 0x54, 0x6c, 0x66, 0x49, 0x44, 0xc4, 0x10, 53 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 54 0x0, 0x17, 55 } 56 57 func TestDiskBlockCacheMetadataEncodeHardcoded(t *testing.T) { 58 codec := kbfscodec.NewMsgpack() 59 60 bytes, err := codec.Encode(testMetaDb) 61 require.NoError(t, err) 62 require.Equal(t, testMetaDbEncoded, bytes) 63 } 64 65 func TestDiskBlockCacheMetadataDecodeHardcoded(t *testing.T) { 66 codec := kbfscodec.NewMsgpack() 67 68 var metaDb DiskBlockCacheMetadata 69 err := codec.Decode(testMetaDbEncoded, &metaDb) 70 require.NoError(t, err) 71 72 require.Equal(t, testMetaDb, metaDb) 73 }