MCPcopy Create free account
hub / github.com/activecm/rita / validateMetaDBFilesTable

Function validateMetaDBFilesTable

integration/metadb_test.go:397–484  ·  view source on GitHub ↗
(t *testing.T, db *database.DB, directory string, dbName string, importID util.FixedString)

Source from the content-addressed store, hash-verified

395}
396
397func validateMetaDBFilesTable(t *testing.T, db *database.DB, directory string, dbName string, importID util.FixedString) {
398 t.Helper()
399
400 // set the context
401 ctx := clickhouse.Context(db.GetContext(), clickhouse.WithParameters(clickhouse.Parameters{
402 "table": "files",
403 "database": dbName,
404 "importID": importID.Hex(),
405 }))
406
407 // files table exists
408 t.Run("Table Exists", func(t *testing.T) {
409 var exists uint8
410 err := db.Conn.QueryRow(ctx, `EXISTS TABLE {table:Identifier}`).Scan(&exists)
411 require.NoError(t, err)
412 require.EqualValues(t, 1, exists, "files table must exist")
413 })
414
415 // verify that files entries for import are correct
416 t.Run("Files List Correct", func(t *testing.T) {
417
418 // get the files listed in the files table for the first import
419 rows, err := db.Conn.Query(ctx, `
420 SELECT path
421 FROM {table:Identifier}
422 WHERE database = {database:String} AND import_id = unhex({importID:String})
423 `)
424 require.NoError(t, err)
425 defer rows.Close()
426
427 // type fileVersions
428
429 // map to track the versions of each file
430 dbFiles := make(map[string]struct {
431 log bool
432 logGz bool
433 })
434
435 for rows.Next() {
436 var result struct {
437 Path string `ch:"path"`
438 }
439 err = rows.ScanStruct(&result)
440 require.NoError(t, err)
441
442 // get the filename without the path
443 name := fp.Base(result.Path)
444
445 // set map key as the filename without the .gz extension
446 normalizedFilename := strings.TrimSuffix(name, ".gz")
447
448 // get the version info for the file
449 versionInfo := dbFiles[normalizedFilename]
450
451 // set the version info for the file
452 if strings.HasSuffix(name, ".gz") {
453 versionInfo.logGz = true
454 } else {

Callers 1

TestMetaDatabaseFunction · 0.85

Calls 4

HexMethod · 0.80
CloseMethod · 0.80
GetContextMethod · 0.65
ScanMethod · 0.45

Tested by

no test coverage detected