|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "os/exec" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +// TestSearchHelp tests the search command help |
| 9 | +func TestSearchHelp(t *testing.T) { |
| 10 | + cmd := exec.Command("../maestro-k", "search", "--help") |
| 11 | + output, err := cmd.Output() |
| 12 | + |
| 13 | + if err != nil { |
| 14 | + t.Fatalf("Failed to run query help command: %v", err) |
| 15 | + } |
| 16 | + |
| 17 | + helpOutput := string(output) |
| 18 | + |
| 19 | + // Check for expected search help content |
| 20 | + expectedContent := []string{ |
| 21 | + "search", |
| 22 | + "Search documents in a vector database using natural language", |
| 23 | + "doc-limit", |
| 24 | + "Maximum number of documents to consider", |
| 25 | + "Examples:", |
| 26 | + } |
| 27 | + |
| 28 | + for _, expected := range expectedContent { |
| 29 | + if !contains(helpOutput, expected) { |
| 30 | + t.Errorf("Search help output should contain '%s'", expected) |
| 31 | + } |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +// TestSearchNoArgs tests the search command with no arguments |
| 36 | +func TestSearchNoArgs(t *testing.T) { |
| 37 | + cmd := exec.Command("../maestro-k", "search") |
| 38 | + output, err := cmd.CombinedOutput() |
| 39 | + |
| 40 | + if err == nil { |
| 41 | + t.Error("Search command should fail with no arguments") |
| 42 | + } |
| 43 | + |
| 44 | + outputStr := string(output) |
| 45 | + if !contains(outputStr, "Error:") { |
| 46 | + t.Error("Search command should show error message with no arguments") |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +// TestSearchEmptyDatabaseName tests the search command with missing vdb flag |
| 51 | +func TestSearchEmptyDatabaseName(t *testing.T) { |
| 52 | + cmd := exec.Command("../maestro-k", "search", "test query") |
| 53 | + output, err := cmd.CombinedOutput() |
| 54 | + |
| 55 | + if err == nil { |
| 56 | + t.Error("Search command should fail with missing --vdb flag") |
| 57 | + } |
| 58 | + |
| 59 | + outputStr := string(output) |
| 60 | + if !contains(outputStr, "Error:") { |
| 61 | + t.Error("Search command should show error message with missing --vdb flag") |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +// TestSearchEmptySearch tests the search command with empty query |
| 66 | +func TestSearchEmptySearch(t *testing.T) { |
| 67 | + cmd := exec.Command("../maestro-k", "search", "", "--vdb=test-db") |
| 68 | + output, err := cmd.CombinedOutput() |
| 69 | + |
| 70 | + if err == nil { |
| 71 | + t.Error("Search command should fail with empty query") |
| 72 | + } |
| 73 | + |
| 74 | + outputStr := string(output) |
| 75 | + if !contains(outputStr, "Error:") { |
| 76 | + t.Error("Search command should show error message with empty query") |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +// TestSearchWithDryRunFlag tests the search command with dry-run flag |
| 81 | +func TestSearchWithDryRunFlag(t *testing.T) { |
| 82 | + cmd := exec.Command("../maestro-k", "search", "test query", "--vdb=test-db", "--dry-run") |
| 83 | + output, err := cmd.Output() |
| 84 | + |
| 85 | + if err != nil { |
| 86 | + t.Fatalf("Search command with dry-run should not fail: %v", err) |
| 87 | + } |
| 88 | + |
| 89 | + outputStr := string(output) |
| 90 | + if !contains(outputStr, "[DRY RUN]") { |
| 91 | + t.Error("Search command with dry-run should show dry run message") |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +// TestSearchWithSpecialCharacters tests the search command with special characters |
| 96 | +func TestSearchWithSpecialCharacters(t *testing.T) { |
| 97 | + cmd := exec.Command("../maestro-k", "search", "What's the deal with API endpoints? (v2.0)", "--vdb=test-db", "--dry-run") |
| 98 | + output, err := cmd.Output() |
| 99 | + |
| 100 | + if err != nil { |
| 101 | + t.Fatalf("Search command with special characters should not fail: %v", err) |
| 102 | + } |
| 103 | + |
| 104 | + outputStr := string(output) |
| 105 | + if !contains(outputStr, "[DRY RUN]") { |
| 106 | + t.Error("Search command with special characters should show dry run message") |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +// TestSearchWithLongSearch tests the search command with a long query |
| 111 | +func TestSearchWithLongSearch(t *testing.T) { |
| 112 | + longSearch := "This is a very long query that contains many words and should test the ability of the command to handle long input strings without any issues or problems" |
| 113 | + cmd := exec.Command("../maestro-k", "search", longSearch, "--vdb=test-db", "--dry-run") |
| 114 | + output, err := cmd.Output() |
| 115 | + |
| 116 | + if err != nil { |
| 117 | + t.Fatalf("Search command with long query should not fail: %v", err) |
| 118 | + } |
| 119 | + |
| 120 | + outputStr := string(output) |
| 121 | + if !contains(outputStr, "[DRY RUN]") { |
| 122 | + t.Error("Search command with long query should show dry run message") |
| 123 | + } |
| 124 | +} |
| 125 | + |
| 126 | +// TestSearchInvalidDocLimit tests the search command with invalid doc-limit values |
| 127 | +func TestSearchInvalidDocLimit(t *testing.T) { |
| 128 | + testCases := []string{"abc", "1.5"} |
| 129 | + |
| 130 | + for _, invalidLimit := range testCases { |
| 131 | + t.Run("InvalidLimit_"+invalidLimit, func(t *testing.T) { |
| 132 | + cmd := exec.Command("../maestro-k", "search", "test-db", "test query", "--doc-limit", invalidLimit) |
| 133 | + output, err := cmd.CombinedOutput() |
| 134 | + |
| 135 | + // The command should handle invalid limits gracefully |
| 136 | + outputStr := string(output) |
| 137 | + |
| 138 | + // It might fail due to argument parsing or MCP server, but shouldn't crash |
| 139 | + if err == nil && !contains(outputStr, "[DRY RUN]") { |
| 140 | + t.Error("Search command should handle invalid doc-limit gracefully") |
| 141 | + } |
| 142 | + }) |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | +// TestSearchCommandExists tests that the search command exists in the CLI |
| 147 | +func TestSearchCommandExists(t *testing.T) { |
| 148 | + cmd := exec.Command("../maestro-k", "--help") |
| 149 | + output, err := cmd.Output() |
| 150 | + |
| 151 | + if err != nil { |
| 152 | + t.Fatalf("Failed to run help command: %v", err) |
| 153 | + } |
| 154 | + |
| 155 | + helpOutput := string(output) |
| 156 | + if !contains(helpOutput, "search") { |
| 157 | + t.Error("Help output should contain 'search' command") |
| 158 | + } |
| 159 | +} |
0 commit comments