diff options
Diffstat (limited to 'lib/btrfs/internal')
-rw-r--r-- | lib/btrfs/internal/uuid.go | 6 | ||||
-rw-r--r-- | lib/btrfs/internal/uuid_test.go | 16 |
2 files changed, 12 insertions, 10 deletions
diff --git a/lib/btrfs/internal/uuid.go b/lib/btrfs/internal/uuid.go index a16d10f..3749b1a 100644 --- a/lib/btrfs/internal/uuid.go +++ b/lib/btrfs/internal/uuid.go @@ -2,12 +2,14 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -package util +package internal import ( "encoding/hex" "fmt" "strings" + + "git.lukeshu.com/btrfs-progs-ng/lib/fmtutil" ) type UUID [16]byte @@ -33,7 +35,7 @@ func (a UUID) Cmp(b UUID) int { } func (uuid UUID) Format(f fmt.State, verb rune) { - FormatByteArrayStringer(uuid, uuid[:], f, verb) + fmtutil.FormatByteArrayStringer(uuid, uuid[:], f, verb) } func ParseUUID(str string) (UUID, error) { diff --git a/lib/btrfs/internal/uuid_test.go b/lib/btrfs/internal/uuid_test.go index 747ff6b..dfc3688 100644 --- a/lib/btrfs/internal/uuid_test.go +++ b/lib/btrfs/internal/uuid_test.go @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -package util_test +package internal_test import ( "fmt" @@ -10,18 +10,18 @@ import ( "github.com/stretchr/testify/assert" - "git.lukeshu.com/btrfs-progs-ng/lib/util" + "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/internal" ) func TestParseUUID(t *testing.T) { t.Parallel() type TestCase struct { Input string - OutputVal util.UUID + OutputVal internal.UUID OutputErr string } testcases := map[string]TestCase{ - "basic": {Input: "a0dd94ed-e60c-42e8-8632-64e8d4765a43", OutputVal: util.UUID{0xa0, 0xdd, 0x94, 0xed, 0xe6, 0x0c, 0x42, 0xe8, 0x86, 0x32, 0x64, 0xe8, 0xd4, 0x76, 0x5a, 0x43}}, + "basic": {Input: "a0dd94ed-e60c-42e8-8632-64e8d4765a43", OutputVal: internal.UUID{0xa0, 0xdd, 0x94, 0xed, 0xe6, 0x0c, 0x42, 0xe8, 0x86, 0x32, 0x64, 0xe8, 0xd4, 0x76, 0x5a, 0x43}}, "too-long": {Input: "a0dd94ed-e60c-42e8-8632-64e8d4765a43a", OutputErr: `too long to be a UUID: "a0dd94ed-e60c-42e8-8632-64e8d4765a43"|"a"`}, "bad char": {Input: "a0dd94ej-e60c-42e8-8632-64e8d4765a43a", OutputErr: `illegal byte in UUID: "a0dd94e"|"j"|"-e60c-42e8-8632-64e8d4765a43a"`}, } @@ -29,7 +29,7 @@ func TestParseUUID(t *testing.T) { tc := tc t.Run(tcName, func(t *testing.T) { t.Parallel() - val, err := util.ParseUUID(tc.Input) + val, err := internal.ParseUUID(tc.Input) assert.Equal(t, tc.OutputVal, val) if tc.OutputErr == "" { assert.NoError(t, err) @@ -43,18 +43,18 @@ func TestParseUUID(t *testing.T) { func TestUUIDFormat(t *testing.T) { t.Parallel() type TestCase struct { - InputUUID util.UUID + InputUUID internal.UUID InputFmt string Output string } - uuid := util.MustParseUUID("a0dd94ed-e60c-42e8-8632-64e8d4765a43") + uuid := internal.MustParseUUID("a0dd94ed-e60c-42e8-8632-64e8d4765a43") testcases := map[string]TestCase{ "s": {InputUUID: uuid, InputFmt: "%s", Output: "a0dd94ed-e60c-42e8-8632-64e8d4765a43"}, "x": {InputUUID: uuid, InputFmt: "%x", Output: "a0dd94ede60c42e8863264e8d4765a43"}, "X": {InputUUID: uuid, InputFmt: "%X", Output: "A0DD94EDE60C42E8863264E8D4765A43"}, "v": {InputUUID: uuid, InputFmt: "%v", Output: "a0dd94ed-e60c-42e8-8632-64e8d4765a43"}, "40s": {InputUUID: uuid, InputFmt: "|% 40s", Output: "| a0dd94ed-e60c-42e8-8632-64e8d4765a43"}, - "#115v": {InputUUID: uuid, InputFmt: "|%#115v", Output: "| util.UUID{0xa0, 0xdd, 0x94, 0xed, 0xe6, 0xc, 0x42, 0xe8, 0x86, 0x32, 0x64, 0xe8, 0xd4, 0x76, 0x5a, 0x43}"}, + "#115v": {InputUUID: uuid, InputFmt: "|%#115v", Output: "| internal.UUID{0xa0, 0xdd, 0x94, 0xed, 0xe6, 0xc, 0x42, 0xe8, 0x86, 0x32, 0x64, 0xe8, 0xd4, 0x76, 0x5a, 0x43}"}, } for tcName, tc := range testcases { tc := tc |