malliaridis commented on code in PR #3810: URL: https://github.com/apache/solr/pull/3810#discussion_r2470043111
########## solr/packaging/powershell-tests/Help.Tests.ps1: ########## @@ -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)))" Review Comment: 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: ```powershell if ($PesterPreference.Show -contains 'Detailed') { # gradle script sets verbosity to Normal # ... } ``` This would also require an update in the gradle task to allow changing the verbosity via `-Dpester.verbosity`. Something like ```groovy def pesterVerbosity = (project.findProperty("pester.verbosity") ?: System.getProperty("pester.verbosity", "Normal")) ``` and in the pester config ``` // ... "\$config.Output.Verbosity = '${pesterVerbosity}'; " + // ... ``` ########## solr/packaging/powershell-tests/Zk.Tests.ps1: ########## @@ -0,0 +1,208 @@ +# +# 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 zk command + Ported from test/test_zk.bats +#> + +BeforeAll { + # Get the Solr installation directory from environment variable + $script:SolrTip = $env:SOLR_TIP + + # Note: $SolrTip cannot be used directly in -Skip statements in tests, use $env:SOLR_TIP instead + 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" + + # Get ZooKeeper port from environment or default + $script:ZK_PORT = if ($env:ZK_PORT) { $env:ZK_PORT } else { "9983" } + $script:SOLR_PORT = if ($env:SOLR_PORT) { $env:SOLR_PORT } else { "8983" } + + function Test-CommandOutput { + param( + [string[]]$Arguments, + [string]$TestName + ) + + Write-Host "Testing: $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 Zk Command" { + Context "Help commands" { + It "short help" { + $output = Test-CommandOutput @("zk", "ls", "-h") "zk ls -h" + $output | Should -Match "usage: bin/solr zk" + } + + It "short help is inferred" { + $output = Test-CommandOutput @("zk", "ls") "zk ls" + $output | Should -Match "usage: bin/solr zk" + } + + It "long help" { + $output = Test-CommandOutput @("zk", "-h") "zk -h" + $output | Should -Match "bin/solr zk ls" + $output | Should -Match "bin/solr zk updateacls" + $output | Should -Match "Pass --help or -h after any COMMAND" + } + + It "running subcommands with zk is prevented" { + $output = Test-CommandOutput @("ls", "/", "-z", "localhost:$ZK_PORT") "ls / -z localhost:$ZK_PORT" + $output | Should -Match "You must invoke this subcommand using the zk command" + } + } + + Context "Zk operations (requires running Solr with ZooKeeper)" -Skip:(-not (Test-Path (Join-Path $env:SOLR_TIP "server\solr"))) { + BeforeAll { + # Check if Solr is running by trying to connect to the port + $solrRunning = $false + try { + $response = Invoke-WebRequest -Uri "http://localhost:$SOLR_PORT/solr/" -UseBasicParsing -ErrorAction SilentlyContinue + if ($response.StatusCode -eq 200) { + $solrRunning = $true + } + } catch { + $solrRunning = $false + } + + $script:SolrRunning = $solrRunning + if (-not $solrRunning) { + Write-Host "WARNING: Solr does not appear to be running on port $SOLR_PORT" + } + } + + It "listing out files" { + if (-not $script:SolrRunning) { Set-ItResult -Skipped -Because "Solr is not running"; return } Review Comment: Could this line be configured in a `BeforeEach` block and reduce duplication maybe? ########## solr/packaging/powershell-tests/Zk.Tests.ps1: ########## @@ -0,0 +1,208 @@ +# +# 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 zk command + Ported from test/test_zk.bats +#> + +BeforeAll { + # Get the Solr installation directory from environment variable + $script:SolrTip = $env:SOLR_TIP + + # Note: $SolrTip cannot be used directly in -Skip statements in tests, use $env:SOLR_TIP instead + 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" + + # Get ZooKeeper port from environment or default + $script:ZK_PORT = if ($env:ZK_PORT) { $env:ZK_PORT } else { "9983" } + $script:SOLR_PORT = if ($env:SOLR_PORT) { $env:SOLR_PORT } else { "8983" } + + function Test-CommandOutput { + param( + [string[]]$Arguments, + [string]$TestName + ) + + Write-Host "Testing: $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 Zk Command" { + Context "Help commands" { + It "short help" { + $output = Test-CommandOutput @("zk", "ls", "-h") "zk ls -h" + $output | Should -Match "usage: bin/solr zk" + } + + It "short help is inferred" { + $output = Test-CommandOutput @("zk", "ls") "zk ls" + $output | Should -Match "usage: bin/solr zk" + } + + It "long help" { + $output = Test-CommandOutput @("zk", "-h") "zk -h" + $output | Should -Match "bin/solr zk ls" + $output | Should -Match "bin/solr zk updateacls" + $output | Should -Match "Pass --help or -h after any COMMAND" + } + + It "running subcommands with zk is prevented" { + $output = Test-CommandOutput @("ls", "/", "-z", "localhost:$ZK_PORT") "ls / -z localhost:$ZK_PORT" + $output | Should -Match "You must invoke this subcommand using the zk command" + } + } + + Context "Zk operations (requires running Solr with ZooKeeper)" -Skip:(-not (Test-Path (Join-Path $env:SOLR_TIP "server\solr"))) { + BeforeAll { + # Check if Solr is running by trying to connect to the port + $solrRunning = $false + try { + $response = Invoke-WebRequest -Uri "http://localhost:$SOLR_PORT/solr/" -UseBasicParsing -ErrorAction SilentlyContinue + if ($response.StatusCode -eq 200) { + $solrRunning = $true + } + } catch { Review Comment: This block always fails, leading to the 9 tests being skipped. Is Solr ever started during the test? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
