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

Add integration tests for automatic project deletion #4136

Merged
merged 3 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions tests/docker/config/delta-postgres.conf
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,12 @@ plugins {

project-deletion {
enabled = true
included-projects = [
"autodeletion.+"
]
excluded-projects = []
idle-interval = 5s
idle-check-period = 1s
delete-deprecated-projects = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,36 +82,42 @@ class AdminDsl(cl: HttpClient, config: TestsConfig) extends TestHelpers with Cir
id: String,
description: String,
authenticated: Authenticated,
expectedResponse: Option[ExpectedResponse] = None
expectedResponse: Option[ExpectedResponse] = None,
ignoreConflict: Boolean = false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be able to run the test locally multiple times

): Task[Assertion] =
updateOrganization(id, description, authenticated, 0, expectedResponse)
updateOrganization(id, description, authenticated, 0, expectedResponse, ignoreConflict)

def updateOrganization(
id: String,
description: String,
authenticated: Authenticated,
rev: Int,
expectedResponse: Option[ExpectedResponse] = None
expectedResponse: Option[ExpectedResponse] = None,
ignoreConflict: Boolean = false
): Task[Assertion] = {
cl.put[Json](s"/orgs/$id${queryParams(rev)}", orgPayload(description), authenticated) { (json, response) =>
expectedResponse match {
case Some(e) =>
response.status shouldEqual e.statusCode
json shouldEqual e.json
case None =>
if (rev == 0L)
response.status shouldEqual StatusCodes.Created
else
response.status shouldEqual StatusCodes.OK

filterMetadataKeys(json) shouldEqual createOrgRespJson(
id,
rev + 1,
"orgs",
"Organization",
authenticated,
"organizations"
)
if (ignoreConflict && response.status == StatusCodes.Conflict)
succeed
else {
if (rev == 0L)
response.status shouldEqual StatusCodes.Created
else
response.status shouldEqual StatusCodes.OK

filterMetadataKeys(json) shouldEqual createOrgRespJson(
id,
rev + 1,
"orgs",
"Organization",
authenticated,
"organizations"
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package ch.epfl.bluebrain.nexus.tests.kg

import akka.http.scaladsl.model.StatusCodes
import ch.epfl.bluebrain.nexus.tests.BaseSpec
import ch.epfl.bluebrain.nexus.tests.Identity.projects.Bojack
import ch.epfl.bluebrain.nexus.tests.iam.types.Permission.{Events, Organizations, Projects, Resources}
import monix.execution.Scheduler.Implicits.global
import io.circe.Json

import scala.concurrent.duration._

/**
* Tests related to automatic project deletion
*
* Automatic deletion is configured to look up on projects in the `autodeletion` organization and deletes them after 5
* seconds without activity
*
* Only checks that the project deletion has been triggered and that the project itself has been deleted. All the
* additional checks on the deletion of resources/views contained in this project are done in [[ProjectsDeletionSpec]]
*
* @see
* ProjectsDeletionSpec
*/
class AutoProjectDeletionSpec extends BaseSpec {

// We double the default patience in order to make sure that the automatic deletion has time to process the project
implicit override def patienceConfig: PatienceConfig = PatienceConfig(config.patience * 2, 300.millis)

private val org = "autodeletion"
private val proj1 = genId()
private val ref1 = s"$org/$proj1"

override def beforeAll(): Unit = {
super.beforeAll()
val setup = for {
_ <- aclDsl.addPermissions("/", Bojack, Set(Organizations.Create, Projects.Delete, Resources.Read, Events.Read))
// First org and projects
_ <- adminDsl.createOrganization(org, org, Bojack, ignoreConflict = true)
_ <- adminDsl.createProject(org, proj1, kgDsl.projectJson(name = proj1), Bojack)
_ <- deltaClient.get[Json](s"/projects/$ref1", Bojack)(expect(StatusCodes.OK))
} yield succeed

setup.void.runSyncUnsafe()
}

"eventually return a not found when attempting to fetch the project" in eventually {
deltaClient.get[Json](s"/projects/$ref1", Bojack)(expect(StatusCodes.NotFound))
}

}