|
| 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 assert command |
| 19 | + Ported from test/test_assert.bats |
| 20 | +#> |
| 21 | + |
| 22 | +BeforeAll { |
| 23 | + # Get the Solr installation directory from environment variable |
| 24 | + $script:SolrTip = $env:SOLR_TIP |
| 25 | + $script:SolrPort = $env:SOLR_PORT |
| 26 | + $script:SolrHome = $env:SOLR_HOME |
| 27 | + $script:TestFailureDir = $env:TEST_FAILURE_DIR |
| 28 | + |
| 29 | + if (-not $SolrTip) { |
| 30 | + throw "SOLR_TIP environment variable is not set" |
| 31 | + } |
| 32 | + |
| 33 | + if (-not $SolrPort) { |
| 34 | + throw "SOLR_PORT environment variable is not set" |
| 35 | + } |
| 36 | + |
| 37 | + # Determine the Solr executable based on OS |
| 38 | + $script:SolrCmd = Join-Path $SolrTip "bin\solr.cmd" |
| 39 | + |
| 40 | + if (-not (Test-Path $SolrCmd)) { |
| 41 | + throw "Solr executable not found at: $SolrCmd" |
| 42 | + } |
| 43 | + |
| 44 | + Write-Host "Using Solr installation at: $SolrTip" |
| 45 | + Write-Host "Using Solr port: $SolrPort" |
| 46 | + Write-Host "Using Solr home: $SolrHome" |
| 47 | +} |
| 48 | + |
| 49 | +AfterEach { |
| 50 | + # Stop all Solr instances after each test |
| 51 | + & $SolrCmd stop --all 2>&1 | Out-Null |
| 52 | + Start-Sleep -Seconds 2 |
| 53 | +} |
| 54 | + |
| 55 | +Describe "Solr Assert Command" { |
| 56 | + Context "Assert for non-cloud mode" { |
| 57 | + It "assert --not-started before starting Solr" { |
| 58 | + $output = & $SolrCmd assert --not-started "http://localhost:$SolrPort" --timeout 5000 2>&1 |
| 59 | + $output | Out-String | Should -Match "Solr is not running" |
| 60 | + } |
| 61 | + |
| 62 | + It "assert --started after starting Solr" { |
| 63 | + # Start Solr in user-managed mode (non-cloud) |
| 64 | + & $SolrCmd start --user-managed 2>&1 | Out-Null |
| 65 | + Start-Sleep -Seconds 5 |
| 66 | + |
| 67 | + $output = & $SolrCmd assert --started "http://localhost:$SolrPort" --timeout 5000 2>&1 |
| 68 | + $output | Out-String | Should -Match "Solr is running" |
| 69 | + } |
| 70 | + |
| 71 | + It "assert --not-cloud on standalone Solr instance" { |
| 72 | + # Start Solr in user-managed mode (non-cloud) |
| 73 | + & $SolrCmd start --user-managed 2>&1 | Out-Null |
| 74 | + Start-Sleep -Seconds 5 |
| 75 | + |
| 76 | + $output = & $SolrCmd assert --not-cloud "http://localhost:$SolrPort/solr" 2>&1 |
| 77 | + $output | Out-String | Should -Match "needn't include Solr's context-root" |
| 78 | + $output | Out-String | Should -Not -Match "ERROR" |
| 79 | + } |
| 80 | + |
| 81 | + It "assert --cloud fails on standalone Solr instance" { |
| 82 | + # Start Solr in user-managed mode (non-cloud) |
| 83 | + & $SolrCmd start --user-managed 2>&1 | Out-Null |
| 84 | + Start-Sleep -Seconds 5 |
| 85 | + |
| 86 | + $output = & $SolrCmd assert --cloud "http://localhost:$SolrPort" 2>&1 |
| 87 | + $LASTEXITCODE | Should -Not -Be 0 |
| 88 | + $output | Out-String | Should -Match "ERROR: Solr is not running in cloud mode" |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + Context "Assert for cloud mode" { |
| 93 | + It "assert --cloud on cloud Solr instance" { |
| 94 | + # Start Solr in cloud mode (default) |
| 95 | + & $SolrCmd start 2>&1 | Out-Null |
| 96 | + Start-Sleep -Seconds 5 |
| 97 | + |
| 98 | + $output = & $SolrCmd assert --started "http://localhost:$SolrPort" --timeout 5000 2>&1 |
| 99 | + $output | Out-String | Should -Match "Solr is running" |
| 100 | + |
| 101 | + $output = & $SolrCmd assert --cloud "http://localhost:$SolrPort" 2>&1 |
| 102 | + $output | Out-String | Should -Not -Match "ERROR" |
| 103 | + } |
| 104 | + |
| 105 | + It "assert --not-cloud fails on cloud Solr instance" { |
| 106 | + # Start Solr in cloud mode (default) |
| 107 | + & $SolrCmd start 2>&1 | Out-Null |
| 108 | + Start-Sleep -Seconds 5 |
| 109 | + |
| 110 | + $output = & $SolrCmd assert --not-cloud "http://localhost:$SolrPort/solr" 2>&1 |
| 111 | + $LASTEXITCODE | Should -Not -Be 0 |
| 112 | + $output | Out-String | Should -Match "needn't include Solr's context-root" |
| 113 | + $output | Out-String | Should -Match "ERROR: Solr is not running in standalone mode" |
| 114 | + } |
| 115 | + } |
| 116 | +} |
0 commit comments