Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: verify project exists before sending destroy task #474

Merged
merged 3 commits into from
Nov 15, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions gateway/src/api/latest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ async fn delete_project(
) -> Result<AxumJson<project::Response>, Error> {
let project_name = project.clone();

let state = service.find_project(&project_name).await?;

let mut response = project::Response {
name: project_name.to_string(),
state: state.into(),
};

if response.state == shuttle_common::models::project::State::Destroyed {
return Ok(AxumJson(response));
}

// if project exists and isn't `Destroyed`, send destroy task
service
.new_task()
.project(project)
Expand All @@ -132,10 +144,8 @@ async fn delete_project(
.send(&sender)
.await?;

let response = project::Response {
name: project_name.to_string(),
state: shuttle_common::models::project::State::Destroying,
};
response.state = shuttle_common::models::project::State::Destroying;

Ok(AxumJson(response))
}

Expand Down Expand Up @@ -356,6 +366,15 @@ pub mod tests {
.await
.unwrap();

// delete returns 404 for project that doesn't exist
router
.call(delete_project("resurrections").with_header(&authorization))
oddgrd marked this conversation as resolved.
Show resolved Hide resolved
.map_ok(|resp| {
assert_eq!(resp.status(), StatusCode::NOT_FOUND);
})
.await
.unwrap();

Ok(())
}

Expand Down