MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / createTestIndexFile

Function createTestIndexFile

internal/users/index_test.go:187–200  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
187func 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.

Callers 4

TestSearchIndexByUserIdFunction · 0.85
TestAppendUserRecordFunction · 0.85

Calls 2

CreateMethod · 0.95
AddUserMethod · 0.95

Tested by

no test coverage detected