|
| 1 | +use http::method::Method; |
| 2 | +use http::StatusCode; |
1 | 3 | use omicron_common::api::IdentityMetadataCreateParams; |
2 | 4 | use omicron_common::api::Name; |
3 | 5 | use omicron_common::api::ProjectCreateParams; |
4 | 6 | use omicron_common::api::ProjectView; |
| 7 | +use omicron_common::api::VPCCreateParams; |
5 | 8 | use omicron_common::api::VPCView; |
6 | 9 | use std::convert::TryFrom; |
7 | 10 |
|
| 11 | +use dropshot::test_util::object_get; |
8 | 12 | use dropshot::test_util::objects_list_page; |
9 | 13 | use dropshot::test_util::objects_post; |
10 | 14 | use dropshot::test_util::ClientTestContext; |
11 | 15 |
|
12 | 16 | pub mod common; |
| 17 | +use common::identity_eq; |
13 | 18 | use common::test_setup; |
14 | 19 |
|
15 | 20 | #[macro_use] |
@@ -40,8 +45,72 @@ async fn test_vpcs() { |
40 | 45 | /* List vpcs. There aren't any yet. */ |
41 | 46 | let vpcs = vpcs_list(&client, &vpcs_url).await; |
42 | 47 | assert_eq!(vpcs.len(), 0); |
| 48 | + |
| 49 | + // /* Make sure we get a 404 if we fetch one. */ |
| 50 | + let vpc_url = format!("{}/just-rainsticks", vpcs_url); |
| 51 | + |
| 52 | + // let error = client |
| 53 | + // .make_request_error(Method::GET, &vpc_url, StatusCode::NOT_FOUND) |
| 54 | + // .await; |
| 55 | + // assert_eq!( |
| 56 | + // error.message, |
| 57 | + // "not found: vpc with name \"just-rainsticks\"" |
| 58 | + // ); |
| 59 | + |
| 60 | + // /* Ditto if we try to delete one. */ |
| 61 | + // let error = client |
| 62 | + // .make_request_error( |
| 63 | + // Method::DELETE, |
| 64 | + // &vpc_url, |
| 65 | + // StatusCode::NOT_FOUND, |
| 66 | + // ) |
| 67 | + // .await; |
| 68 | + // assert_eq!( |
| 69 | + // error.message, |
| 70 | + // "not found: vpc with name \"just-rainsticks\"" |
| 71 | + // ); |
| 72 | + |
| 73 | + /* Create a VPC. */ |
| 74 | + let new_vpc = VPCCreateParams { |
| 75 | + identity: IdentityMetadataCreateParams { |
| 76 | + name: Name::try_from("just-rainsticks").unwrap(), |
| 77 | + description: String::from("sells rainsticks"), |
| 78 | + }, |
| 79 | + }; |
| 80 | + let vpc: VPCView = objects_post(&client, &vpcs_url, new_vpc.clone()).await; |
| 81 | + assert_eq!(vpc.identity.name, "just-rainsticks"); |
| 82 | + assert_eq!(vpc.identity.description, "sells rainsticks"); |
| 83 | + |
| 84 | + /* Attempt to create a second VPC with a conflicting name. */ |
| 85 | + // let error = client |
| 86 | + // .make_request_error_body( |
| 87 | + // Method::POST, |
| 88 | + // &vpcs_url, |
| 89 | + // new_vpc, |
| 90 | + // StatusCode::BAD_REQUEST, |
| 91 | + // ) |
| 92 | + // .await; |
| 93 | + // assert_eq!(error.message, "already exists: instance \"just-rainsticks\""); |
| 94 | + |
| 95 | + /* List VPCs again and expect to find the one we just created. */ |
| 96 | + let vpcs = vpcs_list(&client, &vpcs_url).await; |
| 97 | + assert_eq!(vpcs.len(), 1); |
| 98 | + vpcs_eq(&vpcs[0], &vpc); |
| 99 | + |
| 100 | + /* Fetch the VPC and expect it to match. */ |
| 101 | + // let vpc = vpc_get(&client, &vpc_url).await; |
| 102 | + // vpcs_eq(&vpcs[0], &vpc); |
43 | 103 | } |
44 | 104 |
|
45 | 105 | async fn vpcs_list(client: &ClientTestContext, vpcs_url: &str) -> Vec<VPCView> { |
46 | 106 | objects_list_page::<VPCView>(client, vpcs_url).await.items |
47 | 107 | } |
| 108 | + |
| 109 | +async fn vpc_get(client: &ClientTestContext, vpc_url: &str) -> VPCView { |
| 110 | + object_get::<VPCView>(client, vpc_url).await |
| 111 | +} |
| 112 | + |
| 113 | +fn vpcs_eq(vpc1: &VPCView, vpc2: &VPCView) { |
| 114 | + identity_eq(&vpc1.identity, &vpc2.identity); |
| 115 | + assert_eq!(vpc1.project_id, vpc2.project_id); |
| 116 | +} |
0 commit comments