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

Validate datastore engine #810

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Himanshu372
Copy link

@Himanshu372 Himanshu372 commented Jun 11, 2023

Description

Added

  1. Added a DatastoreEngine type which takes up const permissible engine type values
  2. Added helper methods for the type DatastoreEngine
  3. Added checks to validate engine AFTER it is marshalled into config type
  4. Added tests

References

Addresses comment - #712 (comment)
Closes #681

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

@Himanshu372 Himanshu372 requested a review from a team as a code owner June 11, 2023 08:56
@Himanshu372
Copy link
Author

Himanshu372 commented Jun 11, 2023

Hi @jon-whit, based on our last discussion, raised this PR to verify Datastore engine. I have purposefully setup validation after unmarshalling of configs, as I can't write custom unmarshal for viper. Please have a look. Thanks

cmd/shared.go Outdated Show resolved Hide resolved
cmd/shared.go Outdated Show resolved Hide resolved
cmd/shared.go Outdated Show resolved Hide resolved

t.Run("correct datastore engine specified", func(t *testing.T) {
cfg := DefaultConfig()
cfg.Datastore.URI = "postgresql://localhost:5432"
Copy link
Member

Choose a reason for hiding this comment

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

I didn't think postgresql was a valid prefix? The enumerations in cmd/shared.go below define postgres.

This test should return an error, and we should change this test to assert postgres://localhost:5432 does not.

Copy link
Author

Choose a reason for hiding this comment

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

I think, I accidently set URI in this test. I just wanted to test for correct DatastoreEngine. After changes, I am getting expected result.
Although one thing which I noticed is, on setting wrong postgres URI, RunServer stalls and waits for connection. I think we should fail early. Let me know your thoughts

Copy link
Member

@jon-whit jon-whit left a comment

Choose a reason for hiding this comment

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

Left some comments for review.

@Himanshu372
Copy link
Author

Left some comments for review.

@jon-whit Addressed comments, plz check.

@Himanshu372
Copy link
Author

Left some comments for review.

@jon-whit Addressed comments, plz check.

Hey @jon-whit plz have a look and let me know if the changes are OK

cmd/cmd.go Show resolved Hide resolved
Copy link

It appears this PR has been stale for at least 14 days 🗓️. If no action is taken the maintainer team may consider closing the PR. Please reach out if you need assistance or help to finish the work 👍🏼.

@github-actions github-actions bot added the Stale label Dec 18, 2023
@Himanshu372 Himanshu372 requested a review from a team as a code owner April 17, 2024 21:29
Copy link

codecov bot commented Apr 17, 2024

Codecov Report

Attention: Patch coverage is 96.29630% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 86.08%. Comparing base (9ac5204) to head (4d8ccc6).

❗ Current head 4d8ccc6 differs from pull request most recent head d8ab7d3. Consider uploading reports for the commit d8ab7d3 to get more accurate results

Files Patch % Lines
cmd/migrate/migrate.go 83.34% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #810      +/-   ##
==========================================
+ Coverage   86.05%   86.08%   +0.03%     
==========================================
  Files          85       86       +1     
  Lines        8048     8064      +16     
==========================================
+ Hits         6925     6941      +16     
  Misses        792      792              
  Partials      331      331              

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

@miparnisari
Copy link
Member

Hi @Himanshu372, i apologize for taking so long to review this. I took the liberty of updating this PR with respect to main. I also added some more validations to the datastore configs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"datastore.uri" and "datastore.engine" should be required fields when doing run and migrate
3 participants