Skip to content

Commit 81d1c00

Browse files
committed
First attempt at a Pester test for Windows
1 parent b8ae627 commit 81d1c00

File tree

3 files changed

+157
-0
lines changed

3 files changed

+157
-0
lines changed

.github/workflows/pester-tests.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Powershell Pester Tests
2+
3+
on:
4+
push:
5+
branches: [ main, SOLR-17508-* ]
6+
paths:
7+
- 'solr/packaging/powershell-tests/**'
8+
- 'solr/packaging/build.gradle'
9+
- 'solr/bin/solr.cmd'
10+
- 'solr/bin/solr.in.cmd'
11+
pull_request:
12+
branches: [ main ]
13+
14+
jobs:
15+
pester-tests:
16+
runs-on: windows-latest
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Set up Java
22+
uses: actions/setup-java@v3
23+
with:
24+
java-version: '21'
25+
distribution: 'temurin'
26+
27+
- name: Build Solr distribution
28+
run: |
29+
cd solr/packaging
30+
gradle installFullDist
31+
shell: powershell
32+
33+
- name: Run Pester tests
34+
run: |
35+
cd solr/packaging
36+
gradle pesterTests
37+
shell: powershell
38+
39+
- name: Upload test results
40+
if: always()
41+
uses: actions/upload-artifact@v3
42+
with:
43+
name: pester-test-results
44+
path: solr/packaging/build/test-output/

solr/packaging/build.gradle

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,65 @@ task integrationTests(type: BatsTask) {
273273
environment BATS_LIB_PREFIX: "$nodeProjectDir/node_modules"
274274
}
275275

276+
task pesterTests {
277+
dependsOn installFullDist
278+
onlyIf { Os.isFamily(Os.FAMILY_WINDOWS) }
279+
280+
def integrationTestOutput = "$buildDir/test-output"
281+
def solrHome = "$integrationTestOutput/solr-home"
282+
def solrTestFailuresDir = "$integrationTestOutput/failure-snapshots"
283+
var solrPort = Integer.parseInt((String) project.findProperty('pester.port') ?: System.getProperty("pester.port", "-1"))
284+
while (solrPort > 64000 || solrPort < 0) { // We need room for +1000 for ZK
285+
try (ServerSocket s = new ServerSocket(0)) {
286+
solrPort = s.getLocalPort()
287+
} catch (Exception e) {
288+
println("WARN: Could not assign random port for Pester tests. Using default port 8983.")
289+
solrPort = 8983
290+
}
291+
}
292+
293+
inputs.dir(distDir)
294+
outputs.dir(integrationTestOutput)
295+
296+
doFirst {
297+
delete integrationTestOutput
298+
mkdir integrationTestOutput
299+
mkdir solrHome
300+
mkdir solrTestFailuresDir
301+
302+
println("Running Pester tests with Solr base port ${solrPort}")
303+
}
304+
305+
doLast {
306+
exec {
307+
executable "powershell"
308+
args = [
309+
"-Command",
310+
"& { " +
311+
"Import-Module Pester -MinimumVersion 5.0; " +
312+
"\$config = New-PesterConfiguration; " +
313+
"\$config.Run.Path = 'powershell-tests'; " +
314+
"\$config.Run.Exit = \$true; " +
315+
"\$config.TestResult.OutputPath = '${integrationTestOutput}/test-results.xml'; " +
316+
"\$env:SOLR_TIP = '${distDir}'; " +
317+
"\$env:SOLR_HOME = '${solrHome}'; " +
318+
"\$env:SOLR_PID_DIR = '${solrHome}'; " +
319+
"\$env:SOLR_PORT = ${solrPort}; " +
320+
"\$env:SOLR2_PORT = ${solrPort + 1}; " +
321+
"\$env:SOLR3_PORT = ${solrPort + 2}; " +
322+
"\$env:ZK_PORT = ${solrPort + 1000}; " +
323+
"\$env:SOLR_LOGS_DIR = '${solrHome}/logs'; " +
324+
"\$env:TEST_OUTPUT_DIR = '${integrationTestOutput}'; " +
325+
"\$env:TEST_FAILURE_DIR = '${solrTestFailuresDir}'; " +
326+
"Invoke-Pester -Configuration \$config; " +
327+
"}"
328+
]
329+
330+
workingDir projectDir.toString()
331+
}
332+
}
333+
}
334+
276335
class BatsTask extends Exec {
277336
@InputDirectory
278337
String testDir = 'test'
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
<#
18+
Pester tests for Solr version command
19+
Ported from test/test_version.bats
20+
#>
21+
22+
BeforeAll {
23+
# Get the Solr installation directory from environment variable
24+
$script:SolrTip = $env:SOLR_TIP
25+
if (-not $SolrTip) {
26+
throw "SOLR_TIP environment variable is not set"
27+
}
28+
29+
# Determine the Solr executable based on OS
30+
$script:SolrCmd = Join-Path $SolrTip "bin\solr.cmd"
31+
32+
if (-not (Test-Path $SolrCmd)) {
33+
throw "Solr executable not found at: $SolrCmd"
34+
}
35+
36+
Write-Host "Using Solr installation at: $SolrTip"
37+
Write-Host "Using Solr command: $SolrCmd"
38+
}
39+
40+
Describe "Solr Version Command" {
41+
Context "When using --version flag" {
42+
It "--version returns Solr version" {
43+
$output = & $SolrCmd --version 2>&1
44+
$output | Should -Contain "Solr version is:"
45+
}
46+
}
47+
48+
Context "When using version as direct command" {
49+
It "version as direct tool call still runs" {
50+
$output = & $SolrCmd version 2>&1
51+
$output | Should -Contain "Solr version is:"
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)