Skip to content

Commit 754c254

Browse files
committed
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 <[email protected]>
1 parent 35c6cec commit 754c254

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

cmd/commands/commands_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,3 +434,61 @@ func TestParseBlockHeightInputs(t *testing.T) {
434434
})
435435
}
436436
}
437+
438+
// TestParseChanIDs tests the parseChanIDs function with various
439+
// valid and invalid input values and verifies the output.
440+
func TestParseChanIDs(t *testing.T) {
441+
t.Parallel()
442+
443+
testCases := []struct {
444+
name string
445+
chanIDs []string
446+
expected []uint64
447+
expectedErr bool
448+
}{
449+
{
450+
name: "valid chan ids",
451+
chanIDs: []string{
452+
"1499733860352000", "17592186044552773633",
453+
},
454+
expected: []uint64{
455+
1499733860352000, 17592186044552773633,
456+
},
457+
expectedErr: false,
458+
},
459+
{
460+
name: "invalid chan id",
461+
chanIDs: []string{
462+
"channel id",
463+
},
464+
expected: []uint64{},
465+
expectedErr: true,
466+
},
467+
{
468+
name: "negative chan id",
469+
chanIDs: []string{
470+
"-10000",
471+
},
472+
expected: []uint64{},
473+
expectedErr: true,
474+
},
475+
{
476+
name: "empty chan ids",
477+
chanIDs: []string{},
478+
expected: nil,
479+
expectedErr: false,
480+
},
481+
}
482+
483+
for _, tc := range testCases {
484+
t.Run(tc.name, func(t *testing.T) {
485+
chanIDs, err := parseChanIDs(tc.chanIDs)
486+
if tc.expectedErr {
487+
require.Error(t, err)
488+
return
489+
}
490+
require.NoError(t, err)
491+
require.Equal(t, tc.expected, chanIDs)
492+
})
493+
}
494+
}

0 commit comments

Comments
 (0)