From 754c254a4bae099cd8b2ec8cee6a9f80a0245919 Mon Sep 17 00:00:00 2001 From: Abdullahi Yunus Date: Tue, 22 Jul 2025 23:28:18 +0100 Subject: [PATCH] commands: add test for parseChanIDs In this commit we add test for `parseChanIDs` to make sure it parses the chan ids correctly and return errors when invalid value is passed. Signed-off-by: Abdullahi Yunus --- cmd/commands/commands_test.go | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/cmd/commands/commands_test.go b/cmd/commands/commands_test.go index c6baad258..12e861cd5 100644 --- a/cmd/commands/commands_test.go +++ b/cmd/commands/commands_test.go @@ -434,3 +434,61 @@ func TestParseBlockHeightInputs(t *testing.T) { }) } } + +// TestParseChanIDs tests the parseChanIDs function with various +// valid and invalid input values and verifies the output. +func TestParseChanIDs(t *testing.T) { + t.Parallel() + + testCases := []struct { + name string + chanIDs []string + expected []uint64 + expectedErr bool + }{ + { + name: "valid chan ids", + chanIDs: []string{ + "1499733860352000", "17592186044552773633", + }, + expected: []uint64{ + 1499733860352000, 17592186044552773633, + }, + expectedErr: false, + }, + { + name: "invalid chan id", + chanIDs: []string{ + "channel id", + }, + expected: []uint64{}, + expectedErr: true, + }, + { + name: "negative chan id", + chanIDs: []string{ + "-10000", + }, + expected: []uint64{}, + expectedErr: true, + }, + { + name: "empty chan ids", + chanIDs: []string{}, + expected: nil, + expectedErr: false, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + chanIDs, err := parseChanIDs(tc.chanIDs) + if tc.expectedErr { + require.Error(t, err) + return + } + require.NoError(t, err) + require.Equal(t, tc.expected, chanIDs) + }) + } +}