testing.diff() function

The testing.diff() function produces a diff between two streams.

*Function type: Test*

  1. import "testing"
  2. testing.diff(
  3. got: stream2,
  4. want: stream1,
  5. epsilon: 0.000000001
  6. )

It matches tables from each stream with the same group keys. For each matched table, it produces a diff. Any added or removed rows are added to the table as a row. An additional string column with the name diff is created and contains a - if the row was present in the got table and not in the want table or + if the opposite is true.

The diff function is guaranteed to emit at least one row if the tables are different and no rows if the tables are the same. The exact diff produced may change.

The testing.diff() function can be used to perform in-line diffs in a query.

Parameters

got

Stream containing data to test. Defaults to piped-forward data (<-).

*Data type: Record*

want

Stream that contains the expected data to test against.

*Data type: Record*

epsilon

Specifies how far apart two float values can be, but still considered equal. Defaults to 0.000000001.

*Data type: Float*

Examples

Diff separate streams
  1. import "testing"
  2. want = from(bucket: "backup-example-bucket")
  3. |> range(start: -5m)
  4. got = from(bucket: "example-bucket")
  5. |> range(start: -5m)
  6. testing.diff(got: got, want: want)
Inline diff
  1. import "testing"
  2. want = from(bucket: "backup-example-bucket") |> range(start: -5m)
  3. from(bucket: "example-bucket")
  4. |> range(start: -5m)
  5. |> testing.diff(want: want)