Scala Embedded InfluxDB

Build Status Codecov Download License

About project

Open-source library for ScalaTest and Specs2, for simply embedding InfluxDB in your test. Built on top of embed-influxDB. Inspired by scalatest-embedmongo.

Integration

Add this dependencies to your build.sbt

// Scalatest
libraryDependencies += "com.github.fsanaulla" %% "scalatest-embedinflux" % <version> % Test

// Specs2
libraryDependencies += "com.github.fsanaulla" %% "specs2-embedinflux" % <version> % Test

Usage

Before you start your testing you need to choose, what type of configuration you need. For example if you need to work with HTTP service. Mix your test suite with InfluxHttpConf. For using UDP feature mix suite with InfluxUDPConf. All port configuration can be changed. By overriding appropriate fields.

HTTP

For starting InfluxDB with HTTP service:

// ScalaTest
class InfluxSpec extends FlatSpec with InfluxHTTPConf with EmbeddedInfluxDB {

  // by default `httpPort`: 8086
  // def httpPort: Int = 8086

  // auth is disabled(false)
  // def auth: Boolean = false

  lazy val influx: InfluxDBClient = _

  ... // your tests
}
// Specs2
class InfluxSpec extends mutable.Specification with InfluxHTTPConf with EmbeddedInfluxDB {

  // by default `httpPort`: 8086
  // def httpPort: Int = 8086

  // auth is disabled(false)
  // def auth: Boolean = false

  lazy val influx: InfluxDBClient = _

  ... // your tests
}

UDP

For UDP support in your tests:

// ScalaTest
class InfluxSpec extends FlatSpec with InfluxUDPConf with EmbeddedInfluxDB {

  // by default `httpPort`: 8086
  // def httpPort: Int = 8086

  // by default `udpPort`: 8089
  // def udpPort: Int = 8089

  // default database name `udp`
  // def databse: Boolean = false

  lazy val influx: InfluxDBClient = _

  ... // your tests
}
// Specs2
class InfluxSpec extends mutable.Specification with InfluxUDPConf with EmbeddedInfluxDB {

  // by default `httpPort`: 8086
  // def httpPort: Int = 8086

  // by default `udpPort`: 8089
  // def udpPort: Int = 8089

  // default database name `udp`
  // def databse: Boolean = false

  lazy val influx: InfluxDBClient = _

  ... // your tests
}

Custom

You can define custom configuration by mixin with InfluxConf into your test suite and overriding configuration method. How to properly configure it look here.