Skip to content

Commit

Permalink
Add PrintStreamReporter back to project
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris O'Meara committed Jan 9, 2017
1 parent 9638f24 commit 3f6345d
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/scala/com/chrisomeara/pillar/PrintStreamReporter.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.chrisomeara.pillar

import java.io.PrintStream
import java.util.Date

import com.datastax.driver.core.Session

class PrintStreamReporter(stream: PrintStream) extends Reporter {
override def initializing(session: Session, keyspace: String, replicationOptions: ReplicationOptions) {
stream.println(s"Initializing $keyspace")
}

override def migrating(session: Session, dateRestriction: Option[Date]) {
stream.println(s"Migrating with date restriction $dateRestriction")
}

override def applying(migration: Migration) {
stream.println(s"Applying ${migration.authoredAt.getTime}: ${migration.description}")
}

override def reversing(migration: Migration) {
stream.println(s"Reversing ${migration.authoredAt.getTime}: ${migration.description}")
}

override def destroying(session: Session, keyspace: String) {
stream.println(s"Destroying $keyspace")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.chrisomeara.pillar

import com.datastax.driver.core.Session
import org.scalatest._
import org.scalatest.matchers.ShouldMatchers
import java.io.{ByteArrayOutputStream, PrintStream}
import java.util.Date

import org.scalatest.mock.MockitoSugar

class PrintStreamReporterSpec extends FunSpec with MockitoSugar with Matchers with OneInstancePerTest {
val session = mock[Session]
val migration = Migration("creates things table", new Date(1370489972546L), Seq("up"), Some(Seq("down")))
val output = new ByteArrayOutputStream()
val stream = new PrintStream(output)
val reporter = new PrintStreamReporter(stream)
val keyspace = "myks"

describe("#initializing") {
it("should print to the stream") {
reporter.initializing(session, keyspace, ReplicationOptions.default)
output.toString should equal("Initializing myks\n")
}
}

describe("#migrating") {
describe("without date restriction") {
it("should print to the stream") {
reporter.migrating(session, None)
output.toString should equal("Migrating with date restriction None\n")
}
}
}

describe("#applying") {
it("should print to the stream") {
reporter.applying(migration)
output.toString should equal("Applying 1370489972546: creates things table\n")
}
}

describe("#reversing") {
it("should print to the stream") {
reporter.reversing(migration)
output.toString should equal("Reversing 1370489972546: creates things table\n")
}
}

describe("#destroying") {
it("should print to the stream") {
reporter.destroying(session, keyspace)
output.toString should equal("Destroying myks\n")
}
}
}

0 comments on commit 3f6345d

Please sign in to comment.