Skip to content

Commit

Permalink
basic test, move views to views.rs, exempt from authz test
Browse files Browse the repository at this point in the history
  • Loading branch information
david-crespo committed Sep 1, 2023
1 parent 324eb2a commit 5915d70
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
17 changes: 4 additions & 13 deletions nexus/src/external_api/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,17 +366,6 @@ pub fn external_api() -> NexusApiDescription {
// clients. Client generators use operationId to name API methods, so changing
// a function name is a breaking change from a client perspective.

#[derive(Clone, Debug, Eq, PartialEq, Serialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
enum SystemHealthStatus {
Ok,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, JsonSchema)]
struct SystemHealth {
status: SystemHealthStatus,
}

/// Get API status
///
/// Always tries to return Ok. If the API is down, it will either 500 or time out.
Expand All @@ -387,8 +376,10 @@ struct SystemHealth {
}]
async fn system_health(
_rqctx: RequestContext<Arc<ServerContext>>,
) -> Result<HttpResponseOk<SystemHealth>, HttpError> {
Ok(HttpResponseOk(SystemHealth { status: SystemHealthStatus::Ok }))
) -> Result<HttpResponseOk<views::SystemHealth>, HttpError> {
Ok(HttpResponseOk(views::SystemHealth {
status: views::SystemHealthStatus::Ok,
}))
}

/// Fetch the top-level IAM policy
Expand Down
13 changes: 12 additions & 1 deletion nexus/tests/integration_tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use http::StatusCode;
use omicron_common::api::external::IdentityMetadataCreateParams;
use omicron_common::api::external::IdentityMetadataUpdateParams;
use omicron_common::api::external::Name;
use omicron_nexus::external_api::{params, views::Project};
use omicron_nexus::external_api::params;
use omicron_nexus::external_api::views::{self, Project};
use serde::Serialize;
use uuid::Uuid;

Expand Down Expand Up @@ -546,3 +547,13 @@ async fn test_projects_list(cptestctx: &ControlPlaneTestContext) {
.collect::<Vec<Uuid>>()
);
}

#[nexus_test]
async fn test_system_health(cptestctx: &ControlPlaneTestContext) {
let client = &cptestctx.external_client;

let health = NexusRequest::object_get(client, "/v1/system/health")
.execute_and_parse_unwrap::<views::SystemHealth>()
.await;
assert_eq!(health.status, views::SystemHealthStatus::Ok);
}
1 change: 0 additions & 1 deletion nexus/tests/integration_tests/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,5 @@ lazy_static! {
AllowedMethod::GetNonexistent
],
},

];
}
1 change: 1 addition & 0 deletions nexus/tests/output/uncovered-authz-endpoints.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
API endpoints with no coverage in authz tests:
system_health (get "/v1/system/health")
device_auth_request (post "/device/auth")
device_auth_confirm (post "/device/confirm")
device_access_token (post "/device/token")
Expand Down
13 changes: 13 additions & 0 deletions nexus/types/src/external_api/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,16 @@ pub struct UpdateDeployment {
pub version: SemverVersion,
pub status: UpdateStatus,
}

// SYSTEM HEALTH

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum SystemHealthStatus {
Ok,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct SystemHealth {
pub status: SystemHealthStatus,
}

0 comments on commit 5915d70

Please sign in to comment.