Skip to content

Commit af4d074

Browse files
authored
chore: Add roundtip test for compute keypairs (#1176)
1 parent 797b2dc commit af4d074

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
//
13+
// SPDX-License-Identifier: Apache-2.0
14+
15+
use assert_cmd::prelude::*;
16+
use rand::distr::{Alphanumeric, SampleString};
17+
use serde_json::Value;
18+
use std::process::Command;
19+
20+
const PUBLIC_KEY: &str = "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMNR0VlJUeGZI/ax5NOoMM8amfT4zdUv4LysQSAC8D0G3A6Bs9hUZ120+2LLTvAS2GQAU3EtaJQNgJi7G1kYHA8=";
21+
22+
#[test]
23+
fn roundtrip() -> Result<(), Box<dyn std::error::Error>> {
24+
let kp_name = format!(
25+
"test-rust-{}",
26+
Alphanumeric.sample_string(&mut rand::rng(), 16)
27+
);
28+
29+
let output = Command::cargo_bin("osc")?
30+
.args([
31+
"compute",
32+
"keypair",
33+
"create210",
34+
"--name",
35+
&kp_name,
36+
"--public-key",
37+
PUBLIC_KEY,
38+
"-o",
39+
"json",
40+
])
41+
.output()
42+
.expect("failed to create keypair");
43+
let data: Value = serde_json::from_slice(&output.stdout)?;
44+
let public_key = data["public_key"].as_str().expect("ID is present");
45+
46+
assert_eq!(public_key, PUBLIC_KEY);
47+
48+
let output = Command::cargo_bin("osc")?
49+
.args(["compute", "keypair", "show", &kp_name, "-o", "json"])
50+
.output()
51+
.expect("failed to show keypair");
52+
let _data: Value = serde_json::from_slice(&output.stdout)?;
53+
54+
Command::cargo_bin("osc")?
55+
.args(["compute", "keypair", "delete", &kp_name])
56+
.ok()?;
57+
58+
Ok(())
59+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
//
13+
// SPDX-License-Identifier: Apache-2.0
14+
15+
use assert_cmd::prelude::*;
16+
use rand::distr::{Alphanumeric, SampleString};
17+
use serde_json::Value;
18+
use std::process::Command;
19+
20+
const PUBLIC_KEY: &str = "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMNR0VlJUeGZI/ax5NOoMM8amfT4zdUv4LysQSAC8D0G3A6Bs9hUZ120+2LLTvAS2GQAU3EtaJQNgJi7G1kYHA8=";
21+
22+
#[test]
23+
fn roundtrip() -> Result<(), Box<dyn std::error::Error>> {
24+
let kp_name = format!(
25+
"test-rust-{}",
26+
Alphanumeric.sample_string(&mut rand::rng(), 16)
27+
);
28+
29+
let output = Command::cargo_bin("osc")?
30+
.args([
31+
"compute",
32+
"keypair",
33+
"create292",
34+
"--name",
35+
&kp_name,
36+
"--public-key",
37+
PUBLIC_KEY,
38+
"-o",
39+
"json",
40+
])
41+
.output()
42+
.expect("failed to create keypair");
43+
let data: Value = serde_json::from_slice(&output.stdout)?;
44+
let public_key = data["public_key"].as_str().expect("ID is present");
45+
46+
assert_eq!(public_key, PUBLIC_KEY);
47+
48+
let output = Command::cargo_bin("osc")?
49+
.args(["compute", "keypair", "show", &kp_name, "-o", "json"])
50+
.output()
51+
.expect("failed to show keypair");
52+
let _data: Value = serde_json::from_slice(&output.stdout)?;
53+
54+
Command::cargo_bin("osc")?
55+
.args(["compute", "keypair", "delete", &kp_name])
56+
.ok()?;
57+
58+
Ok(())
59+
}

openstack_cli/tests/compute/v2/keypair/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ mod create_210_autogen;
1717
mod create_21_autogen;
1818
mod create_22_autogen;
1919
mod create_292_autogen;
20+
mod crud_210;
21+
mod crud_292;
2022
mod delete_autogen;
2123
mod list_autogen;
2224
mod show_autogen;

0 commit comments

Comments
 (0)