Skip to content
This repository
Browse code

End-to-end tests.

Add tests that hit a running mongo to verify that the queries Rogue
formulates actually do what we expect.

 * Factored test models from QueryTest into TestModels.scala
 * Made EndToEndTest with some simple query tests that I lifted from
   QueryTest.
 * Added a start-test-mongo.sh script to fetch a mongo binary if
   necessary, make a mongo-testdb directory for its data, and start it.
 * Added a RogueTestMongo mongo identifier and made all of the test
   models use it. It connects to localhost:37648 (EROGU), the same port
   that start-test-mongo.sh uses.
 * Added some stuff to gitignore too.
  • Loading branch information...
commit 75a7d4c7a8eba61ab7dabb4e11c917249d44cbd8 1 parent f40d13a
Neil Sanchala authored December 14, 2011
5  .gitignore
@@ -9,3 +9,8 @@ sbtlib
9 9
 target
10 10
 out
11 11
 *~
  12
+mongo-testdb
  13
+dependencies
  14
+mongo.log
  15
+tags
  16
+tags.old
2  sbt
... ...
@@ -1,3 +1,5 @@
  1
+#!/bin/bash
  2
+
1 3
 # Internal options, always specified
2 4
 INTERNAL_OPTS="-Dfile.encoding=UTF-8 -Xss8M -Xmx1G -noverify -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -XX:MaxPermSize=512M"
3 5
 
162  src/test/scala/com/foursquare/rogue/EndToEndTest.scala
... ...
@@ -0,0 +1,162 @@
  1
+// Copyright 2011 Foursquare Labs Inc. All Rights Reserved.
  2
+package com.foursquare.rogue
  3
+
  4
+import com.foursquare.rogue.Rogue._
  5
+
  6
+import java.util.regex.Pattern
  7
+import net.liftweb.common.{Box, Empty, Full}
  8
+import org.bson.types.ObjectId
  9
+import org.junit.{Before, After, Ignore, Test}
  10
+import org.specs.SpecsMatchers
  11
+
  12
+/**
  13
+ * Contains tests that test the interaction of Rogue with a real mongo.
  14
+ */
  15
