Skip to content

Commit

Permalink
fixing flaky filter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reubenmiller committed Apr 15, 2021
1 parent b376c4d commit 5fd661d
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions tools/PSc8y/Tests/c8y/filter.manual.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,50 @@
Describe -Name "c8y filter common parameter" {
BeforeAll {
$TypeSuffix = New-RandomString
$Template = "{ name: 'testFilter', type: 'c8yci_$TypeSuffix', ci_filterTest: {} }"
$UniqueFragment = New-RandomString -Prefix "c8y_citest"
$Template = "{ name: 'testFilter', type: 'c8yci_$TypeSuffix', ${UniqueFragment}: {} }"
$ids = New-Object System.Collections.ArrayList
$Device1 = New-Device -Template $Template
$Device2 = New-Device -Template $Template
$null = $ids.AddRange(@($Device1.id, $Device2.id))
}

It "filters by wildcards" {
$output = c8y devices list --fragmentType "ci_filterTest" --filter "type like *$TypeSuffix*" --orderBy "_id asc" | ConvertFrom-Json
$output = c8y devices list --fragmentType $UniqueFragment --filter "type like *$TypeSuffix*" --orderBy "_id asc" | ConvertFrom-Json
$LASTEXITCODE | Should -Be 0
$output | Should -ContainInCollection $Device1, $Device2

$output = c8y devices list --fragmentType "ci_filterTest" --filter "type -like *$TypeSuffix*" --orderBy "_id asc" | ConvertFrom-Json
$output = c8y devices list --fragmentType $UniqueFragment --filter "type -like *$TypeSuffix*" --orderBy "_id asc" | ConvertFrom-Json
$LASTEXITCODE | Should -Be 0
$output | Should -ContainInCollection $Device1, $Device2
}

It "filters by negated wildcards" {
$output = c8y devices list --fragmentType "ci_filterTest" --filter "id notlike $($Device1.id)*" --orderBy "_id asc" | ConvertFrom-Json
$output = c8y devices list --fragmentType $UniqueFragment --filter "id notlike $($Device1.id)*" --orderBy "_id asc" | ConvertFrom-Json
$LASTEXITCODE | Should -Be 0
$output | Should -ContainInCollection $Device2

$output = c8y devices list --fragmentType "ci_filterTest" --filter "id -notlike $($Device1.id)*" --orderBy "_id asc" | ConvertFrom-Json
$output = c8y devices list --fragmentType $UniqueFragment --filter "id -notlike $($Device1.id)*" --orderBy "_id asc" | ConvertFrom-Json
$LASTEXITCODE | Should -Be 0
$output | Should -ContainInCollection $Device2
}

It "filters by regex" {
$output = c8y devices list --fragmentType "ci_filterTest" --filter "type match c8yci_.+[a-z0-9]*" --orderBy "_id asc" | ConvertFrom-Json
$output = c8y devices list --fragmentType $UniqueFragment --filter "type match c8yci_.+[a-z0-9]*" --orderBy "_id asc" | ConvertFrom-Json
$LASTEXITCODE | Should -Be 0
$output | Should -ContainInCollection $Device1, $Device2

$output = c8y devices list --fragmentType "ci_filterTest" --filter "type -match c8yci_.+[a-z0-9]*" --orderBy "_id asc" | ConvertFrom-Json
$output = c8y devices list --fragmentType $UniqueFragment --filter "type -match c8yci_.+[a-z0-9]*" --orderBy "_id asc" | ConvertFrom-Json
$LASTEXITCODE | Should -Be 0
$output | Should -ContainInCollection $Device1, $Device2
}

It "filters by negated regex" {
$output = c8y devices list --fragmentType "ci_filterTest" --filter "id notmatch $($Device1.id)?" --orderBy "_id asc" | ConvertFrom-Json
$output = c8y devices list --fragmentType $UniqueFragment --filter "id notmatch $($Device1.id)x?" --orderBy "_id asc" | ConvertFrom-Json
$LASTEXITCODE | Should -Be 0
$output | Should -ContainInCollection $Device2

$output = c8y devices list --fragmentType "ci_filterTest" --filter "id -notmatch $($Device1.id)?" --orderBy "_id asc" | ConvertFrom-Json
$output = c8y devices list --fragmentType $UniqueFragment --filter "id -notmatch $($Device1.id)x?" --orderBy "_id asc" | ConvertFrom-Json
$LASTEXITCODE | Should -Be 0
$output | Should -ContainInCollection $Device2
}
Expand Down

0 comments on commit 5fd661d

Please sign in to comment.