From 691df2506f6cc06a9a7b5a24be26ba7a6e26fe1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sim=C3=A3o=20Mata?= Date: Tue, 28 Jan 2020 16:59:00 +0100 Subject: [PATCH] Add test to assert targets.json doesnt change after expire MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Even if assignment was completed before expire Signed-off-by: Simão Mata --- .../director/http/DeviceResourceSpec.scala | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/test/scala/com/advancedtelematic/director/http/DeviceResourceSpec.scala b/src/test/scala/com/advancedtelematic/director/http/DeviceResourceSpec.scala index b22c995..956b8de 100644 --- a/src/test/scala/com/advancedtelematic/director/http/DeviceResourceSpec.scala +++ b/src/test/scala/com/advancedtelematic/director/http/DeviceResourceSpec.scala @@ -105,7 +105,7 @@ class DeviceResourceSpec extends DirectorSpec deviceId } - testWithRepo("targets.json is after after register") { implicit ns => + testWithRepo("targets.json is empty after register") { implicit ns => val deviceId = registerDeviceOk() Get(apiUri(s"device/${deviceId.show}/targets.json")).namespaced ~> routes ~> check { @@ -265,6 +265,26 @@ class DeviceResourceSpec extends DirectorSpec secondTargets.signed.version shouldBe 2 } + testWithRepo("a refreshed targets returns the same assignments as before, even if they were completed") { implicit ns => + val regDev = registerAdminDeviceOk() + + val targetUpdate = GenTargetUpdateRequest.generate + createAssignmentOk(regDev.deviceId, regDev.primary.hardwareId, targetUpdate.some) + + val firstTargets = fetchRoleOk[TargetsRole](regDev.deviceId) + + val deviceManifest = buildPrimaryManifest(regDev.primary, regDev.primaryKey, targetUpdate.to) + + putManifestOk(regDev.deviceId, deviceManifest) + + forceRoleExpire[TargetsRole](regDev.deviceId) + + val secondTargets = fetchRoleOk[TargetsRole](regDev.deviceId) + + secondTargets.signed.expires.isAfter(firstTargets.signed.expires) + secondTargets.signed.targets shouldBe firstTargets.signed.targets + } + testWithRepo("returns a refreshed version of snapshots if it expires") { implicit ns => val regDev = registerAdminDeviceOk()