From 54bcfcfa60e30b9aa34bcc199d45be8701985560 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Thu, 7 Feb 2019 19:33:41 -0700 Subject: [PATCH 1/2] added flux testing package --- .../flux/functions/testing/_index.md | 19 ++++++ .../flux/functions/testing/assertempty.md | 41 ++++++++++++ .../tests => testing}/assertequals.md | 36 +++++----- .../reference/flux/functions/testing/diff.md | 66 +++++++++++++++++++ 4 files changed, 146 insertions(+), 16 deletions(-) create mode 100644 content/v2.0/reference/flux/functions/testing/_index.md create mode 100644 content/v2.0/reference/flux/functions/testing/assertempty.md rename content/v2.0/reference/flux/functions/{built-in/tests => testing}/assertequals.md (58%) create mode 100644 content/v2.0/reference/flux/functions/testing/diff.md diff --git a/content/v2.0/reference/flux/functions/testing/_index.md b/content/v2.0/reference/flux/functions/testing/_index.md new file mode 100644 index 000000000..0aef85a7e --- /dev/null +++ b/content/v2.0/reference/flux/functions/testing/_index.md @@ -0,0 +1,19 @@ +--- +title: Flux Testing functions +description: > + Flux testing functions test piped-forward data in specific ways and return errors if the tests fail. +menu: + v2_0_ref: + name: Testing + parent: Flux functions +weight: 204 +--- + +Flux testing functions test piped-forward data in specific ways and return errors if the tests fail. +To use them, import the `testing` package: + +```js +import "testing" +``` + +{{< children type="functions" show="pages" >}} diff --git a/content/v2.0/reference/flux/functions/testing/assertempty.md b/content/v2.0/reference/flux/functions/testing/assertempty.md new file mode 100644 index 000000000..d4d646c09 --- /dev/null +++ b/content/v2.0/reference/flux/functions/testing/assertempty.md @@ -0,0 +1,41 @@ +--- +title: testing.assertEmpty() function +description: The testing.assertEmpty() function tests if an input stream is empty. +menu: + v2_0_ref: + name: testing.assertEmpty + parent: Testing + weight: 301 +--- + +The `testing.assertEmpty()` function tests if an input stream is empty. +If not empty, the function outputs an error. + +_**Function type:** Test_ + +```js +import "testing" + +testing.assertEmpty() +``` + +_The `testing.assertEmpty()` function can be used to perform in-line tests in a query._ + +## Examples + +#### Check if there is a difference between streams +This example uses the [`diff()` function](/flux/v0.x/functions/tests/diff) +which outputs the diff for the two streams. +The `.testing.assertEmpty()` function checks to see if the diff is empty. + +```js +import "testing" + +got = from(bucket: "telegraf/autogen") + |> range(start: -15m) +want = from(bucket: "backup_telegraf/autogen") + |> range(start: -15m) +got + |> diff(want: want) + |> testing.assertEmpty() +``` diff --git a/content/v2.0/reference/flux/functions/built-in/tests/assertequals.md b/content/v2.0/reference/flux/functions/testing/assertequals.md similarity index 58% rename from content/v2.0/reference/flux/functions/built-in/tests/assertequals.md rename to content/v2.0/reference/flux/functions/testing/assertequals.md index 6c41ac9ef..cb9cfbd64 100644 --- a/content/v2.0/reference/flux/functions/built-in/tests/assertequals.md +++ b/content/v2.0/reference/flux/functions/testing/assertequals.md @@ -1,45 +1,45 @@ --- -title: assertEquals() function -description: The assertEquals() function tests whether two streams have identical data. +title: testing.assertEquals() function +description: The testing.assertEquals() function tests whether two streams have identical data. aliases: - /v2.0/reference/flux/functions/tests/assertequals menu: v2_0_ref: - name: assertEquals - parent: built-in-tests -weight: 401 + name: testing.assertEquals + parent: Testing +weight: 301 --- -The `assertEquals()` function tests whether two streams have identical data. +The `testing.assertEquals()` function tests whether two streams have identical data. If equal, the function outputs the tested data stream unchanged. If unequal, the function outputs an error. -_**Function type:** Test_ - ```js -assertEquals( +import "testing" + +testing.assertEquals( name: "streamEquality", got: got, want: want ) ``` -_The `assertEquals()` function can be used to perform in-line tests in a query._ +_The `testing.assertEquals()` function can be used to perform in-line tests in a query._ ## Parameters -## name +### name Unique name given to the assertion. _**Data type:** String_ -## got +### got The stream containing data to test. -Defaults to data piped-forward from another function (`<-`). +Defaults to piped-forward data (`<-`). _**Data type:** Object_ -## want +### want The stream that contains the expected data to test against. _**Data type:** Object_ @@ -49,21 +49,25 @@ _**Data type:** Object_ ##### Assert of separate streams ```js +import "testing" + want = from(bucket: "backup-telegraf/autogen") |> range(start: -5m) got = from(bucket: "telegraf/autogen") |> range(start: -5m) -assertEquals(got: got, want: want) +testing.assertEquals(got: got, want: want) ``` ##### Inline assertion ```js +import "testing" + want = from(bucket: "backup-telegraf/autogen") |> range(start: -5m) from(bucket: "telegraf/autogen") |> range(start: -5m) - |> assertEquals(want: want) + |> testing.assertEquals(want: want) ``` diff --git a/content/v2.0/reference/flux/functions/testing/diff.md b/content/v2.0/reference/flux/functions/testing/diff.md new file mode 100644 index 000000000..420165c88 --- /dev/null +++ b/content/v2.0/reference/flux/functions/testing/diff.md @@ -0,0 +1,66 @@ +--- +title: testing.diff() function +description: The testing.diff() function produces a diff between two streams. +menu: + v2_0_ref: + name: testing.diff + parent: Testing + weight: 301 +--- + +The `testing.diff()` function produces a diff between two streams. + +_**Function type:** Test_ + +```js +import "testing" + +testing.diff(got: stream2, want: stream1) +``` + +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 +The stream containing data to test. +_Defaults to piped-forward data (`<-`)._ + +_**Data type:** Object_ + +### want +The stream that contains the expected data to test against. + +_**Data type:** Object_ + +## Examples + +##### Diff separate streams +```js +import "testing" + +want = from(bucket: "backup-telegraf/autogen") + |> range(start: -5m) +got = from(bucket: "telegraf/autogen") + |> range(start: -5m) +testing.diff(got: got, want: want) +``` + +##### Inline diff +```js +import "testing" + +want = from(bucket: "backup-telegraf/autogen") |> range(start: -5m) +from(bucket: "telegraf/autogen") + |> range(start: -5m) + |> testing.diff(want: want) +``` From f2b889f659beb28df5c3409fb4232002cccc6872 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Thu, 7 Feb 2019 19:35:11 -0700 Subject: [PATCH 2/2] removed old testing functions --- .../flux/functions/built-in/tests/_index.md | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 content/v2.0/reference/flux/functions/built-in/tests/_index.md diff --git a/content/v2.0/reference/flux/functions/built-in/tests/_index.md b/content/v2.0/reference/flux/functions/built-in/tests/_index.md deleted file mode 100644 index 9fe1d7e4f..000000000 --- a/content/v2.0/reference/flux/functions/built-in/tests/_index.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: Flux testing functions -description: Flux testing functions test piped-forward data in specific ways and return errors if the tests fail. -aliases: - - /v2.0/reference/flux/functions/tests -menu: - v2_0_ref: - name: Tests - parent: Built-in - identifier: built-in-tests -weight: 305 ---- - -Flux testing functions test piped-forward data in specific ways and return errors if the tests fail. -The following testing functions are available: - -{{< children type="functions" >}}