Skip to content

Commit

Permalink
Add integration tests for automatic project deletion (#4136)
Browse files Browse the repository at this point in the history
* Add integration tests for automatic project deletion

---------

Co-authored-by: Simon Dumas <simon.dumas@epfl.ch>
  • Loading branch information
imsdu and Simon Dumas authored Aug 7, 2023
1 parent 221b199 commit a31dc9f
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 16 deletions.
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
): 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))
}

}

0 comments on commit a31dc9f

Please sign in to comment.