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

test: Improve Test Coverage of model package #367

Conversation

tvarney13
Copy link
Member

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

Provide links to any issues in this repository or elsewhere relating to this pull request.

Describe the solution you've provided

Title explains it. I also made some minor modifications I'll call out in PR comments.

Describe alternatives you've considered

Provide a clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context about the pull request here.

@tvarney13 tvarney13 self-assigned this Jul 3, 2024
Comment on lines +6 to +10
// mockgen -destination mocks/observer.go -package mocks . Observer
//

// Package mock_observer is a generated GoMock package.
package mock_observer
// Package mocks is a generated GoMock package.
package mocks
Copy link
Member Author

Choose a reason for hiding this comment

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

Paired with @mike-zorn on batching all the mock objects in models together in one directory and re-ran codegen.

@@ -1,8 +1,9 @@
package model
package model_test
Copy link
Member Author

Choose a reason for hiding this comment

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

Wanted all the tests to be in the same package.

project, err := store.GetDevProject(ctx, projectKey)
if err != nil {
return Override{}, errors.Wrap(err, "unable to get project")
}

observers := GetObserversFromContext(ctx)
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved this call closer to where it's actually used.

@@ -36,6 +38,7 @@ func CreateProject(ctx context.Context, projectKey, sourceEnvironmentKey string,
project.FlagState = flagsState
project.LastSyncTime = time.Now()

store := StoreFromContext(ctx)
Copy link
Member Author

Choose a reason for hiding this comment

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

Just a cleanup - bundled the project variable initialization together into one statement and also moved the store fetch closer to where the store is used.

@@ -71,7 +74,7 @@ func UpdateProject(ctx context.Context, projectKey string, context *ldcontext.Co
return Project{}, err
}
if !updated {
return Project{}, err
return Project{}, errors.New("Project not updated")
Copy link
Member Author

Choose a reason for hiding this comment

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

For UpdateProject, not returning an error here if the project wasn't actually updated seems like a bug? I updated this and SyncProject to return an error in this case, as well as coverage for that case. However, I definitely lack a lot of context so lemme know if there's something I'm missing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, yeah. that makes sense. TBH we should probably change the store interface so that we return an error instead of the boolean. Issue is that if no rows are updated when we try and update, it means that we couldn't find the project.

@tvarney13 tvarney13 changed the title Improve Test Coverage of model package test: Improve Test Coverage of model package Jul 3, 2024
expectedVal = ldvalue.Float64(99.99)
case "jsonFlag":
expectedVal = ldvalue.CopyArbitraryValue(map[string]any{"cat": "hat"})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
}
default:
assert.Failf(t, "unknown flag, %s", key)
}

Copy link
Contributor

@mike-zorn mike-zorn left a comment

Choose a reason for hiding this comment

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

LGTM!

I had a few suggestions along the way, but none of them are blockers.

@tvarney13 tvarney13 merged commit ddf4190 into moonshot-ld-dev-server Jul 8, 2024
1 check passed
@tvarney13 tvarney13 deleted the tomvarney/sc-248911/improve-test-coverage-of-model-package branch July 8, 2024 13:21
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.

2 participants