+class EndToEndTest extends SpecsMatchers {
  16
+  def baseTestVenue(): Venue = {
  17
+    Venue.createRecord
  18
+         .legacyid(123)
  19
+         .userid(456)
  20
+         .venuename("test venue")
  21
+         .mayor(789)
  22
+         .mayor_count(3)
  23
+         .closed(false)
  24
+         .popularity(List(1L, 2L, 3L))
  25
+         .categories(List(new ObjectId()))
  26
+         .geolatlng(LatLong(40.73, -73.98))
  27
+         .status(VenueStatus.open)
  28
+         .claims(List(VenueClaimBson.createRecord.userid(1234).status(ClaimStatus.pending),
  29
+                      VenueClaimBson.createRecord.userid(5678).status(ClaimStatus.approved)))
  30
+         .lastClaim(VenueClaimBson.createRecord.userid(5678).status(ClaimStatus.approved))
  31
+  }
  32
+
  33
+  def baseTestVenueClaim(vid: ObjectId): VenueClaim = {
  34
+    VenueClaim.createRecord
  35
+              .venueid(vid)
  36
+              .userid(123)
  37
+              .status(ClaimStatus.approved)
  38
+  }
  39
+
  40
+  def baseTestTip(): Tip = {
  41
+    Tip.createRecord
  42
+       .legacyid(234)
  43
+       .counts(Map("foo" -> 1L,
  44
+                   "bar" -> 2L))
  45
+  }
  46
+
  47
+  @Before
  48
+  def setupMongoConnection: Unit = {
  49
+    RogueTestMongo.connectToMongo
  50
+  }
  51
+
  52
+  @After
  53
+  def cleanupTestData: Unit = {
  54
+    Venue.bulkDelete_!!()
  55
+    Venue.count() must_== 0
  56
+
  57
+    VenueClaim.bulkDelete_!!()
  58
+    VenueClaim.count() must_== 0
  59
+
  60
+    RogueTestMongo.disconnectFromMongo
  61
+  }
  62
+
  63
+  @Test
  64
+  def eqsTests: Unit = {
  65
+    val v = baseTestVenue().save
  66
+    val vc = baseTestVenueClaim(v.id).save
  67
+
  68
+    // eqs
  69
+    Venue.where(_._id eqs v.id).fetch().map(_.id)                         must_== List(v.id)
  70
+    Venue.where(_.mayor eqs v.mayor.value).fetch().map(_.id)              must_== List(v.id)
  71
+    Venue.where(_.mayor eqs v.mayor.value).fetch().map(_.id)              must_== List(v.id)
  72
+    Venue.where(_.venuename eqs v.venuename.value).fetch().map(_.id)      must_== List(v.id)
  73
+    Venue.where(_.closed eqs false).fetch().map(_.id)                     must_== List(v.id)
  74
+
  75
+    Venue.where(_.mayor eqs 432432).fetch().map(_.id)                     must_== Nil
  76
+    Venue.where(_.closed eqs true).fetch().map(_.id)                      must_== Nil
  77
+
  78
+    VenueClaim.where(_.status eqs ClaimStatus.approved).fetch().map(_.id) must_== List(vc.id)
  79
+    VenueClaim.where(_.venueid eqs v.id).fetch().map(_.id)                must_== List(vc.id)
  80
+    VenueClaim.where(_.venueid eqs v).fetch().map(_.id)                   must_== List(vc.id)
  81
+  }
  82
+
  83
+  @Test
  84
+  def testInequalityQueries: Unit = {
  85
+    val v = baseTestVenue().save
  86
+    val vc = baseTestVenueClaim(v.id).save
  87
+
  88
+    // neq,lt,gt, where the lone Venue has mayor_count=3, and the only
  89
+    // VenueClaim has status approved.
  90
+    Venue.where(_.mayor_count neqs 5).fetch().map(_.id)                     must_== List(v.id)
  91
+    Venue.where(_.mayor_count < 5).fetch().map(_.id)                        must_== List(v.id)
  92
+    Venue.where(_.mayor_count lt 5).fetch().map(_.id)                       must_== List(v.id)
  93
+    Venue.where(_.mayor_count <= 5).fetch().map(_.id)                       must_== List(v.id)
  94
+    Venue.where(_.mayor_count lte 5).fetch().map(_.id)                      must_== List(v.id)
  95
+    Venue.where(_.mayor_count > 5).fetch().map(_.id)                        must_== Nil
  96
+    Venue.where(_.mayor_count gt 5).fetch().map(_.id)                       must_== Nil
  97
+    Venue.where(_.mayor_count >= 5).fetch().map(_.id)                       must_== Nil
  98
+    Venue.where(_.mayor_count gte 5).fetch().map(_.id)                      must_== Nil
  99
+    Venue.where(_.mayor_count between (3, 5)).fetch().map(_.id)             must_== List(v.id)
  100
+    VenueClaim.where (_.status neqs ClaimStatus.approved).fetch().map(_.id) must_== Nil
  101
+    VenueClaim.where (_.status neqs ClaimStatus.pending).fetch().map(_.id)  must_== List(vc.id)
  102
+  }
  103
+
  104
+  @Test
  105
+  def selectQueries: Unit = {
  106
+    val v = baseTestVenue().save
  107
+
  108
+    val base = Venue.where(_._id eqs v.id)
  109
+    base.select(_.legacyid).fetch() must_== List(v.legacyid.value)
  110
+    base.select(_.legacyid, _.userid).fetch() must_== List((v.legacyid.value, v.userid.value))
  111
+    base.select(_.legacyid, _.userid, _.mayor).fetch() must_== List((v.legacyid.value, v.userid.value, v.mayor.value))
  112
+    base.select(_.legacyid, _.userid, _.mayor, _.mayor_count).fetch() must_== List((v.legacyid.value, v.userid.value, v.mayor.value, v.mayor_count.value))
  113
+    base.select(_.legacyid, _.userid, _.mayor, _.mayor_count, _.closed).fetch() must_== List((v.legacyid.value, v.userid.value, v.mayor.value, v.mayor_count.value, v.closed.value))
  114
+    base.select(_.legacyid, _.userid, _.mayor, _.mayor_count, _.closed, _.tags).fetch() must_== List((v.legacyid.value, v.userid.value, v.mayor.value, v.mayor_count.value, v.closed.value, v.tags.value))
  115
+  }
  116
+
  117
+  @Test
  118
+  def selectEnum: Unit = {
  119
+    val v = baseTestVenue().save
  120
+    Venue.where(_._id eqs v.id).select(_.status).fetch() must_== List(VenueStatus.open)
  121
+  }
  122
+
  123
+  @Test
  124
+  def selectCaseQueries: Unit = {
  125
+    val v = baseTestVenue().save
  126
+
  127
+    val base = Venue.where(_._id eqs v.id)
  128
+    base.selectCase(_.legacyid, V1).fetch() must_== List(V1(v.legacyid.value))
  129
+    base.selectCase(_.legacyid, _.userid, V2).fetch() must_== List(V2(v.legacyid.value, v.userid.value))
  130
+    base.selectCase(_.legacyid, _.userid, _.mayor, V3).fetch() must_== List(V3(v.legacyid.value, v.userid.value, v.mayor.value))
  131
+    base.selectCase(_.legacyid, _.userid, _.mayor, _.mayor_count, V4).fetch() must_== List(V4(v.legacyid.value, v.userid.value, v.mayor.value, v.mayor_count.value))
  132
+    base.selectCase(_.legacyid, _.userid, _.mayor, _.mayor_count, _.closed, V5).fetch() must_== List(V5(v.legacyid.value, v.userid.value, v.mayor.value, v.mayor_count.value, v.closed.value))
  133
+    base.selectCase(_.legacyid, _.userid, _.mayor, _.mayor_count, _.closed, _.tags, V6).fetch() must_== List(V6(v.legacyid.value, v.userid.value, v.mayor.value, v.mayor_count.value, v.closed.value, v.tags.value))
  134
+  }
  135
+
  136
+  @Test
  137
+  def selectSubfieldQueries: Unit = {
  138
+    val v = baseTestVenue().save
  139
+    val t = baseTestTip().save
  140
+
  141
+    // select subfields
  142
+    Tip.where(_._id eqs t.id).select(_.counts at "foo").fetch() must_== List(Full(1L))
  143
+
  144
+    Venue.where(_._id eqs v.id).select(_.geolatlng.unsafeField[Double]("lat")).fetch() must_== List(Full(40.73))
  145
+  }
  146
+
  147
+  @Ignore("These tests are broken because DummyField doesn't know how to convert a String to an Enum")
  148
+  def testSelectEnumSubfield: Unit = {
  149
+    val v = baseTestVenue().save
  150
+
  151
+    // This behavior is broken because we get a String back from mongo, and at
  152
+    // that point we only have a DummyField for the subfield, and that doesn't
  153
+    // know how to convert the String to an Enum.
  154
+
  155
+    val statuses: List[Box[VenueClaimBson.status.MyType]] =
  156
+          Venue.where(_._id eqs v.id).select(_.lastClaim.subfield(_.status)) .fetch()
  157
+    // This assertion works.
  158
+    statuses must_== List(Full("Approved"))
  159
+    // This assertion is what we want, and it fails.
  160
+    // statuses must_== List(Full(ClaimStatus.approved))
  161
+  }
  162
+}
101  src/test/scala/com/foursquare/rogue/QueryTest.scala
@@ -14,107 +14,6 @@ import org.joda.time.{DateTime, DateTimeZone}
14 14
 import org.junit._
