| 171 | } |
| 172 | |
| 173 | func TestFileDetector_DetectWithoutMockFS(t *testing.T) { |
| 174 | // Specify the name of an existing directory that contains the expected files |
| 175 | directory, err := os.Getwd() |
| 176 | if err != nil { |
| 177 | t.Fatalf("Unexpected Getwd error: %v", err) |
| 178 | } |
| 179 | dirFS := os.DirFS(directory).(FS) |
| 180 | |
| 181 | files, err := os.ReadDir(directory) |
| 182 | if err != nil { |
| 183 | t.Fatalf("Unexpected ReadDir error: %v", err) |
| 184 | } |
| 185 | |
| 186 | // Choose a random file from working directory |
| 187 | expectedFiles := []string{files[0].Name()} |
| 188 | |
| 189 | // Create the FileDetector with the expected file paths |
| 190 | // Instantiating one without a FileSystem will use the actual OS File System |
| 191 | detector := FileDetector{ |
| 192 | Title: "Test Detector", |
| 193 | Paths: expectedFiles, |
| 194 | } |
| 195 | |
| 196 | // Perform the detection |
| 197 | match, err := detector.Detect(dirFS) |
| 198 | |
| 199 | if err != nil { |
| 200 | t.Fatalf("Unexpected error during detection: %v", err) |
| 201 | } |
| 202 | |
| 203 | // Verify the detection result |
| 204 | if !match.Detected { |
| 205 | t.Errorf("Expected detection result to be true, but got false") |
| 206 | } |
| 207 | |
| 208 | if match.Confidence != High { |
| 209 | t.Errorf("Expected confidence to be High, but got %s", match.Confidence) |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | func TestFileDetector_GetTitle(t *testing.T) { |
| 214 | detector := FileDetector{ |