Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 (catalogd) add unit tests for indexing algo for query endpoint #1702

Merged

Conversation

anik120
Copy link
Contributor

@anik120 anik120 commented Feb 4, 2025

Closes #1697

Description

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

@anik120 anik120 requested a review from a team as a code owner February 4, 2025 19:55
Copy link

netlify bot commented Feb 4, 2025

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit 8bf3528
🔍 Latest deploy log https://app.netlify.com/sites/olmv1/deploys/67a27cbf3d1abc000845ea1a
😎 Deploy Preview https://deploy-preview-1702--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -50,20 +50,6 @@ func (s *section) UnmarshalJSON(b []byte) error {
return nil
}

func (i index) Size() int64 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we removing this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I realized it's not being used anywhere, so at least in the context of existing code, it's dead code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I was using that in my prototype to estimate how big the index would be in memory. No need for it anymore.

Copy link

codecov bot commented Feb 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.66%. Comparing base (46cec30) to head (8bf3528).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1702      +/-   ##
==========================================
+ Coverage   67.47%   67.66%   +0.18%     
==========================================
  Files          59       59              
  Lines        5003     4991      -12     
==========================================
+ Hits         3376     3377       +1     
+ Misses       1380     1367      -13     
  Partials      247      247              
Flag Coverage Δ
e2e 53.29% <ø> (-0.09%) ⬇️
unit 55.39% <ø> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@anik120 anik120 force-pushed the query-endpoint-index-unit-tests branch from 24bc1a1 to b280e81 Compare February 4, 2025 20:42
camilamacedo86
camilamacedo86 previously approved these changes Feb 4, 2025
Copy link
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Feb 4, 2025
@camilamacedo86 camilamacedo86 changed the title ✨(catalogd) add unit tests for indexing algo for query endpoint 🌱 (catalogd) add unit tests for indexing algo for query endpoint Feb 4, 2025
@anik120 anik120 force-pushed the query-endpoint-index-unit-tests branch from b280e81 to 8bf3528 Compare February 4, 2025 20:46
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Feb 4, 2025
@camilamacedo86
Copy link
Contributor

HI @anik120

Nit: I hope that you do not mind I update the emoji with the title to 🌱 because that means no changes to end users
Also, see Error: catalogd/internal/storage/index_test.go:8:1: File is not properly formatted (gci) make lint with fix flag will sort out this one.

Just sort out the lint then it seems good to fly 🚀

Copy link
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Feb 4, 2025
@anik120
Copy link
Contributor Author

anik120 commented Feb 4, 2025

@camilamacedo86 thanks for the lgtm! lint is passing now too.

}

// createBlob is a helper function that creates a JSON blob with a trailing newline
func createBlob(t *testing.T, data map[string]interface{}) []byte {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also use the declcfg.WriteJSON method in operator-registry which utilizes the underlying JSON encoder which turns each blob into a JSONLines-compliant format by appending a newline suffix here.
This is how catalogd ends up coincidentally JSONLines-compliant.

Copy link
Contributor Author

@anik120 anik120 Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I studied the WriteJSON function and looks like it requires a declCfg.DeclConfig as an argument. Overkill imho if we create a declCfg.DeclConfig from test data just to use WriteJSON.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how catalogd ends up coincidentally JSONLines-compliant.

On a side note this sounds fragile because it looks like they only add the /n to make the output look nicer and could easily pull this out in a future release in which case WriteJSON will stop being JSONLines compliant.

Not sure how many places this function is actually being used, but I guess at this point this is a "we'll cross the bridge if we ever get there" case :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I initially included the note just for the context because this is totally an accident and could just as easily go away. So we used to have tests to ensure we would recognize any change from that accident.
We need to restore those tests, since presumably any behavior change will come from a dependency bump, so we want the CI to fail early/loud if the behavior changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't related to this PR, so I created #1709 for them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!


for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
reader := idx.Get(fullData, tt.schema, tt.packageName, tt.blobName)
Copy link
Contributor

@grokspawn grokspawn Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blobName and packageName are not consistently provided in the tests. Are they needed?
Looks like blobName is actually bundleName. Rename?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getSection() code handles these cases:

func (i *index) getSectionSet(schema, packageName, name string) sets.Set[section] {
	.
        .
	// Filter by package name if specified
	if packageName != "" {
		.
                .
	}

	// Filter by name if specified
	if name != "" {
		.
                .
	}
	return sectionSet
}

Copy link
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@grokspawn, it seems fine to me.
@anik120 shows that answers your concerns.
But @anik120 I think it would be nice just ensure that @grokspawn is also OK within

@anik120 anik120 added this pull request to the merge queue Feb 5, 2025
Merged via the queue into operator-framework:main with commit e639717 Feb 5, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

catalogd: Unit tests for indexing algorithm.
4 participants