15 15
 import org.specs.SpecsMatchers
16 16
 
17  
-/////////////////////////////////////////////////
18  
-// Sample records for testing
19  
-/////////////////////////////////////////////////
20  
-object VenueStatus extends Enumeration {
21  
-  val open = Value("Open")
22  
-  val closed = Value("Closed")
23  
-}
24  
-
25  
-class Venue extends MongoRecord[Venue] with MongoId[Venue] {
26  
-  def meta = Venue
27  
-  object legacyid extends LongField(this) { override def name = "legid" }
28  
-  object userid extends LongField(this)
29  
-  object venuename extends StringField(this, 255)
30  
-  object mayor extends LongField(this)
31  
-  object mayor_count extends LongField(this)
32  
-  object closed extends BooleanField(this)
33  
-  object tags extends MongoListField[Venue, String](this)
34  
-  object popularity extends MongoListField[Venue, Long](this)
35  
-  object categories extends MongoListField[Venue, ObjectId](this)
36  
-  object geolatlng extends MongoCaseClassField[Venue, LatLong](this) { override def name = "latlng" }
37  
-  object last_updated extends DateTimeField(this)
38  
-  object status extends EnumNameField(this, VenueStatus) { override def name = "status" }
39  
-  object claims extends BsonRecordListField(this, VenueClaimBson)
40  
-  object lastClaim extends BsonRecordField(this, VenueClaimBson)
41  
-}
42  
-object Venue extends Venue with MongoMetaRecord[Venue] {
43  
-  object CustomIndex extends IndexModifier("custom")
44  
-  val idIdx = Venue.index(_._id, Asc)
45  
-  val legIdx = Venue.index(_.legacyid, Desc)
46  
-  val geoIdx = Venue.index(_.geolatlng, TwoD)
47  
-  val geoCustomIdx = Venue.index(_.geolatlng, CustomIndex, _.tags, Asc)
48  
-
49  
-  trait FK[T <: FK[T]] extends MongoRecord[T] {
50  
-    self: T=>
51  
-    object venueid extends ObjectIdField[T](this) with HasMongoForeignObjectId[Venue] {
52  
-      override def name = "vid"
53  
-    }
54  
-  }
55  
-}
56  
-
57  
-object ClaimStatus extends Enumeration {
58  
-  val pending = Value("Pending approval")
59  
-  val approved = Value("Approved")
60  
-}
61  
-
62  
-class VenueClaim extends MongoRecord[VenueClaim] with MongoId[VenueClaim] with Venue.FK[VenueClaim] {
63  
-  def meta = VenueClaim
64  
-  object userid extends LongField(this) { override def name = "uid" }
65  
-  object status extends EnumNameField(this, ClaimStatus)
66  
-}
67  
-object VenueClaim extends VenueClaim with MongoMetaRecord[VenueClaim] {
68  
-  override def fieldOrder = List(status, _id, userid, venueid)
69  
-}
70  
-
71  
-class VenueClaimBson extends BsonRecord[VenueClaimBson] {
72  
-  def meta = VenueClaimBson
73  
-  object userid extends LongField(this) { override def name = "uid" }
74  
-  object status extends EnumNameField(this, ClaimStatus)
75  
-}
76  
-object VenueClaimBson extends VenueClaimBson with BsonMetaRecord[VenueClaimBson] {
77  
-  override def fieldOrder = List(status, userid)
78  
-}
79  
-
80  
-
81  
-case class OneComment(timestamp: String, userid: Long, comment: String)
82  
-class Comment extends MongoRecord[Comment] with MongoId[Comment] {
83  
-  def meta = Comment
84  
-  object comments extends MongoCaseClassListField[Comment, OneComment](this)
85  
-}
86  
-object Comment extends Comment with MongoMetaRecord[Comment] {
87  
-  val idx1 = Comment.index(_._id, Asc)
88  
-}
89  
-
90  
-class Tip extends MongoRecord[Tip] with MongoId[Tip] {
91  
-  def meta = Tip
92  
-  object legacyid extends LongField(this) { override def name = "legid" }
93  
-  object counts extends MongoMapField[Tip, Long](this)
94  
-}
95  
-object Tip extends Tip with MongoMetaRecord[Tip]
96  
-
97  
-object ConsumerPrivilege extends Enumeration {
98  
-  val awardBadges = Value("Award badges")
99  
-}
100  
-
101  
-class OAuthConsumer extends MongoRecord[OAuthConsumer] with MongoId[OAuthConsumer] {
102  
-  def meta = OAuthConsumer
103  
-  object privileges extends MongoListField[OAuthConsumer, ConsumerPrivilege.Value](this)
104  
-}
105  
-object OAuthConsumer extends OAuthConsumer with MongoMetaRecord[OAuthConsumer]
106  
-
107  
-case class V1(legacyid: Long)
108  
-case class V2(legacyid: Long, userid: Long)
109  
-case class V3(legacyid: Long, userid: Long, mayor: Long)
110  
-case class V4(legacyid: Long, userid: Long, mayor: Long, mayor_count: Long)
111  
-case class V5(legacyid: Long, userid: Long, mayor: Long, mayor_count: Long, closed: Boolean)
112  
-case class V6(legacyid: Long, userid: Long, mayor: Long, mayor_count: Long, closed: Boolean, tags: List[String])
113  
-
114  
-/////////////////////////////////////////////////
115  
-// Actual tests
116  
-/////////////////////////////////////////////////
117  
-
118 17
 class QueryTest extends SpecsMatchers {
119 18
 
120 19
   @Test
143  src/test/scala/com/foursquare/rogue/TestModels.scala
... ...
@@ -0,0 +1,143 @@
  1
+// Copyright 2011 Foursquare Labs Inc. All Rights Reserved.
  2
+package com.foursquare.rogue
  3
+
  4
+import com.foursquare.rogue.Rogue._
  5
+
  6
+import com.mongodb.{Mongo, ServerAddress}
  7
+import net.liftweb.mongodb.{MongoDB, MongoIdentifier}
  8
+import net.liftweb.mongodb.record._
  9
+import net.liftweb.mongodb.record.field._
  10
+import net.liftweb.record.field._
  11
+import net.liftweb.record._
  12
+import org.bson.types.ObjectId
  13
+
  14
+/////////////////////////////////////////////////
  15
+// Sample records for testing
  16
+/////////////////////////////////////////////////
  17
+
  18
+object RogueTestMongo extends MongoIdentifier {
  19
+  override def jndiName = "rogue_mongo"
  20
+
  21
+  private var mongo: Option[Mongo] = None
  22
+
  23
+  def connectToMongo = {
  24
+    val MongoPort = 37648
  25
+    mongo = Some(new Mongo(new ServerAddress("localhost", MongoPort)))
  26
+    MongoDB.defineDb(RogueTestMongo, mongo.get, "rogue-test")
  27
+  }
  28
+
  29
+  def disconnectFromMongo = {
  30
+    mongo.foreach(_.close)
  31
+    MongoDB.close
  32
+    mongo = None
  33
+  }
  34
+}
  35
+
  36
+object VenueStatus extends Enumeration {
  37
+  val open = Value("Open")
  38
+  val closed = Value("Closed")
  39
+}
  40
+
  41
+class Venue extends MongoRecord[Venue] with MongoId[Venue] {
  42
+  def meta = Venue
  43
+  object legacyid extends LongField(this) { override def name = "legid" }
  44
+  object userid extends LongField(this)
  45
+  object venuename extends StringField(this, 255)
  46
+  object mayor extends LongField(this)
  47
+  object mayor_count extends LongField(this)
  48
+  object closed extends BooleanField(this)
  49
+  object tags extends MongoListField[Venue, String](this)
  50
+  object popularity extends MongoListField[Venue, Long](this)
  51
+  object categories extends MongoListField[Venue, ObjectId](this)
  52
+  object geolatlng extends MongoCaseClassField[Venue, LatLong](this) { override def name = "latlng" }
  53
+  object last_updated extends DateTimeField(this)
  54
+  object status extends EnumNameField(this, VenueStatus) { override def name = "status" }
  55
+  object claims extends BsonRecordListField(this, VenueClaimBson)
  56
+  object lastClaim extends BsonRecordField(this, VenueClaimBson)
  57
+}
  58
+object Venue extends Venue with MongoMetaRecord[Venue] {
  59
+  override def collectionName = "venues"
  60
+  override def mongoIdentifier = RogueTestMongo
  61
+
  62
+  object CustomIndex extends IndexModifier("custom")
  63
+  val idIdx = Venue.index(_._id, Asc)
  64
+  val legIdx = Venue.index(_.legacyid, Desc)
  65
+  val geoIdx = Venue.index(_.geolatlng, TwoD)
  66
+  val geoCustomIdx = Venue.index(_.geolatlng, CustomIndex, _.tags, Asc)
  67
+
  68
+  trait FK[T <: FK[T]] extends MongoRecord[T] {
  69
+    self: T=>
  70
+    object venueid extends ObjectIdField[T](this) with HasMongoForeignObjectId[Venue] {
  71
+      override def name = "vid"
  72
+    }
  73
+  }
  74
+}
  75
+
  76
+object ClaimStatus extends Enumeration {
  77
+  val pending = Value("Pending approval")
  78
+  val approved = Value("Approved")
  79
+}
  80
+
  81
+class VenueClaim extends MongoRecord[VenueClaim] with MongoId[VenueClaim] with Venue.FK[VenueClaim] {
  82
+  def meta = VenueClaim
  83
+  object userid extends LongField(this) { override def name = "uid" }
  84
+  object status extends EnumNameField(this, ClaimStatus)
  85
+}
  86
+object VenueClaim extends VenueClaim with MongoMetaRecord[VenueClaim] {
  87
+  override def fieldOrder = List(status, _id, userid, venueid)
  88
+  override def collectionName = "venueclaims"
  89
+  override def mongoIdentifier = RogueTestMongo
  90
+}
  91
+
  92
+class VenueClaimBson extends BsonRecord[VenueClaimBson] {
  93
+  def meta = VenueClaimBson
  94
+  object userid extends LongField(this) { override def name = "uid" }
  95
+  object status extends EnumNameField(this, ClaimStatus)
  96
+}
  97
+object VenueClaimBson extends VenueClaimBson with BsonMetaRecord[VenueClaimBson] {
  98
+  override def fieldOrder = List(status, userid)
  99
+}
  100
+
  101
+
  102
+case class OneComment(timestamp: String, userid: Long, comment: String)
  103
+class Comment extends MongoRecord[Comment] with MongoId[Comment] {
  104
+  def meta = Comment
  105
+  object comments extends MongoCaseClassListField[Comment, OneComment](this)
  106
+}
  107
+object Comment extends Comment with MongoMetaRecord[Comment] {
  108
+  override def collectionName = "comments"
  109
+  override def mongoIdentifier = RogueTestMongo
  110
+
  111
+  val idx1 = Comment.index(_._id, Asc)
  112
+}
  113
+
  114
+class Tip extends MongoRecord[Tip] with MongoId[Tip] {
  115
+  def meta = Tip
  116
+  object legacyid extends LongField(this) { override def name = "legid" }
  117
+  object counts extends MongoMapField[Tip, Long](this)
  118
+}
  119
+object Tip extends Tip with MongoMetaRecord[Tip] {
  120
+  override def collectionName = "tips"
  121
+  override def mongoIdentifier = RogueTestMongo
  122
+}
  123
+
  124
+object ConsumerPrivilege extends Enumeration {
  125
+  val awardBadges = Value("Award badges")
  126
+}
  127
+
  128
+class OAuthConsumer extends MongoRecord[OAuthConsumer] with MongoId[OAuthConsumer] {
  129
+  def meta = OAuthConsumer
  130
+  object privileges extends MongoListField[OAuthConsumer, ConsumerPrivilege.Value](this)
  131
+}
  132
+object OAuthConsumer extends OAuthConsumer with MongoMetaRecord[OAuthConsumer] {
  133
+  override def collectionName = "oauthconsumers"
  134
+  override def mongoIdentifier = RogueTestMongo
  135
+}
  136
+
  137
+// Used for selectCase tests.
  138
+case class V1(legacyid: Long)
  139
+case class V2(legacyid: Long, userid: Long)
  140
+case class V3(legacyid: Long, userid: Long, mayor: Long)
  141
+case class V4(legacyid: Long, userid: Long, mayor: Long, mayor_count: Long)
  142
+case class V5(legacyid: Long, userid: Long, mayor: Long, mayor_count: Long, closed: Boolean)
  143
+case class V6(legacyid: Long, userid: Long, mayor: Long, mayor_count: Long, closed: Boolean, tags: List[String])
40  start-test-mongo.sh
... ...
@@ -0,0 +1,40 @@
  1
+#!/bin/bash
  2
+# Usage: ./start-test-mongo.sh
  3
+
  4
+# EROGU
  5
+MONGO_PORT=37648
  6
+
  7
+MY_DIR=$(dirname $0)
  8
+
  9
+# download mongodb if necessary and place it inside the dependencies/ subdirectory.
  10
+MONGO_DIR=osx
  11
+MONGO_VERSION=1.8.4
  12
+MONGO=mongodb-osx-x86_64-$MONGO_VERSION
  13
+
  14
+if [ $(uname) = 'Linux' ]; then
  15
+  MONGO_DIR=linux
  16
+  MONGO=mongodb-linux-x86_64-$MONGO_VERSION
  17
+fi
  18
+
  19
+mkdir -p dependencies
  20
+
  21
+if [ ! -e dependencies/$MONGO ]; then
  22
+  echo "Fetching MongoDB: $MONGO"
  23
+  curl -# http://fastdl.mongodb.org/$MONGO_DIR/$MONGO.tgz | tar -xz -C dependencies/
  24
+fi
  25
+
  26
+# ln -sf doesn't work on mac os x, so we need to rm and recreate.
  27
+rm -f dependencies/mongodb
  28
+ln -sf $MONGO dependencies/mongodb
  29
+
  30
+if ! [ -d mongo-testdb ]; then
  31
+  echo "creating mongo-testdb directly for tests that use mongo"
  32
+  mkdir mongo-testdb
  33
+fi
  34
+
  35
+if ! ./dependencies/mongodb/bin/mongo --port $MONGO_PORT --eval "db.serverStatus()" 2>&1 > /dev/null; then
  36
+  echo "automatically starting up local mongo on $MONGO_PORT so we can use it for tests"
  37
+  ./dependencies/mongodb/bin/mongod --dbpath mongo-testdb --maxConns 800 --port $MONGO_PORT $@ 2>&1 | tee mongo.log
  38
+else
  39
+  echo "great, you have a local mongo running for tests already"
  40
+fi

0 notes on commit 75a7d4c

Please sign in to comment.
Something went wrong with that request. Please try again.