I am writing tests that involve sending data with an authentication value through the header element. I did some searching and found this line of code:
let header = test::TestRequest::default().insert_header(
actix_web::http::header::AUTHORIZATION,
HeaderValue::from(.....) // This line
).to_http_request();
```, and it used content-length instead of authentication. I don't how to send the basic authentication through the headervalue element when it is not one of the types it takes in.
Here is my code:
```...
let data = <initializing data>;
let app = test::init_service(
App::new()
.app_data(data)
.service(<app_service>))
.await;
let basicAuth = BasicAuth::from(Basic::new("<username>", Some("<password>")));
let header = test::TestRequest::default().insert_header(
actix_web::http::header::AUTHORIZATION,
HeaderValue::from(.....) // This line
).to_http_request();
let req = test::TestRequest::put().uri("<route>").app_data(http_req).to_request();
let resp: MyResponse = test::call_and_read_body_json(&app, req).await;
...
ok. How do you add the header element to the request and how should I initialize the header element? I realized passing in the http request through the .app_data function was not working.