Skip to content

Files

This branch is 435 commits behind spotify/ratatool:master.

ratatool-scalacheck

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Apr 30, 2019
Apr 30, 2019

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]]