-
Notifications
You must be signed in to change notification settings - Fork 779
SOLR-17508 Port BATS tests to Powershell (Pester) #3810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
janhoy
wants to merge
20
commits into
apache:main
Choose a base branch
from
janhoy:SOLR-17508-pester-tests-for-windows-cmd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
81d1c00
First attempt at a Pester test for Windows
janhoy 4a25bdf
Fix action
janhoy 1960625
No gradle daemon
janhoy b6998f8
Use gradlew
janhoy 2ece5e6
Use a distinct integrationTestOutput folder for pester
janhoy d895399
Fix OS detection bug
janhoy 5daa0db
Collapse two gradle steps into one, don't use daemon
janhoy ffcc870
Rename a test file
janhoy 30adf7e
Adjust test
janhoy 768c7f6
Port the assert test
janhoy b7bacb0
Use the Help test
janhoy 6645e1a
More verbose logging
janhoy cac5d78
Fix Help test
janhoy c9a18db
Port he ZK tests
janhoy 1dc7cd8
Fix a zk test
janhoy 49ffa3c
Try to fix the help test, with case sensitive "refute" matching
janhoy 64f3449
Use another way to test if solr is running
janhoy a6e4338
Reduce logging to "Normal"
janhoy 00b1b69
Add solr startup for tests that require a solr instance
malliaridis 78d9f17
Fix failing test due to false positive
malliaridis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| name: Powershell Pester Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main, SOLR-17508-* ] | ||
| paths: | ||
| - 'solr/packaging/powershell-tests/**' | ||
| - 'solr/packaging/build.gradle' | ||
| - 'solr/bin/solr.cmd' | ||
| - 'solr/bin/solr.in.cmd' | ||
| pull_request: | ||
| branches: [ main ] | ||
|
|
||
| jobs: | ||
| pester-tests: | ||
| runs-on: windows-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Java | ||
| uses: actions/setup-java@v3 | ||
| with: | ||
| java-version: '21' | ||
| distribution: 'temurin' | ||
|
|
||
| - name: Build Solr distribution | ||
| run: | | ||
| .\gradlew.bat --no-daemon -p solr/packaging installFullDist | ||
| shell: powershell | ||
|
|
||
| - name: Run Pester tests | ||
| run: | | ||
| .\gradlew.bat --no-daemon -p solr/packaging pesterTests | ||
| shell: powershell | ||
|
|
||
| - name: Upload test results | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: pester-test-results | ||
| path: solr/packaging/build/test-output/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| <# | ||
| Pester tests for Solr help command | ||
| Ported from test/test_help.bats | ||
| #> | ||
|
|
||
| BeforeAll { | ||
| # Get the Solr installation directory from environment variable | ||
| $script:SolrTip = $env:SOLR_TIP | ||
|
|
||
| if (-not $SolrTip) { | ||
| throw "SOLR_TIP environment variable is not set" | ||
| } | ||
|
|
||
| # Determine the Solr executable based on OS | ||
| $script:SolrCmd = Join-Path $SolrTip "bin\solr.cmd" | ||
|
|
||
| if (-not (Test-Path $SolrCmd)) { | ||
| throw "Solr executable not found at: $SolrCmd" | ||
| } | ||
|
|
||
| Write-Host "Using Solr installation at: $SolrTip" | ||
| Write-Host "Using Solr command: $SolrCmd" | ||
|
|
||
| function Test-HelpOutput { | ||
| param( | ||
| [string[]]$Arguments, | ||
| [string]$ExpectedPattern, | ||
| [string]$TestName | ||
| ) | ||
|
|
||
| Write-Host "Testing help: $TestName" | ||
| Write-Host "Running: $SolrCmd $($Arguments -join ' ')" | ||
|
|
||
| $output = & $SolrCmd @Arguments 2>&1 | ||
| $outputStr = $output | Out-String | ||
|
|
||
| Write-Host "Exit Code: $LASTEXITCODE" | ||
| if ($outputStr.Length -gt 0) { | ||
| Write-Host "Output (first 500 chars): $($outputStr.Substring(0, [Math]::Min(500, $outputStr.Length)))" | ||
| } else { | ||
| Write-Host "WARNING: Output is empty!" | ||
| } | ||
|
|
||
| return $outputStr | ||
| } | ||
| } | ||
|
|
||
| Describe "Solr Help Command" { | ||
| Context "Main help commands" { | ||
| It "solr --help flag prints help" { | ||
| $output = Test-HelpOutput @("--help") "Usage: solr COMMAND OPTIONS" "solr --help" | ||
| $output | Should -Match "Usage: solr COMMAND OPTIONS" | ||
| $output | Should -Not -cmatch "ERROR" | ||
| } | ||
|
|
||
| It "solr with no flags prints help" { | ||
| $output = Test-HelpOutput @() "Usage: solr COMMAND OPTIONS" "solr (no flags)" | ||
| $output | Should -Match "Usage: solr COMMAND OPTIONS" | ||
| $output | Should -Not -cmatch "ERROR" | ||
| } | ||
| } | ||
|
|
||
| Context "Command-specific help" { | ||
| It "start --help flag prints help" { | ||
| $output = Test-HelpOutput @("start", "--help") "Usage: solr start" "start --help" | ||
| $output | Should -Match "Usage: solr start" | ||
| $output | Should -Not -cmatch "ERROR" | ||
| } | ||
|
|
||
| It "start -h flag prints help" { | ||
| $output = Test-HelpOutput @("start", "-h") "Usage: solr start" "start -h" | ||
| $output | Should -Match "Usage: solr start" | ||
| $output | Should -Not -Match "ERROR: Hostname is required when using the -h option!" | ||
| } | ||
|
|
||
| It "stop --help flag prints help" { | ||
| $output = Test-HelpOutput @("stop", "--help") "Usage: solr stop" "stop --help" | ||
| $output | Should -Match "Usage: solr stop" | ||
| $output | Should -Not -cmatch "ERROR" | ||
| } | ||
|
|
||
| It "restart --help flag prints help" { | ||
| $output = Test-HelpOutput @("restart", "--help") "Usage: solr restart" "restart --help" | ||
| $output | Should -Match "Usage: solr restart" | ||
| $output | Should -Not -cmatch "ERROR" | ||
| } | ||
|
|
||
| It "status --help flag prints help" { | ||
| $output = Test-HelpOutput @("status", "--help") "usage: bin/solr status" "status --help" | ||
| $output | Should -Match "usage: bin/solr status" | ||
| $output | Should -Not -cmatch "ERROR" | ||
| } | ||
|
|
||
| It "healthcheck --help flag prints help" { | ||
| $output = Test-HelpOutput @("healthcheck", "--help") "usage: bin/solr healthcheck" "healthcheck --help" | ||
| $output | Should -Match "usage: bin/solr healthcheck" | ||
| $output | Should -Not -cmatch "ERROR" | ||
| } | ||
|
|
||
| It "create --help flag prints help" { | ||
| $output = Test-HelpOutput @("create", "--help") "usage: bin/solr create" "create --help" | ||
| $output | Should -Match "usage: bin/solr create" | ||
| $output | Should -Not -cmatch "ERROR" | ||
| } | ||
|
|
||
| It "delete -h flag prints help" { | ||
| $output = Test-HelpOutput @("delete", "-h") "usage: bin/solr delete" "delete -h" | ||
| $output | Should -Match "usage: bin/solr delete" | ||
| $output | Should -Not -cmatch "ERROR" | ||
| } | ||
|
|
||
| It "zk --help flag prints help" { | ||
| $output = Test-HelpOutput @("zk", "--help") "usage:" "zk --help" | ||
| $output | Should -Match "usage:" | ||
| $output | Should -Match "bin/solr zk ls" | ||
| $output | Should -Not -cmatch "ERROR" | ||
| } | ||
|
|
||
| It "auth --help flag prints help" { | ||
| $output = Test-HelpOutput @("auth", "--help") "bin/solr auth enable" "auth --help" | ||
| $output | Should -Match "bin/solr auth enable" | ||
| $output | Should -Not -cmatch "ERROR" | ||
| } | ||
|
|
||
| It "assert --help flag prints help" { | ||
| $output = Test-HelpOutput @("assert", "--help") "usage: bin/solr assert" "assert --help" | ||
| $output | Should -Match "usage: bin/solr assert" | ||
| $output | Should -Not -cmatch "ERROR" | ||
| } | ||
|
|
||
| It "post --help flag prints help" { | ||
| $output = Test-HelpOutput @("post", "--help") "usage: bin/solr post" "post --help" | ||
| $output | Should -Match "usage: bin/solr post" | ||
| $output | Should -Not -cmatch "ERROR" | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| <# | ||
| Pester tests for Solr version command | ||
| Ported from test/test_version.bats | ||
| #> | ||
|
|
||
| BeforeAll { | ||
| # Get the Solr installation directory from environment variable | ||
| $script:SolrTip = $env:SOLR_TIP | ||
| if (-not $SolrTip) { | ||
| throw "SOLR_TIP environment variable is not set" | ||
| } | ||
|
|
||
| # Determine the Solr executable based on OS | ||
| $script:SolrCmd = Join-Path $SolrTip "bin\solr.cmd" | ||
|
|
||
| if (-not (Test-Path $SolrCmd)) { | ||
| throw "Solr executable not found at: $SolrCmd" | ||
| } | ||
|
|
||
| Write-Host "Using Solr installation at: $SolrTip" | ||
| Write-Host "Using Solr command: $SolrCmd" | ||
| } | ||
|
|
||
| Describe "Solr Version Command" { | ||
| Context "When using --version flag" { | ||
| It "--version returns Solr version" { | ||
| $output = & $SolrCmd --version 2>&1 | ||
| $output | Out-String | Should -Match "Solr version is:" | ||
| } | ||
| } | ||
|
|
||
| Context "When using version as direct command" { | ||
| It "version as direct tool call still runs" { | ||
| $output = & $SolrCmd version 2>&1 | ||
| $output | Out-String | Should -Match "Solr version is:" | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This output (and a similar one in
Zk.Tests.ps1) adds some verbosity tot he console during execution which I would prefer to enable manually if needed. Perhaps we could use the pester verbosity here and do something like:This would also require an update in the gradle task to allow changing the verbosity via
-Dpester.verbosity. Something likeand in the pester config