func checkInsertedVulns(ctx context.Context, t *testing.T, pool *pgxpool.Pool, id uuid.UUID, vulns []*claircore.Vulnerability) {
	const query = `SELECT
	vuln.hash_kind,
	vuln.hash,
	vuln.updater,
	vuln.id,
	vuln.name,
	vuln.description,
	vuln.issued,
	vuln.links,
	vuln.normalized_severity,
	vuln.severity,
	vuln.package_name,
	vuln.package_version,
	vuln.package_module,
	vuln.package_arch,
	vuln.package_kind,
	vuln.dist_id,
	vuln.dist_name,
	vuln.dist_version,
	vuln.dist_version_code_name,
	vuln.dist_version_id,
	vuln.dist_arch,
	vuln.dist_cpe,
	vuln.dist_pretty_name,
	vuln.arch_operation,
	vuln.repo_name,
	vuln.repo_key,
	vuln.repo_uri,
	vuln.fixed_in_version
FROM uo_vuln
JOIN vuln ON vuln.id = uo_vuln.vuln
JOIN update_operation uo ON uo.id = uo_vuln.uo
WHERE uo.ref = $1::uuid;`
	expectedVulns := map[string]*claircore.Vulnerability{}
	for _, vuln := range vulns {
		expectedVulns[vuln.Name] = vuln
	}
	rows, err := pool.Query(ctx, query, id)
	if err != nil {
		t.Fatalf("query failed: %v", err)
	}
	defer rows.Close()

	queriedVulns := map[string]*claircore.Vulnerability{}
	for rows.Next() {
		var id int64
		var hashKind string
		var hash []byte
		vuln := claircore.Vulnerability{
			Package: &claircore.Package{},
			Dist:    &claircore.Distribution{},
			Repo:    &claircore.Repository{},
		}
		err := rows.Scan(
			&hashKind,
			&hash,
			&vuln.Updater,
			&id,
			&vuln.Name,
			&vuln.Description,
			&vuln.Issued,
			&vuln.Links,
			&vuln.NormalizedSeverity,
			&vuln.Severity,
			&vuln.Package.Name,
			&vuln.Package.Version,
			&vuln.Package.Module,
			&vuln.Package.Arch,
			&vuln.Package.Kind,
			&vuln.Dist.DID,
			&vuln.Dist.Name,
			&vuln.Dist.Version,
			&vuln.Dist.VersionCodeName,
			&vuln.Dist.VersionID,
			&vuln.Dist.Arch,
			&vuln.Dist.CPE,
			&vuln.Dist.PrettyName,
			&vuln.ArchOperation,
			&vuln.Repo.Name,
			&vuln.Repo.Key,
			&vuln.Repo.URI,
			&vuln.FixedInVersion,
		)
		vuln.ID = strconv.FormatInt(id, 10)
		if err != nil {
			t.Fatalf("failed to scan vulnerability: %v", err)
		}
		// confirm a hash was generated
		if hashKind == "" || len(hash) == 0 {
			t.Fatalf("failed to identify hash for inserted vulnerability %+v", vuln)
		}
		queriedVulns[vuln.Name] = &vuln
	}
	if err := rows.Err(); err != nil {
		t.Error(err)
	}

	// confirm we did not receive unexpected vulns or bad fields
	for name, got := range queriedVulns {
		if want, ok := expectedVulns[name]; !ok {
			t.Fatalf("received unexpected vuln: %v", got.Name)
		} else {
			// compare vuln fields. ignore id's
			if !cmp.Equal(want, got, vulnCmp) {
				t.Fatal(cmp.Diff(want, got, vulnCmp))
			}
		}
	}

	// confirm queriedVulns contain all expected vulns
	for name := range expectedVulns {
		if _, ok := queriedVulns[name]; !ok {
			t.Fatalf("expected vuln %v was not found in query", name)
		}
	}
}
// checkInsertedVulns confirms vulnerabilitiles are inserted into the database correctly when
// store.UpdateVulnerabilities is called.
checkInsertedVulns confirms vulnerabilitiles are inserted into the database correctly when
store.UpdateVulnerabilities is called.
// checkInsertedVulns confirms vulnerabilitiles are inserted into the database correctly when // store . UpdateVulnerabilities is called .
func checkInsertedVulns(ctx context.Context, t *testing.T, pool *pgxpool.Pool, id uuid.UUID, vulns []*claircore.Vulnerability) {
	const query = `SELECT
	vuln.hash_kind,
	vuln.hash,
	vuln.updater,
	vuln.id,
	vuln.name,
	vuln.description,
	vuln.issued,
	vuln.links,
	vuln.normalized_severity,
	vuln.severity,
	vuln.package_name,
	vuln.package_version,
	vuln.package_module,
	vuln.package_arch,
	vuln.package_kind,
	vuln.dist_id,
	vuln.dist_name,
	vuln.dist_version,
	vuln.dist_version_code_name,
	vuln.dist_version_id,
	vuln.dist_arch,
	vuln.dist_cpe,
	vuln.dist_pretty_name,
	vuln.arch_operation,
	vuln.repo_name,
	vuln.repo_key,
	vuln.repo_uri,
	vuln.fixed_in_version
FROM uo_vuln
JOIN vuln ON vuln.id = uo_vuln.vuln
JOIN update_operation uo ON uo.id = uo_vuln.uo
WHERE uo.ref = $1::uuid;`
	expectedVulns := map[string]*claircore.Vulnerability{}
	for _, vuln := range vulns {
		expectedVulns[vuln.Name] = vuln
	}
	rows, err := pool.Query(ctx, query, id)
	if err != nil {
		t.Fatalf("query failed: %v", err)
	}
	defer rows.Close()
	queriedVulns := map[string]*claircore.Vulnerability{}
	for rows.Next() {
		var id int64
		var hashKind string
		var hash []byte
		vuln := claircore.Vulnerability{
			Package: &claircore.Package{},
			Dist:    &claircore.Distribution{},
			Repo:    &claircore.Repository{},
		}
		err := rows.Scan(
			&hashKind,
			&hash,
			&vuln.Updater,
			&id,
			&vuln.Name,
			&vuln.Description,
			&vuln.Issued,
			&vuln.Links,
			&vuln.NormalizedSeverity,
			&vuln.Severity,
			&vuln.Package.Name,
			&vuln.Package.Version,
			&vuln.Package.Module,
			&vuln.Package.Arch,
			&vuln.Package.Kind,
			&vuln.Dist.DID,
			&vuln.Dist.Name,
			&vuln.Dist.Version,
			&vuln.Dist.VersionCodeName,
			&vuln.Dist.VersionID,
			&vuln.Dist.Arch,
			&vuln.Dist.CPE,
			&vuln.Dist.PrettyName,
			&vuln.ArchOperation,
			&vuln.Repo.Name,
			&vuln.Repo.Key,
			&vuln.Repo.URI,
			&vuln.FixedInVersion,
		)
		vuln.ID = strconv.FormatInt(id, 10)
		if err != nil {
			t.Fatalf("failed to scan vulnerability: %v", err)
		}
		if hashKind == "" || len(hash) == 0 {
			t.Fatalf("failed to identify hash for inserted vulnerability %+v", vuln)
		}
		queriedVulns[vuln.Name] = &vuln
	}
	if err := rows.Err(); err != nil {
		t.Error(err)
	}
	for name, got := range queriedVulns {
		if want, ok := expectedVulns[name]; !ok {
			t.Fatalf("received unexpected vuln: %v", got.Name)
		} else {
			if !cmp.Equal(want, got, vulnCmp) {
				t.Fatal(cmp.Diff(want, got, vulnCmp))
			}
		}
	}
	for name := range expectedVulns {
		if _, ok := queriedVulns[name]; !ok {
			t.Fatalf("expected vuln %v was not found in query", name)
		}
	}
}
func checkInsertedVulns ( ctx context . Context , t * testing . T , pool * pgxpool . Pool , id uuid . UUID , vulns [ ] * claircore . Vulnerability ) { const query = `SELECT
	vuln.hash_kind,
	vuln.hash,
	vuln.updater,
	vuln.id,
	vuln.name,
	vuln.description,
	vuln.issued,
	vuln.links,
	vuln.normalized_severity,
	vuln.severity,
	vuln.package_name,
	vuln.package_version,
	vuln.package_module,
	vuln.package_arch,
	vuln.package_kind,
	vuln.dist_id,
	vuln.dist_name,
	vuln.dist_version,
	vuln.dist_version_code_name,
	vuln.dist_version_id,
	vuln.dist_arch,
	vuln.dist_cpe,
	vuln.dist_pretty_name,
	vuln.arch_operation,
	vuln.repo_name,
	vuln.repo_key,
	vuln.repo_uri,
	vuln.fixed_in_version
FROM uo_vuln
JOIN vuln ON vuln.id = uo_vuln.vuln
JOIN update_operation uo ON uo.id = uo_vuln.uo
WHERE uo.ref = $1::uuid;` expectedVulns := map [ string ] * claircore . Vulnerability { } for _ , vuln := range vulns { expectedVulns [ vuln . Name ] = vuln } rows , err := pool . Query ( ctx , query , id ) if err != nil { t . Fatalf ( " " , err ) } defer rows . Close ( ) queriedVulns := map [ string ] * claircore . Vulnerability { } for rows . Next ( ) { var id int64 var hashKind string var hash [ ] byte vuln := claircore . Vulnerability { Package : & claircore . Package { } , Dist : & claircore . Distribution { } , Repo : & claircore . Repository { } , } err := rows . Scan ( & hashKind , & hash , & vuln . Updater , & id , & vuln . Name , & vuln . Description , & vuln . Issued , & vuln . Links , & vuln . NormalizedSeverity , & vuln . Severity , & vuln . Package . Name , & vuln . Package . Version , & vuln . Package . Module , & vuln . Package . Arch , & vuln . Package . Kind , & vuln . Dist . DID , & vuln . Dist . Name , & vuln . Dist . Version , & vuln . Dist . VersionCodeName , & vuln . Dist . VersionID , & vuln . Dist . Arch , & vuln . Dist . CPE , & vuln . Dist . PrettyName , & vuln . ArchOperation , & vuln . Repo . Name , & vuln . Repo . Key , & vuln . Repo . URI , & vuln . FixedInVersion , ) vuln . ID = strconv . FormatInt ( id , 10 ) if err != nil { t . Fatalf ( " " , err ) } if hashKind == " " || len ( hash ) == 0 { t . Fatalf ( " " , vuln ) } queriedVulns [ vuln . Name ] = & vuln } if err := rows . Err ( ) ; err != nil { t . Error ( err ) } for name , got := range queriedVulns { if want , ok := expectedVulns [ name ] ; ! ok { t . Fatalf ( " " , got . Name ) } else { if ! cmp . Equal ( want , got , vulnCmp ) { t . Fatal ( cmp . Diff ( want , got , vulnCmp ) ) } } } for name := range expectedVulns { if _ , ok := queriedVulns [ name ] ; ! ok { t . Fatalf ( " " , name ) } } }
checkInsertedVulns confirms vulnerabilitiles are inserted into the database correctly when
store.UpdateVulnerabilities is called.
checkInsertedVulns confirms vulnerabilitiles are inserted into the database correctly when store . UpdateVulnerabilities is called .
// confirm a hash was generated // confirm we did not receive unexpected vulns or bad fields // compare vuln fields. ignore id's // confirm queriedVulns contain all expected vulns