Skip to content

DBPW - Add test helpers for DB v5 interface#9948

Merged
pcman312 merged 2 commits into
masterfrom
dbpw-test-helpers
Sep 15, 2020
Merged

DBPW - Add test helpers for DB v5 interface#9948
pcman312 merged 2 commits into
masterfrom
dbpw-test-helpers

Conversation

@pcman312
Copy link
Copy Markdown
Contributor

Overview

This PR is part of a larger feature adding support for password policies into the combined database engine. This feature is being split into multiple PRs to make for smaller reviews & earlier feedback.

Adds some test helper functions to call the various functions on the v5 Database interface with common assertions (no error, NewUser gives a non-empty username). These do not preclude calling the functions directly in a test if needed. These are made available for the common testing use cases.

Related PRs

Original password policies PR
1/X - Database interface & gRPC
2/X - Middleware
3/X - Plugin management
4/X - Database engine

func AssertInitialize(t *testing.T, db newdbplugin.Database, req newdbplugin.InitializeRequest) newdbplugin.InitializeResponse {
t.Helper()

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we make this a tunable value? It may be sufficient for certain cases such as mocked databases, but 2 seconds might not be enough if operations end up taking longer than this duration for certain databases which can happen on CI (depending on load, machine type/size, etc.) and result in flaky tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm hesitant to add too much configurability to these as these are meant for the common use case. If they don't work for a specific database, those tests can fall back to calling the database functions directly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added the ability to change the timeouts via env variable with a default of 2s.

@pcman312 pcman312 merged commit 281a09f into master Sep 15, 2020
@pcman312 pcman312 deleted the dbpw-test-helpers branch September 15, 2020 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants