Skip to content

Commit

Permalink
Merge pull request #31 from ConSol-Monitoring/add_pester_integration_…
Browse files Browse the repository at this point in the history
…test

Add pester integration test
  • Loading branch information
sni authored Jul 21, 2023
2 parents 1e18765 + 7bd7d85 commit 7a76e61
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 45 deletions.
53 changes: 53 additions & 0 deletions .github/tests/windows/00-basic.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
$global:msiFilePath = "snclient.msi"
$global:snclient = "C:\Program Files\snclient\snclient.exe"

Describe "MSI Installation Test" {
Context "Install snclient.msi" {
It "Should install the .msi successfully" {
Start-Process msiexec -ArgumentList "/i $msiFilePath /qn" -Wait
}

It "Wait until the snclient.exe appears" {
$maxWaitTimeSeconds = 30
$elapsedTime = 0

while (-Not (Test-Path $snclient)) {
if ($elapsedTime -ge $maxWaitTimeSeconds) {
throw "$snclient did not appear within $maxWaitTimeSeconds seconds."
}

Start-Sleep -Seconds 1
$elapsedTime += 1
}
}
}

Context "check_time" {
It "Should run the application after installation" {
$res = Invoke-Expression -Command "&'$snclient' run check_uptime crit=uptime<2s warn=uptime<1s"
$res | Should -Match "OK: uptime"
$LASTEXITCODE | Should -Be 0
}
}

Context "Uninstall snclient.msi" {
It "Should uninstall the .msi successfully" {
Start-Process msiexec -ArgumentList "/x $msiFilePath /qn" -Wait
$LASTEXITCODE | Should -Be 0
}

It "Wait until the snclient.exe disappears" {
$maxWaitTimeSeconds = 30
$elapsedTime = 0

while (Test-Path $snclient) {
if ($elapsedTime -ge $maxWaitTimeSeconds) {
throw "$snclient did not disappear within $maxWaitTimeSeconds seconds."
}

Start-Sleep -Seconds 1
$elapsedTime += 1
}
}
}
}
90 changes: 50 additions & 40 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
tags:
- "*"

# set go version for all steps
env:
GOVERSION: 1.20.x

jobs:
get-version:
Expand Down Expand Up @@ -34,54 +37,51 @@ jobs:


test:
strategy:
fail-fast: false
matrix:
go-version: [1.20.x]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
go-version: ${{ env.GOVERSION }}
- run: make citest


test-win:
strategy:
fail-fast: false
matrix:
go-version: [1.20.x]
os: [windows-latest]
runs-on: ${{ matrix.os }}
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
go-version: ${{ env.GOVERSION }}
- run: go test -v pkg/... ; if ($LASTEXITCODE -ne 0) { exit 1 }

test-osx:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ env.GOVERSION }}
- run: make test

build:
strategy:
fail-fast: false
matrix:
go-version: [1.20.x]
go-os: [linux, freebsd, darwin]
go-arch: [386, amd64, arm64]
exclude:
- go-os: darwin
go-arch: 386
needs: [test, test-win, get-version]
needs: [get-version]
runs-on: ubuntu-latest
env:
BIN: "snclient-${{needs.get-version.outputs.version}}-${{ matrix.go-os }}-${{ matrix.go-arch }}"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
go-version: ${{ env.GOVERSION }}
- run: |
echo "Building ${{ env.BIN }}"
make GOOS=${{ matrix.go-os }} GOARCH=${{ matrix.go-arch }} build
Expand All @@ -96,18 +96,17 @@ jobs:
strategy:
fail-fast: false
matrix:
go-version: [1.20.x]
go-os: [windows]
go-arch: [386, amd64]
needs: [test, test-win, get-version]
needs: [get-version]
runs-on: ubuntu-latest
env:
BIN: "snclient-${{needs.get-version.outputs.version}}-${{ matrix.go-os }}-${{ matrix.go-arch }}"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
go-version: ${{ env.GOVERSION }}
- run: |
echo "Building ${{ env.BIN }}.exe"
make GOOS=${{ matrix.go-os }} GOARCH=${{ matrix.go-arch }} build
Expand All @@ -120,16 +119,13 @@ jobs:


dist-win:
strategy:
matrix:
go-version: [1.20.x]
needs: [test, test-win, get-version]
needs: [get-version]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
go-version: ${{ env.GOVERSION }}
- run: sudo apt-get install help2man
- run: |
echo "Creating dist folder for windows"
Expand All @@ -144,10 +140,9 @@ jobs:
pkg-msi:
strategy:
matrix:
go-version: [1.20.x]
go-os: [windows]
go-arch: [386, amd64]
needs: [get-version, build-win, dist-win]
needs: [get-version, build-win, dist-win, test, test-win, test-osx]
runs-on: windows-latest
env:
BIN: "snclient-${{needs.get-version.outputs.version}}-${{ matrix.go-os }}-${{ matrix.go-arch }}"
Expand Down Expand Up @@ -185,11 +180,10 @@ jobs:
pkg-deb:
strategy:
matrix:
go-version: [1.20.x]
go-os: [linux]
go-arch: [386, amd64, arm64]
runs-on: ubuntu-latest
needs: [get-version, build]
needs: [get-version, build, test, test-win, test-osx]
env:
BIN: "snclient-${{needs.get-version.outputs.version}}-${{ matrix.go-os }}-${{ matrix.go-arch }}"
steps:
Expand All @@ -211,11 +205,10 @@ jobs:
pkg-osx:
strategy:
matrix:
go-version: [1.20.x]
go-os: [darwin]
go-arch: [amd64, arm64]
runs-on: macos-latest
needs: [get-version, build]
needs: [get-version, build, test, test-win, test-osx]
env:
BIN: "snclient-${{needs.get-version.outputs.version}}-${{ matrix.go-os }}-${{ matrix.go-arch }}"
DIST: "snclient-${{needs.get-version.outputs.version}}-osx-${{ matrix.go-arch }}"
Expand Down Expand Up @@ -245,11 +238,10 @@ jobs:
pkg-rpm:
strategy:
matrix:
go-version: [1.20.x]
go-os: [linux]
go-arch: [386, amd64, arm64]
runs-on: ubuntu-latest
needs: [get-version, build]
needs: [get-version, build, test, test-win, test-osx]
env:
BIN: "snclient-${{needs.get-version.outputs.version}}-${{ matrix.go-os }}-${{ matrix.go-arch }}"
steps:
Expand All @@ -275,7 +267,6 @@ jobs:
clean-tmp-files:
strategy:
matrix:
go-version: [1.20.x]
go-os: [linux]
go-arch: [386, amd64, arm64]
runs-on: ubuntu-latest
Expand All @@ -298,10 +289,34 @@ jobs:
name: "windist"


integration-test-windows:
strategy:
matrix:
go-os: [windows]
go-arch: [amd64]
runs-on: windows-latest
needs: [get-version,pkg-msi]
env:
BIN: "snclient-${{needs.get-version.outputs.version}}-${{ matrix.go-os }}-${{ matrix.go-arch }}"
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: "${{ env.BIN }}.msi"
- name: Run Pester Tests
run: |
Move-Item -Path ${{ env.BIN }}.msi -Destination .\snclient.msi
Set-PSRepository psgallery -InstallationPolicy trusted
Install-Module -Name Pester -Confirm:$false -Force -SkipPublisherCheck
Invoke-Pester -Path ".\.github\tests\windows" -CI
if ($Error[0].Fullyqualifiederrorid -eq 'PesterAssertionFailed') {exit 1}
shell: powershell


make-release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs: [get-version,pkg-msi,pkg-deb,pkg-rpm]
needs: [get-version,pkg-msi,pkg-deb,pkg-rpm,pkg-osx,integration-test-windows, test, test-win, test-osx]
outputs:
release-upload-url: ${{ steps.create-release.outputs.upload_url }}
steps:
Expand All @@ -320,7 +335,6 @@ jobs:
if: startsWith(github.ref, 'refs/tags/')
strategy:
matrix:
go-version: [1.20.x]
go-os: [windows]
go-arch: [386, amd64]
runs-on: ubuntu-latest
Expand All @@ -340,7 +354,6 @@ jobs:
if: startsWith(github.ref, 'refs/tags/')
strategy:
matrix:
go-version: [1.20.x]
go-os: [linux]
go-arch: [386, amd64, arm64]
runs-on: ubuntu-latest
Expand All @@ -360,7 +373,6 @@ jobs:
if: startsWith(github.ref, 'refs/tags/')
strategy:
matrix:
go-version: [1.20.x]
go-os: [linux]
go-arch: [386, amd64, arm64]
runs-on: ubuntu-latest
Expand All @@ -380,7 +392,6 @@ jobs:
if: startsWith(github.ref, 'refs/tags/')
strategy:
matrix:
go-version: [1.20.x]
go-os: [darwin]
go-arch: [amd64, arm64]
runs-on: ubuntu-latest
Expand All @@ -400,7 +411,6 @@ jobs:
if: startsWith(github.ref, 'refs/tags/')
strategy:
matrix:
go-version: [1.20.x]
go-os: [freebsd]
go-arch: [386, amd64, arm64]
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ golangci: tools
if [ $$dir != "pkg/eventlog" ]; then \
echo " - GOOS=linux"; \
( cd $$dir && GOOS=linux golangci-lint run ./... ); \
echo " - GOOS=darwin"; \
( cd $$dir && GOOS=darwin golangci-lint run ./... ); \
echo " - GOOS=freebsd"; \
( cd $$dir && GOOS=freebsd golangci-lint run ./... ); \
fi; \
echo " - GOOS=windows"; \
( cd $$dir && GOOS=windows golangci-lint run ./... ); \
Expand Down
6 changes: 3 additions & 3 deletions pkg/snclient/check_files_helper_osx_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func getCheckFileTimes(fileInfo fs.FileInfo) (*FileInfoUnified, error) {
}

return &FileInfoUnified{
Atime: time.Unix(int64(fileInfoSys.Atimespec.Sec), int64(fileInfoSys.Atimespec.Nsec)),
Mtime: time.Unix(int64(fileInfoSys.Mtimespec.Sec), int64(fileInfoSys.Mtimespec.Nsec)),
Ctime: time.Unix(int64(fileInfoSys.Ctimespec.Sec), int64(fileInfoSys.Ctimespec.Nsec)),
Atime: time.Unix(int64(fileInfoSys.Atimespec.Sec), int64(fileInfoSys.Atimespec.Nsec)), //nolint:unconvert // its a int32 on freebsd i386, so conversion is required
Mtime: time.Unix(int64(fileInfoSys.Mtimespec.Sec), int64(fileInfoSys.Mtimespec.Nsec)), //nolint:unconvert // same
Ctime: time.Unix(int64(fileInfoSys.Ctimespec.Sec), int64(fileInfoSys.Ctimespec.Nsec)), //nolint:unconvert // same
}, nil
}
2 changes: 0 additions & 2 deletions pkg/snclient/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,6 @@ func addFireWallRule(snc *snclient.Agent, name string, port int64) error {
fmt.Sprintf("localport=%d", port),
fmt.Sprintf("name=%s%s", FIREWALLPREFIX, name),
)
pwd, _ := os.Getwd()
snc.Log.Errorf("pwd: %s", pwd)

output, err := cmd.CombinedOutput()
output = bytes.TrimSpace(output)
Expand Down

0 comments on commit 7a76e61

Please sign in to comment.