Skip to content

Commit

Permalink
Merge pull request #185 from tumblr/bhaskar-fix-unit-tests
Browse files Browse the repository at this point in the history
Fix unit tests
  • Loading branch information
Bhaskar Maddala committed Aug 4, 2014
2 parents a827683 + 5d4e0cd commit 51d3244
Show file tree
Hide file tree
Showing 10 changed files with 1,702 additions and 29 deletions.
2 changes: 1 addition & 1 deletion app/models/shared/IpAddressable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ trait IpAddressStorage[T <: IpAddressable] extends Schema with AnormAdapter[T] {
* For a range 0L..20L, used addresses List(5,6,7,8,19,20), the result will be Some(8)
* For a range 0L..20L, used addresses List(17,18,19,20), the result will be None (allocate from beginning)
*/
protected def getCurrentLowestLocalMaxAddress(calc: IpAddressCalc)(implicit scope: Option[String]): Option[Long] = {
protected def getCurrentLowestLocalMaxAddress(calc: IpAddressCalc)(implicit scope: Option[String]): Option[Long] = inTransaction {
val minAddress = calc.minAddressAsLong
val maxAddress = calc.maxAddressAsLong
val sortedAddresses = from(tableDef)(t =>
Expand Down
2 changes: 1 addition & 1 deletion app/util/parsers/LshwParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class LshwParser(txt: String) extends CommonParser[LshwRepresentation](txt) {
.map((s: String) => BitStorageUnit(s.toLong))
.getOrElse(
throw AttributeNotFoundException(
"Could not find capacity for network interface"
"Could not find capacity for network interface for %s".format(asset.product)
))
}
}
Expand Down
24 changes: 12 additions & 12 deletions test/controllers/AssetApiSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,66 +117,66 @@ class AssetApiSpec extends ApplicationSpecification with ControllerSpec {
"Support find" in {
"by custom attribute" in new asset {
val req = FakeRequest("GET", findUrl + "?attribute=foo;bar")
val result = Extract.from(api.getAssets(0, 10, "", "", "").apply(req))
val result = Extract.from(api.getAssets(0, 10, "", "TAG", "").apply(req))
result must haveJsonData.which { txt =>
txt must /("data") */("Data") */("TAG" -> assetTag)
}
val req2 = FakeRequest("GET", findUrl + "?attribute=fizz;buzz")
Extract.from(api.getAssets(0, 10, "", "", "").apply(req2)) must haveJsonData.which { txt =>
Extract.from(api.getAssets(0, 10, "", "TAG", "").apply(req2)) must haveJsonData.which { txt =>
txt must /("data") */("Data") */("TAG" -> assetTag)
}
}
"by type" in new asset {
val req = FakeRequest("GET", findUrl + "?type=SERVER_NODE")
val result = Extract.from(api.getAssets(0, 10, "", "", "").apply(req))
val result = Extract.from(api.getAssets(0, 10, "", "TAG", "").apply(req))
result must haveJsonData.which { txt =>
txt must /("data") */("Data") */("TAG" -> assetTag)
}
}
"by status" in new asset {
val req = FakeRequest("GET", findUrl + "?status=Unallocated")
val result = Extract.from(api.getAssets(0, 10, "", "", "").apply(req))
val result = Extract.from(api.getAssets(0, 10, "", "TAG", "").apply(req))
result must haveJsonData.which { txt =>
txt must /("data") */("Data") */("TAG" -> assetTag)
}
}
"by createdAfter" in new asset {
val req = FakeRequest("GET", findUrl + "?createdAfter=2011-12-30T00:00:00")
Extract.from(api.getAssets(0, 10, "", "", "").apply(req)) must haveJsonData.which { txt =>
Extract.from(api.getAssets(0, 10, "", "TAG", "").apply(req)) must haveJsonData.which { txt =>
txt must /("data") */("Data") */("TAG" -> assetTag)
}
val req2 = FakeRequest("GET", findUrl + "?createdAfter=2020-12-30T00:00:00")
Extract.from(api.getAssets(0, 10, "", "", "").apply(req2)) must haveJsonData.which { txt =>
Extract.from(api.getAssets(0, 10, "", "TAG", "").apply(req2)) must haveJsonData.which { txt =>
txt must /("data") */("Pagination") */("TotalResults" -> 0.0)
}
}
"by createdBefore" in new asset {
val req = FakeRequest("GET", findUrl + "?createdBefore=2020-12-30T00:00:00")
Extract.from(api.getAssets(0, 10, "", "", "").apply(req)) must haveJsonData.which { txt =>
Extract.from(api.getAssets(0, 10, "", "TAG", "").apply(req)) must haveJsonData.which { txt =>
txt must /("data") */("Data") */("TAG" -> assetTag)
}
val req2 = FakeRequest("GET", findUrl + "?createdBefore=2011-12-30T00:00:00")
Extract.from(api.getAssets(0, 10, "", "", "").apply(req2)) must haveJsonData.which { txt =>
Extract.from(api.getAssets(0, 10, "", "TAG", "").apply(req2)) must haveJsonData.which { txt =>
txt must /("data") */("Pagination") */("TotalResults" -> 0.0)
}
}
"by updatedAfter" in new asset {
val req = FakeRequest("GET", findUrl + "?updatedAfter=2011-12-30T00:00:00")
Extract.from(api.getAssets(0, 10, "", "", "").apply(req)) must haveJsonData.which { txt =>
Extract.from(api.getAssets(0, 10, "", "TAG", "").apply(req)) must haveJsonData.which { txt =>
txt must /("data") */("Data") */("TAG" -> assetTag)
}
val req2 = FakeRequest("GET", findUrl + "?updatedAfter=2020-12-30T00:00:00")
Extract.from(api.getAssets(0, 10, "", "", "").apply(req2)) must haveJsonData.which { txt =>
Extract.from(api.getAssets(0, 10, "", "TAG", "").apply(req2)) must haveJsonData.which { txt =>
txt must /("data") */("Pagination") */("TotalResults" -> 0.0)
}
}
"by updatedBefore" in new asset {
val req = FakeRequest("GET", findUrl + "?updatedBefore=2020-12-30T00:00:00")
Extract.from(api.getAssets(0, 10, "", "", "").apply(req)) must haveJsonData.which { txt =>
Extract.from(api.getAssets(0, 10, "", "TAG", "").apply(req)) must haveJsonData.which { txt =>
txt must /("data") */("Data") */("TAG" -> assetTag)
}
val req2 = FakeRequest("GET", findUrl + "?updatedAfter=2020-12-30T00:00:00")
Extract.from(api.getAssets(0, 10, "", "", "").apply(req2)) must haveJsonData.which { txt =>
Extract.from(api.getAssets(0, 10, "", "TAG", "").apply(req2)) must haveJsonData.which { txt =>
txt must /("data") */("Pagination") */("TotalResults" -> 0.0)
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/models/CommonHelperSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trait CommonHelperSpec[REP] extends test.ResourceFinder {
val data = getResource(filename)
val parser = getParser(data)
val parsed = parser.parse()
parsed.right.get
parsed.right.getOrElse(throw parsed.left.get)
}


Expand Down
6 changes: 2 additions & 4 deletions test/models/IpmiInfoSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package models
import test.ApplicationSpecification
import util.IpAddress
import util.config.IpmiConfig

import play.api.Configuration

import org.specs2._
import specification._

Expand Down Expand Up @@ -64,13 +62,13 @@ class IpmiInfoSpec extends ApplicationSpecification {
IpmiInfo.deleteByAsset(a3) mustEqual 1
IpmiInfo.createForAsset(a3).dottedAddress mustEqual "172.16.32.22"
}
"createForAsset with rollover" in {
"createForAsset with reuse in range" in {
val asset = ipmiAsset("ipmiAssetTag3")
val ipmiInfo = IpmiInfo.findByAsset(asset).get
IpmiInfo.update(ipmiInfo.copy(address = IpAddress.toLong("172.16.32.254"))) mustEqual 1
val a4 = newIpmiAsset("ipmiAssetTag4")
val ipmi4 = IpmiInfo.createForAsset(a4)
ipmi4.dottedAddress mustEqual "172.16.33.1"
ipmi4.dottedAddress mustEqual "172.16.32.22"
ipmi4.dottedGateway mustEqual "172.16.32.1"
}
"findByAsset" in {
Expand Down
Loading

0 comments on commit 51d3244

Please sign in to comment.