Skip to content

Commit

Permalink
Create and delete ServiceAccount for integration test
Browse files Browse the repository at this point in the history
Signed-off-by: pbzweihander <pbzweihander@gmail.com>
  • Loading branch information
pbzweihander committed Aug 19, 2022
1 parent 8706b3a commit 40ee0cf
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions kube-client/src/api/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,20 @@ mod test {
let serviceaccount_namespace = "default";
let audiences = vec!["api".to_string()];

// Create TokenRequest
let serviceaccounts: Api<ServiceAccount> = Api::namespaced(client.clone(), serviceaccount_namespace);
let tokenreviews: Api<TokenReview> = Api::all(client);

// Create ServiceAccount
let fake_sa = serde_json::from_value(json!({
"apiVersion": "v1",
"kind": "ServiceAccount",
"metadata": {
"name": serviceaccount_name,
},
}))?;
serviceaccounts.create(&PostParams::default(), &fake_sa).await?;

// Create TokenRequest
let tokenrequest = serviceaccounts
.create_token_request(serviceaccount_name, &PostParams::default(), &TokenRequest {
metadata: Default::default(),
Expand All @@ -132,7 +144,6 @@ mod test {
assert!(!token.is_empty());

// Check created token is valid with TokenReview
let tokenreviews: Api<TokenReview> = Api::all(client);
let tokenreview = tokenreviews
.create(&PostParams::default(), &TokenReview {
metadata: Default::default(),
Expand All @@ -155,6 +166,11 @@ mod test {
))
);

// Cleanup ServiceAccount
serviceaccounts
.delete(serviceaccount_name, &DeleteParams::default())
.await?;

Ok(())
}
}

0 comments on commit 40ee0cf

Please sign in to comment.