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

Implement test helpers for constructing user device data #4476

Merged
merged 9 commits into from
Jan 15, 2025

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Jan 8, 2025

Currently it's very hard to extend our test data because it has been generated manually with real users and devices. I'd like to change that so that the data is created more dynamically, so that it is easier to extend.

This PR introduces a builder type which can be used to help construct such test data, and rebuilds some of the existing test data using it. Unfortunately we're lacking some private keys, so I've had to replace a couple of keys.

The PR also introduces some snapshots, so we can keep an eye on how the data is changing.

Recommend reviewing commit-by-commit.

@richvdh richvdh force-pushed the rav/test_data_rework branch 5 times, most recently from e31eff1 to 25f7927 Compare January 8, 2025 11:42
Comment on lines +262 to +322
/// Current user's private user-signing key, as an [`Ed25519SecretKey`].
pub fn me_private_user_signing_key() -> Ed25519SecretKey {
Ed25519SecretKey::from_base64(Self::USER_SIGNING_KEY_PRIVATE_EXPORT).unwrap()
}
Copy link
Member Author

Choose a reason for hiding this comment

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

we end up using this in a few places in a later commit, hence pulling it out to a separate function

Copy link

codecov bot commented Jan 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.05%. Comparing base (c503583) to head (f31bd13).
Report is 107 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4476   +/-   ##
=======================================
  Coverage   85.04%   85.05%           
=======================================
  Files         283      283           
  Lines       31749    31749           
=======================================
+ Hits        27002    27005    +3     
+ Misses       4747     4744    -3     

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

@richvdh richvdh force-pushed the rav/test_data_rework branch from a50bd6d to 88b101c Compare January 8, 2025 14:11
@richvdh richvdh force-pushed the rav/test_data_rework branch from 88b101c to 1cce2f3 Compare January 8, 2025 14:14
@richvdh richvdh marked this pull request as ready for review January 8, 2025 14:24
@richvdh richvdh requested a review from a team as a code owner January 8, 2025 14:24
@richvdh richvdh requested review from Hywan and removed request for a team January 8, 2025 14:24
@poljar poljar requested review from poljar and removed request for Hywan January 13, 2025 12:17
Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

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

I left some comments, I'm not particularly happy with how much code duplication is going on here if we could replace at least a couple of the raw json() calls with types that already define the structure, that would ease my mind.

Thanks for trying to contain the mess our test data produces.

testing/matrix-sdk-test/src/test_json/keys_query_sets.rs Outdated Show resolved Hide resolved
testing/matrix-sdk-test/src/test_json/keys_query_sets.rs Outdated Show resolved Hide resolved
testing/matrix-sdk-test/src/test_json/keys_query_sets.rs Outdated Show resolved Hide resolved
testing/matrix-sdk-test/src/test_json/keys_query_sets.rs Outdated Show resolved Hide resolved
testing/matrix-sdk-test/src/test_json/keys_query_sets.rs Outdated Show resolved Hide resolved
testing/matrix-sdk-test/src/test_json/keys_query_sets.rs Outdated Show resolved Hide resolved
testing/matrix-sdk-test/src/test_json/keys_query_sets.rs Outdated Show resolved Hide resolved
testing/matrix-sdk-test/src/test_json/keys_query_sets.rs Outdated Show resolved Hide resolved
testing/matrix-sdk-test/src/test_json/keys_query_sets.rs Outdated Show resolved Hide resolved
@richvdh richvdh force-pushed the rav/test_data_rework branch from 1cce2f3 to 935dcf1 Compare January 14, 2025 15:32
We're going to be switching away from JSON-twiddling, so let's snapshot the
real object rather than the JSON.
Our test helper won't do this, and it's redundant
... and use it for some simple data
Regenerate Dan's data with new cross-signing and device keys, for which I know
the private keys.

The signatures are manually calculated for now; this will be improved in a
later commit.
@richvdh richvdh force-pushed the rav/test_data_rework branch from 38383db to f31bd13 Compare January 14, 2025 16:44
@richvdh richvdh requested a review from poljar January 14, 2025 17:11
Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

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

Left a lingering question, but I think this looks good now.

);

let response = builder.build_response();
with_settings!({sort_maps => true}, {
Copy link
Contributor

Choose a reason for hiding this comment

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

What happened with the idea of putting the assert_json_snapshot() into the build_response() command?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, I wanted to start with some snapshots before I added build_response, so that I could check what I was changing.

We could probably move the snapshot now, but it's a whole other line of investigation. panic::Location doesn't really work, because it ties the name of the snapshot to the line number where build_response was called, which is obviously not stable. I don't know if we could do something with backtrace, but I'm inclined to leave it for now.

@richvdh richvdh merged commit fe3cc09 into main Jan 15, 2025
41 checks passed
@richvdh richvdh deleted the rav/test_data_rework branch January 15, 2025 10:42
richvdh added a commit that referenced this pull request Jan 16, 2025
#4540)

#4476 added some test helpers to generate `/keys/query` responses. We're
going to need to test dehydrated devices, so this PR adds support for
that.
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