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

refactor: specs2 and is supposed to be used to chain two assertions… #6147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ class VariableTest extends Specification {
} yield {
variableSpecParser.parseSectionVariableSpec("default section", specNode)
})
(sysvar.size === 1) and (sysvar.head must beLeft[LoadTechniqueError])
sysvar.size === 1
sysvar.head must beLeft
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ class HooksTest() extends Specification with AfterAll {
1.second,
500.millis
)

(timeout must beEqualTo(HookTimeout(Some(6.seconds), Some(10.seconds)))) and (res must beEqualTo(Ok("", "")))
timeout must beEqualTo(HookTimeout(Some(6.seconds), Some(10.seconds)))
res must beEqualTo(Ok("", ""))
}

// This one is more for testing performance. I don't want to make it a test, because in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@ class NodeCountHistorizationTest extends Specification with BeforeAfter {
ZioRuntime.unsafeRun(prog.provideLayer(Scope.default >>> testEnvironment))
val lines = File(rootDir, "nodes-2020-03").lines(StandardCharsets.UTF_8).toVector

(lines.size must beEqualTo(3)) and (
(lines(1) must beEqualTo(""""2020-03-20T03:49:36Z";"1";"2";"3";"4";"5";"6"""")) and
(lines(2) must beEqualTo(""""2020-03-20T03:49:37Z";"35";"46";"57";"68";"79";"3""""))
)
lines.size must beEqualTo(3)
lines(1) must beEqualTo(""""2020-03-20T03:49:36Z";"1";"2";"3";"4";"5";"6"""")
lines(2) must beEqualTo(""""2020-03-20T03:49:37Z";"35";"46";"57";"68";"79";"3"""")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ class TestTechniqueCompilationCache extends Specification with BeforeAfterAll {
(writeCache.syncOne(newError) *> // println(mockActor.messages.head).succeed *>
msgLock.withPermit(
(mockActor hasReceivedMessage_? UpdateCompilationStatus(expectedCompilationStatus ++ newErrorStatus)).succeed
)).runNow.aka("actor received message") must beTrue and (mockActor.messageCount must beEqualTo(1))
)).runNow.aka("actor received message") must beTrue
mockActor.messageCount must beEqualTo(1)
}

"update an existing technique in error" in {
Expand Down Expand Up @@ -307,14 +308,16 @@ class TestTechniqueCompilationCache extends Specification with BeforeAfterAll {
(writeCache.syncTechniqueActiveStatus(newError.id) *>
msgLock.withPermit(
(mockActor hasReceivedMessage_? UpdateCompilationStatus(newErrorStatus)).succeed
)).runNow.aka("actor received message") must beTrue and (mockActor.messageCount must beEqualTo(2))
)).runNow.aka("actor received message") must beTrue
mockActor.messageCount must beEqualTo(2)
}

"unsync one" in {
(writeCache.unsyncOne(newError.id -> newError.version) *>
msgLock.withPermit(
(mockActor hasReceivedMessage_? UpdateCompilationStatus(CompilationStatusAllSuccess)).succeed
)).runNow.aka("actor received message") must beTrue and (mockActor.messageCount must beEqualTo(3))
)).runNow.aka("actor received message") must beTrue
mockActor.messageCount must beEqualTo(3)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ class ReportsTest extends DBCommon {

val checkInsert = transacRun(xa => sql"""select id from ruddersysevents""".query[Long].to[Vector].transact(xa)).size

(checkInsert must beEqualTo(14)) and
(res._1 must contain(exactly(expected*)))
checkInsert must beEqualTo(14)
res._1 must contain(exactly(expected*))
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class RuleValServiceTest extends Specification {
vars.get(ComponentId(reportKeysVariableName("component1"), "component1" :: "root section" :: Nil, None)) match {
case None => ko(s"Excepted variable variable_component1, but got nothing. The variables are ${variables}")
case Some(variable) =>
variable.values.size === 3 and
variable.values.size === 3
variable.values === Seq("variable_component1", "variable_component1one", "variable_component1two")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ class CachedFindRuleNodeStatusReportsTest extends Specification {
// these one are not expired (but false)
val okId = finder.reports.keySet

(n1 must beEqualTo(Map())) and
(n2 must beEqualTo(finder.reports.filter(x => okId.contains(x._1)))) and
n1 must beEqualTo(Map())
n2 must beEqualTo(finder.reports.filter(x => okId.contains(x._1)))
// second time, only the node with changing status (pending and compute) are invalidated
(finder.updated.size must beEqualTo(9 + 2))
finder.updated.size must beEqualTo(9 + 2)
}

"When run are expired but we keep compliance, we keep compliance in repo" >> {
Expand Down Expand Up @@ -305,8 +305,8 @@ class CachedFindRuleNodeStatusReportsTest extends Specification {
// let a chance for zio to exec again to find back expired
Thread.sleep(1000)

(n1 must beEqualTo(Map())) and
(n2 must beEqualTo(finder.reports)) and
(finder.updated.size must beEqualTo(9)) // second time, only expired are invalidate: none here
n1 must beEqualTo(Map())
n2 must beEqualTo(finder.reports)
finder.updated.size must beEqualTo(9) // second time, only expired are invalidate: none here
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ class TestInstanceIdService extends Specification {
"make instance" in {
"with non-existing file without creating the file" in {
val file = File("/tmp/rudder-test-instance-id-not-exists")
(InstanceIdService.make(file, instanceIdGenerator).either.runNow must beRight(
InstanceIdService.make(file, instanceIdGenerator).either.runNow must beRight(
beLike[InstanceIdService](_.instanceId must beEqualTo(instanceIdGenerator.newInstanceId))
)) and (
file.exists must beFalse
)
file.exists must beFalse
}

"existing file" in File.temporaryFile("rudder-test-instance-id-", "", None, Attributes.default) { tmpFile =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ class TestMigrateJsonTechniquesToYaml extends Specification with ContentMatchers

"There is only three techniques to migrate" >> {
val res = migration.getAllTechniqueFiles(gitMock.configurationRepositoryRoot / "techniques").runNow
(res.size === 3) and
(res.map(_.parent.parent.name) must containTheSameElementsAs(
res.size === 3
res.map(_.parent.parent.name) must containTheSameElementsAs(
List("technique_with_blocks", "technique_with_error", "technique_with_parameters")
))
)
}

"After migration, the config repo matches what is expected" >> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,15 @@ class LoadDemoDataTest extends Specification {
val dn = new DN("ou=Machines,ou=Accepted Inventories,ou=Inventories,cn=rudder-configuration")
val newParent = new DN("ou=Not Existing Place For Inventories,ou=Inventories,cn=rudder-configuration")

val res = ldap.newConnection.flatMap(_.move(dn, newParent)).either.runNow
/*
* Failure message is:
* Can not move 'biosName=bios1,machineId=machine2,ou=Machines,ou=Accepted Inventories,ou=Inventories,cn=rudder-configuration' to new parent
* 'machineId=machine-does-not-exists,ou=Machines,ou=Accepted Inventories,ou=Inventories,cn=rudder-configuration': Unable to modify the DN of entry
* 'biosName=bios1,machineId=machine2,ou=Machines,ou=Accepted Inventories,ou=Inventories,cn=rudder-configuration' because the parent for the new DN
* 'biosName=bios1,machineId=machine-does-not-exists,ou=Machines,ou=Accepted Inventories,ou=Inventories,cn=rudder-configuration' does not exist.
*/
res must beAnInstanceOf[Left[LDAPRudderError, ?]] and (
ldap.newConnection.flatMap(_.exists(dn)).runNow must beTrue
)

ldap.newConnection.flatMap(_.move(dn, newParent)).either.runNow must beLeft
ldap.newConnection.flatMap(_.exists(dn)).runNow must beTrue
}

"Missing attribute is a grave message that should not be ignored (#10067)" in {
Expand Down