Skip to content

Commit 203808c

Browse files
committed
tests/util: Change MockTokenUser::token to be optional
1 parent 95c15f9 commit 203808c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/tests/util.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl MockCookieUser {
344344

345345
MockTokenUser {
346346
app: self.app.clone(),
347-
token,
347+
token: Some(token),
348348
plaintext: plaintext.expose_secret().into(),
349349
}
350350
}
@@ -353,7 +353,7 @@ impl MockCookieUser {
353353
/// A type that can generate token authenticated requests
354354
pub struct MockTokenUser {
355355
app: TestApp,
356-
token: ApiToken,
356+
token: Option<ApiToken>,
357357
plaintext: String,
358358
}
359359

@@ -372,7 +372,8 @@ impl RequestHelper for MockTokenUser {
372372
impl MockTokenUser {
373373
/// Returns a reference to the database `ApiToken` model
374374
pub fn as_model(&self) -> &ApiToken {
375-
&self.token
375+
const ERROR: &str = "Original `ApiToken` was not set on this `MockTokenUser` instance";
376+
self.token.as_ref().expect(ERROR)
376377
}
377378

378379
pub fn plaintext(&self) -> &str {

0 commit comments

Comments
 (0)