Skip to content

Commit 945624d

Browse files
authored
test: Add coverage for inventory branch, ambiguous context, and TranscriptReader error (#78)
- TestRun_InventoryZeroCounts: exercises the inventory code path in run() - TestHandler_AmbiguousContextCommand: covers multiplePromptMatches fallthrough in handleShellInput when context search returns ambiguous results - TestHandler_TranscriptReaderError already existed but confirms the dispatchCommand error path is covered
1 parent eaeaf48 commit 945624d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

cissh_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ platforms:
6666
}
6767
}
6868

69+
func TestRun_InventoryZeroCounts(t *testing.T) {
70+
inv := `---
71+
devices:
72+
- platform: csr1000v
73+
count: 0
74+
`
75+
invFile := filepath.Join(t.TempDir(), "inventory.yaml")
76+
if err := os.WriteFile(invFile, []byte(inv), 0644); err != nil {
77+
t.Fatal(err)
78+
}
79+
cli := utils.CLI{Platform: "csr1000v", TranscriptMap: validTranscriptMap(t), Inventory: invFile}
80+
if err := run(context.Background(), cli); err != nil {
81+
t.Errorf("unexpected error: %v", err)
82+
}
83+
}
84+
6985
func TestRun_BadInventory(t *testing.T) {
7086
cli := utils.CLI{Platform: "csr1000v", TranscriptMap: validTranscriptMap(t), Inventory: "/nonexistent/inventory.yaml"}
7187
if err := run(context.Background(), cli); err == nil {

ssh_server/handlers/ciscohandlers_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,24 @@ func TestHandler_EmptyInput(t *testing.T) {
321321
}
322322
}
323323

324+
func TestHandler_AmbiguousContextCommand(t *testing.T) {
325+
fd := newTestDevice()
326+
// Add two multi-word context keys sharing a prefix to trigger multiplePromptMatches.
327+
// "sh v" matches both "show version" and "show vlan" via field-by-field matching.
328+
fd.ContextSearch["show version"] = "(show-version)#"
329+
fd.ContextSearch["show vlan"] = "(show-vlan)#"
330+
addr, cleanup := startTestServer(t, fd)
331+
defer cleanup()
332+
333+
// multiplePromptMatches=true falls through to dispatchCommand.
334+
// "sh v" also matches "show version" in SupportedCommands, so we get output.
335+
out := interact(t, addr, []string{"sh v"})
336+
// Verify we got command output (not a context switch) — confirms the fallthrough path executed
337+
if !strings.Contains(out, "FakeOS") {
338+
t.Errorf("expected command output after ambiguous context fallthrough, got:\n%s", out)
339+
}
340+
}
341+
324342
func TestHandler_AmbiguousCommand(t *testing.T) {
325343
fd := newTestDevice()
326344
// Add commands that will be ambiguous with "s v"

0 commit comments

Comments
 (0)