Skip to content

Conversation

@lmphil
Copy link
Contributor

@lmphil lmphil commented Sep 30, 2024

Description

This change is meant to add unit tests to DB functions related to the "alias" and "tags" features.

Type of change

  • Unit Tests

How Has This Been Tested?

  • Locally

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Signed-off-by: Philippe <philippe.a.aviles@lmco.com>
@lmphil lmphil requested a review from a team as a code owner September 30, 2024 14:52
@jhoward-lm
Copy link
Contributor

PR title must be conventional commit and should use standard casing.

e.g. test: add unit tests for alias/tags DB functions

@lmphil lmphil changed the title Add Unit Tests for DB Functions Related to Alias and Tags test: add unit tests for alias/tags DB functions Oct 1, 2024
@jhoward-lm
Copy link
Contributor

Can you try updating db.FilterDocumentsByTag to leverage the sliceutil helper functions?

func (backend *Backend) FilterDocumentsByTag(documents []*sbom.Document, tags ...string) ([]*sbom.Document, error) {
	taggedDocuments, err := backend.GetDocumentsByAnnotation(TagAnnotation, tags...)
	if err != nil {
		return nil, fmt.Errorf("failed to get documents by tag: %w", err)
	}

	taggedDocumentIDs := sliceutil.Extract(taggedDocuments, func(doc *sbom.Document) string {
		return doc.GetMetadata().GetId()
	})

	documents = sliceutil.Filter(documents, func(doc *sbom.Document) bool {
		return slices.Contains(taggedDocumentIDs, doc.GetMetadata().GetId())
	})

	return documents, nil
}

lmphil added 5 commits October 1, 2024 19:10
Signed-off-by: Philippe <philippe.a.aviles@lmco.com>
…mctl/bomctl into alias-unit-tests

Signed-off-by: Philippe <philippe.a.aviles@lmco.com>
Signed-off-by: Philippe <philippe.a.aviles@lmco.com>
Signed-off-by: Philippe <philippe.a.aviles@lmco.com>
Signed-off-by: Philippe <philippe.a.aviles@lmco.com>
@ashearin ashearin merged commit e09b374 into main Oct 2, 2024
@ashearin ashearin deleted the alias-unit-tests branch October 2, 2024 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants