createTestIndexFile creates an index file with a fixed-width header and multiple user records. It uses the UserIndex receiver method formatFixedHeader so that the header is exactly 100 bytes long.
(t *testing.T, filename string)
| 185 | // createTestIndexFile creates an index file with a fixed-width header and multiple user records. |
| 186 | // It uses the UserIndex receiver method formatFixedHeader so that the header is exactly 100 bytes long. |
| 187 | func createTestIndexFile(t *testing.T, filename string) *UserIndex { |
| 188 | |
| 189 | // Create an index instance for the test file. |
| 190 | idx := &UserIndex{Filename: filename} |
| 191 | idx.Create() |
| 192 | |
| 193 | // Prepare records: each iteration writes two records. |
| 194 | for i := 1; i < 100; i++ { |
| 195 | idx.AddUser(i*10, fmt.Sprintf(`alice_%d`, i)) |
| 196 | idx.AddUser(1000000+(i*10), fmt.Sprintf(`bob_%d`, i)) |
| 197 | } |
| 198 | |
| 199 | return idx |
| 200 | } |
| 201 | |
| 202 | // TestSearchIndexByUsername tests the file-based search by creating a test index file |
| 203 | // and then verifying that lookups for "alice" and "bob" succeed while a lookup for a missing user ("charlie") fails. |
no test coverage detected