Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/pester-tests.yml
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/
62 changes: 62 additions & 0 deletions solr/packaging/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

import org.apache.tools.ant.util.TeeOutputStream
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform

// This project puts together a "distribution", assembling dependencies from
// various other projects.
Expand Down Expand Up @@ -273,6 +274,67 @@ task integrationTests(type: BatsTask) {
environment BATS_LIB_PREFIX: "$nodeProjectDir/node_modules"
}

task pesterTests {
dependsOn installFullDist
onlyIf { DefaultNativePlatform.getCurrentOperatingSystem().isWindows() }

def integrationTestOutput = "$buildDir/powershell-test-output"
def solrHome = "$integrationTestOutput/solr-home"
def solrTestFailuresDir = "$integrationTestOutput/failure-snapshots"
var solrPort = Integer.parseInt((String) project.findProperty('pester.port') ?: System.getProperty("pester.port", "-1"))
while (solrPort > 64000 || solrPort < 0) { // We need room for +1000 for ZK
try (ServerSocket s = new ServerSocket(0)) {
solrPort = s.getLocalPort()
} catch (Exception e) {
println("WARN: Could not assign random port for Pester tests. Using default port 8983.")
solrPort = 8983
}
}

inputs.dir(distDir)
outputs.dir(integrationTestOutput)

doFirst {
delete integrationTestOutput
mkdir integrationTestOutput
mkdir solrHome
mkdir solrTestFailuresDir

println("Running Pester tests with Solr base port ${solrPort}")
}

doLast {
exec {
executable "powershell"
args = [
"-Command",
"& { " +
"Import-Module Pester -MinimumVersion 5.0; " +
"\$config = New-PesterConfiguration; " +
"\$config.Run.Path = 'powershell-tests'; " +
"\$config.Run.Exit = \$true; " +
"\$config.Output.Verbosity = 'Normal'; " +
"\$config.TestResult.OutputFormat = 'NUnitXml'; " +
"\$config.TestResult.OutputPath = '${integrationTestOutput}/test-results.xml'; " +
"\$env:SOLR_TIP = '${distDir}'; " +
"\$env:SOLR_HOME = '${solrHome}'; " +
"\$env:SOLR_PID_DIR = '${solrHome}'; " +
"\$env:SOLR_PORT = ${solrPort}; " +
"\$env:SOLR2_PORT = ${solrPort + 1}; " +
"\$env:SOLR3_PORT = ${solrPort + 2}; " +
"\$env:ZK_PORT = ${solrPort + 1000}; " +
"\$env:SOLR_LOGS_DIR = '${solrHome}/logs'; " +
"\$env:TEST_OUTPUT_DIR = '${integrationTestOutput}'; " +
"\$env:TEST_FAILURE_DIR = '${solrTestFailuresDir}'; " +
"Invoke-Pester -Configuration \$config; " +
"}"
]

workingDir projectDir.toString()
}
}
}

class BatsTask extends Exec {
@InputDirectory
String testDir = 'test'
Expand Down
153 changes: 153 additions & 0 deletions solr/packaging/powershell-tests/Help.Tests.ps1
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)))"
Copy link
Contributor

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:

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

def pesterVerbosity = (project.findProperty("pester.verbosity")
  ?: System.getProperty("pester.verbosity", "Normal"))

and in the pester config

// ...
"\$config.Output.Verbosity = '${pesterVerbosity}'; " +
// ...

} 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"
}
}
}
54 changes: 54 additions & 0 deletions solr/packaging/powershell-tests/Version.Tests.ps1
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:"
}
}
}
Loading
Loading