added flux testing package
parent
d5e50b1dcf
commit
54bcfcfa60
|
@ -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" >}}
|
|
@ -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()
|
||||
```
|
|
@ -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)
|
||||
```
|
|
@ -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)
|
||||
```
|
Loading…
Reference in New Issue