Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
src
README.md

README.md

Generators

Ratatool-Scalacheck contains classes and functions which help with using Scalacheck generators with Avro, Protobuf, and BigQuery. For examples of using Generators see ratatool-examples.

Usage

import com.spotify.ratatool.scalacheck._
import org.scalacheck.Gen


val avroGen: Gen[MyRecord] = avroOf[MyRecord]
val record: MyRecord = avroGen.sample.get

Ratatool also provides protobufOf[T] and tableRowOf(schema) defined here.

It also enables modifying specific fields using .amend(). For Protobuf, the record has to be converted to a Builder first.

val intGen = Gen.choose(0, 10)
avroGen.amend(intGen)(_.setMyIntField)

To use the same value in two records, use amend2() after converting (Gen[A], Gen[B]) to Gen[(A, B)] with tupled().

val otherGen: Gen[OtherRecord] = avroOf[OtherRecord]
val keyGen = Arbitrary.arbString.arbitrary

(avroGen, otherGen).tupled.amend2(keyGen)(_.setMyIntField, _.setOtherIntField)

Implicit Arbitrary instances are also available for Avro and Protobuf records. Explicit functions are provided for GenericRecord and TableRow

val avroArb: Arbitrary[MyRecord] = implicitly[Arbitrary[MyRecord]]
You can’t perform that action at this time.