From a371ae78e5280f0a2075692dbb2cfeed4c39bddb Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 30 Aug 2022 01:39:24 -0600 Subject: misc fix --- .../btrfsinspect/rebuildnodes/s3_reinit_test.go | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 lib/btrfsprogs/btrfsinspect/rebuildnodes/s3_reinit_test.go (limited to 'lib/btrfsprogs/btrfsinspect/rebuildnodes/s3_reinit_test.go') diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/s3_reinit_test.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/s3_reinit_test.go new file mode 100644 index 0000000..b361606 --- /dev/null +++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/s3_reinit_test.go @@ -0,0 +1,80 @@ +// Copyright (C) 2022 Luke Shumaker +// +// SPDX-License-Identifier: GPL-2.0-or-later + +package rebuildnodes_test + +import ( + "strings" + "testing" + + "git.lukeshu.com/go/lowmemjson" + "github.com/stretchr/testify/assert" + + "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsprim" + "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfstree" + "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsvol" + "git.lukeshu.com/btrfs-progs-ng/lib/btrfsprogs/btrfsinspect/rebuildnodes" + "git.lukeshu.com/btrfs-progs-ng/lib/containers" +) + +func TestEncodeRebuiltNodes(t *testing.T) { + dat := map[btrfsvol.LogicalAddr]*rebuildnodes.RebuiltNode{ + 100007133184: { + Errs: containers.Set[string]{ + "btrfs.ReadNode: node@0x0000001748e3c000: expected generation\u003c=6596014 but claims to be generation=6596025": struct{}{}, + }, + MinKey: btrfsprim.Key{}, + MaxKey: btrfsprim.Key{}, + InTrees: containers.Set[btrfsprim.ObjID]{ + 257: struct{}{}, + }, + Node: btrfstree.Node{}, + }, + } + var buf strings.Builder + assert.NoError(t, lowmemjson.Encode(&lowmemjson.ReEncoder{ + Out: &buf, + + Indent: "\t", + ForceTrailingNewlines: true, + }, dat)) + assert.Equal(t, `{ + "100007133184": { + "Errs": [ + "btrfs.ReadNode: node@0x0000001748e3c000: expected generation\u003c=6596014 but claims to be generation=6596025" + ], + "MinKey": { + "ObjectID": 0, + "ItemType": 0, + "Offset": 0 + }, + "MaxKey": { + "ObjectID": 0, + "ItemType": 0, + "Offset": 0 + }, + "InTrees": [ + 257 + ], + "Size": 0, + "ChecksumType": 0, + "Head": { + "Checksum": "0000000000000000000000000000000000000000000000000000000000000000", + "MetadataUUID": "00000000-0000-0000-0000-000000000000", + "Addr": 0, + "Flags": 0, + "BackrefRev": 0, + "ChunkTreeUUID": "00000000-0000-0000-0000-000000000000", + "Generation": 0, + "Owner": 0, + "NumItems": 0, + "Level": 0 + }, + "BodyInternal": null, + "BodyLeaf": null, + "Padding": null + } +} +`, buf.String()) +} -- cgit v1.2.3-2-g168b