Skip to content

Commit 77183b3

Browse files
authored
cleanup(auth): remove test_credentials() (#3257)
This is now redundant, `anonymous::Builder` can do the same thing. This is non-breaking. The function was `#[doc(hidden)]`, and those are not part of the public API. In any case, we bumped the version for other reasons
1 parent d27c02d commit 77183b3

30 files changed

+94
-104
lines changed

src/auth/src/credentials.rs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -576,39 +576,13 @@ fn adc_well_known_path() -> Option<String> {
576576
#[cfg_attr(test, mutants::skip)]
577577
#[doc(hidden)]
578578
pub mod testing {
579-
use super::{CacheableResource, EntityTag};
579+
use super::CacheableResource;
580580
use crate::Result;
581581
use crate::credentials::Credentials;
582582
use crate::credentials::dynamic::CredentialsProvider;
583583
use http::{Extensions, HeaderMap};
584584
use std::sync::Arc;
585585

586-
/// A simple credentials implementation to use in tests where authentication does not matter.
587-
///
588-
/// Always returns a "Bearer" token, with "test-only-token" as the value.
589-
pub fn test_credentials() -> Credentials {
590-
Credentials {
591-
inner: Arc::from(TestCredentials {}),
592-
}
593-
}
594-
595-
#[derive(Debug)]
596-
struct TestCredentials;
597-
598-
#[async_trait::async_trait]
599-
impl CredentialsProvider for TestCredentials {
600-
async fn headers(&self, _extensions: Extensions) -> Result<CacheableResource<HeaderMap>> {
601-
Ok(CacheableResource::New {
602-
entity_tag: EntityTag::default(),
603-
data: HeaderMap::new(),
604-
})
605-
}
606-
607-
async fn universe_domain(&self) -> Option<String> {
608-
None
609-
}
610-
}
611-
612586
/// A simple credentials implementation to use in tests.
613587
///
614588
/// Always return an error in `headers()`.

src/auth/tests/credentials.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ mod tests {
2626
use google_cloud_auth::credentials::EntityTag;
2727
use google_cloud_auth::credentials::mds::Builder as MdsBuilder;
2828
use google_cloud_auth::credentials::service_account::Builder as ServiceAccountBuilder;
29-
use google_cloud_auth::credentials::testing::test_credentials;
3029
use google_cloud_auth::credentials::user_account::Builder as UserAccountCredentialBuilder;
3130
use google_cloud_auth::credentials::{
3231
Builder as AccessTokenCredentialBuilder, CacheableResource, Credentials,
@@ -495,23 +494,6 @@ mod tests {
495494
Ok(())
496495
}
497496

498-
#[tokio::test]
499-
async fn testing_credentials() -> Result<()> {
500-
let creds = test_credentials();
501-
let cached_headers = creds.headers(Extensions::new()).await?;
502-
match cached_headers {
503-
CacheableResource::New { entity_tag, data } => {
504-
assert_eq!(entity_tag, EntityTag::default());
505-
assert!(data.is_empty());
506-
}
507-
CacheableResource::NotModified => {
508-
unreachable!("Expecting a header to be present");
509-
}
510-
};
511-
assert_eq!(creds.universe_domain().await, None);
512-
Ok(())
513-
}
514-
515497
#[tokio::test]
516498
async fn get_mds_credentials_from_builder() -> Result<()> {
517499
let test_quota_project = "test-quota-project";

src/gax-internal/tests/grpc_client_polling.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414

1515
#[cfg(all(test, feature = "_internal-grpc-client"))]
1616
mod tests {
17-
use auth::credentials::testing::test_credentials;
1817
use gax::polling_state::PollingState;
1918
use grpc_server::{builder, start_echo_server};
2019

2120
type TestResult = Result<(), Box<dyn std::error::Error>>;
2221

22+
fn test_credentials() -> auth::credentials::Credentials {
23+
auth::credentials::anonymous::Builder::new().build()
24+
}
25+
2326
/// A test policy, the only interesting bit is the name, which is included
2427
/// in debug messages and used in the tests.
2528
#[derive(Debug)]
@@ -90,7 +93,7 @@ mod tests {
9093
async fn request_options_polling_policies() -> TestResult {
9194
let (endpoint, _server) = start_echo_server().await?;
9295
let client = builder(endpoint)
93-
.with_credentials(auth::credentials::testing::test_credentials())
96+
.with_credentials(test_credentials())
9497
.with_polling_error_policy(TestErrorPolicy {
9598
_name: "client-polling-error".to_string(),
9699
})

src/gax-internal/tests/grpc_retry_loop.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414

1515
#[cfg(all(test, feature = "_internal-grpc-client"))]
1616
mod tests {
17-
use auth::credentials::testing::test_credentials;
1817
use gax::options::*;
1918
use gax::retry_policy::{Aip194Strict, RetryPolicyExt};
2019
use google_cloud_gax_internal::grpc;
2120
use grpc_server::google::test::v1::EchoResponse;
2221
use grpc_server::{builder, google, start_fixed_responses};
2322

23+
fn test_credentials() -> auth::credentials::Credentials {
24+
auth::credentials::anonymous::Builder::new().build()
25+
}
26+
2427
#[tokio::test]
2528
async fn no_retry_immediate_success() -> anyhow::Result<()> {
2629
let (endpoint, _server) = start_fixed_responses(vec![success()]).await?;

src/gax-internal/tests/grpc_simple_request.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414

1515
#[cfg(all(test, feature = "_internal-grpc-client"))]
1616
mod tests {
17-
use auth::credentials::testing::test_credentials;
1817
use gax::options::*;
1918
use google_cloud_gax_internal::grpc;
2019
use grpc_server::{builder, google, start_echo_server};
2120

21+
fn test_credentials() -> auth::credentials::Credentials {
22+
auth::credentials::anonymous::Builder::new().build()
23+
}
24+
2225
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
2326
async fn default_endpoint() -> anyhow::Result<()> {
2427
let (endpoint, _server) = start_echo_server().await?;

src/gax-internal/tests/grpc_timeout.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#[cfg(all(test, feature = "_internal-grpc-client"))]
1616
mod tests {
1717
use anyhow::Result;
18-
use auth::credentials::testing::test_credentials;
1918
use gax::options::*;
2019
use gax::retry_policy::{AlwaysRetry, RetryPolicyExt};
2120
use gax::retry_state::RetryState;
@@ -25,6 +24,10 @@ mod tests {
2524
use std::sync::{Arc, Mutex};
2625
use std::time::Duration;
2726

27+
fn test_credentials() -> auth::credentials::Credentials {
28+
auth::credentials::anonymous::Builder::new().build()
29+
}
30+
2831
#[tokio::test(start_paused = true)]
2932
async fn test_no_timeout() -> Result<()> {
3033
let (endpoint, server) = start_echo_server().await?;

src/gax-internal/tests/grpc_user_agent.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ mod test {
1818
use google_cloud_gax_internal::grpc;
1919
use grpc_server::{builder, google, start_echo_server};
2020

21+
fn test_credentials() -> auth::credentials::Credentials {
22+
auth::credentials::anonymous::Builder::new().build()
23+
}
24+
2125
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
2226
async fn test_user_agent() -> anyhow::Result<()> {
2327
let (endpoint, _server) = start_echo_server().await?;
2428
let client = builder(endpoint)
25-
.with_credentials(auth::credentials::testing::test_credentials())
29+
.with_credentials(test_credentials())
2630
.build()
2731
.await?;
2832

src/gax-internal/tests/http_client_errors.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ mod tests {
1919

2020
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
2121

22+
fn test_credentials() -> auth::credentials::Credentials {
23+
auth::credentials::anonymous::Builder::new().build()
24+
}
25+
2226
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
2327
async fn test_error_with_status() -> Result<()> {
2428
use serde_json::Value;
2529
let (endpoint, _server) = echo_server::start().await?;
2630

2731
let client = echo_server::builder(endpoint)
28-
.with_credentials(auth::credentials::testing::test_credentials())
32+
.with_credentials(test_credentials())
2933
.build()
3034
.await?;
3135

src/gax-internal/tests/http_client_polling.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ mod tests {
1818

1919
type TestResult = Result<(), Box<dyn std::error::Error>>;
2020

21+
fn test_credentials() -> auth::credentials::Credentials {
22+
auth::credentials::anonymous::Builder::new().build()
23+
}
24+
2125
/// A test policy, the only interesting bit is the name, which is included
2226
/// in debug messages and used in the tests.
2327
#[derive(Debug)]
@@ -48,7 +52,7 @@ mod tests {
4852
async fn default_polling_policies() -> TestResult {
4953
let (endpoint, _server) = echo_server::start().await?;
5054
let client = echo_server::builder(endpoint)
51-
.with_credentials(auth::credentials::testing::test_credentials())
55+
.with_credentials(test_credentials())
5256
.build()
5357
.await?;
5458

@@ -64,7 +68,7 @@ mod tests {
6468
async fn client_config_polling_policies() -> TestResult {
6569
let (endpoint, _server) = echo_server::start().await?;
6670
let client = echo_server::builder(endpoint)
67-
.with_credentials(auth::credentials::testing::test_credentials())
71+
.with_credentials(test_credentials())
6872
.with_polling_error_policy(TestErrorPolicy {
6973
_name: "client-polling-error".to_string(),
7074
})
@@ -89,7 +93,7 @@ mod tests {
8993
async fn request_options_polling_policies() -> TestResult {
9094
let (endpoint, _server) = echo_server::start().await?;
9195
let client = echo_server::builder(endpoint)
92-
.with_credentials(auth::credentials::testing::test_credentials())
96+
.with_credentials(test_credentials())
9397
.with_polling_error_policy(TestErrorPolicy {
9498
_name: "client-polling-error".to_string(),
9599
})

src/gax-internal/tests/http_metadata.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ mod tests {
5959
}
6060

6161
fn test_config() -> ClientConfig {
62+
let cred = auth::credentials::anonymous::Builder::new().build();
6263
ClientConfig {
63-
cred: auth::credentials::testing::test_credentials().into(),
64+
cred: cred.into(),
6465
..Default::default()
6566
}
6667
}

0 commit comments

Comments
 (0)