Skip to content

Commit

Permalink
Merge branch 'release/1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffen committed Sep 27, 2022
2 parents d2fd075 + 11fcb78 commit e362621
Show file tree
Hide file tree
Showing 14 changed files with 201 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ on:

jobs:
build-validation:
uses: abbgrade/PsBuildTasks/.github/workflows/build-validation-matrix.yml@1.4.0
uses: abbgrade/PsBuildTasks/.github/workflows/build-validation-matrix.yml@1.5.0
2 changes: 1 addition & 1 deletion .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
pre-release:
uses: abbgrade/PsBuildTasks/.github/workflows/pre-release-windows.yml@1.4.0
uses: abbgrade/PsBuildTasks/.github/workflows/pre-release-windows.yml@1.5.0
with:
module-name: PsSqlTestServer
secrets:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
release:
uses: abbgrade/PsBuildTasks/.github/workflows/release-windows.yml@1.4.0
uses: abbgrade/PsBuildTasks/.github/workflows/release-windows.yml@1.5.0
with:
module-name: PsSqlTestServer
secrets:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.4.0] - 2022-09-27

## Added

- Added DatabaseCredential property to `New-DockerInstance`.

## [1.3.0] - 2022-08-07

### Added
Expand Down
57 changes: 57 additions & 0 deletions docs/Clear-SqlTestLocalInstance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
external help file: PsSqlTestServer-help.xml
Module Name: PsSqlTestServer
online version:
schema: 2.0.0
---

# Clear-SqlTestLocalInstance

## SYNOPSIS
Remove all localdb test instances

## SYNTAX

```
Clear-SqlTestLocalInstance [-WhatIf] [<CommonParameters>]
```

## DESCRIPTION
Remove all instances created by New-LocalInstance.
These are identified using the 'test-' prefix.

## EXAMPLES

### EXAMPLE 1
```
Clear-SqlTestLocalInstance
```

## PARAMETERS

### -WhatIf
Shows what would happen if the cmdlet runs.
The cmdlet is not run.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
## OUTPUTS
## NOTES
## RELATED LINKS
37 changes: 19 additions & 18 deletions docs/New-SqlTestDockerInstance.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,25 @@ Returns a object with the properties DataSource and ConnectionString.
### EXAMPLE 1
```
New-SqlTestDockerInstance -AcceptEula
Name : Sandbox
Hostname : localhost
UserId : sa
ConnectionString : Server='localhost';Encrypt=False;User Id='sa';Password='pa$$w0rd'
IsDocker : True
Id : 693d5e79169c50af4ab5b10e1af9069a987ec8902033f3c55f325e12199a61c1
Names : {Sandbox}
Image : mcr.microsoft.com/mssql/server
Command : "/opt/mssql/bin/permissions_check.sh /opt/mssql/bin/sqlservr"
LocalVolumes : {0}
Labels : {com.microsoft.product=Microsoft SQL Server, com.microsoft.version=15.0.4153.1, vendor=Microsoft}
Mounts : {}
Networks : {bridge}
Ports : {0.0.0.0:1433->1433/tcp}
CreatedAt : 2021-12-01 00:00:00 +0100 CET
RunningFor : 2 seconds ago
Status : Up 1 second
Size : 0B (virtual 1.54GB)
Name : Sandbox
Hostname : localhost
UserId : sa
ConnectionString : Server='localhost';Encrypt=False;User Id='sa';Password='pa$$w0rd'
IsDocker : True
Id : 693d5e79169c50af4ab5b10e1af9069a987ec8902033f3c55f325e12199a61c1
Names : {Sandbox}
Image : mcr.microsoft.com/mssql/server
Command : "/opt/mssql/bin/permissions_check.sh /opt/mssql/bin/sqlservr"
LocalVolumes : {0}
Labels : {com.microsoft.product=Microsoft SQL Server, com.microsoft.version=15.0.4153.1, vendor=Microsoft}
Mounts : {}
Networks : {bridge}
Ports : {0.0.0.0:1433->1433/tcp}
CreatedAt : 2021-12-01 00:00:00 +0100 CET
RunningFor : 2 seconds ago
Status : Up 1 second
Size : 0B (virtual 1.54GB)
DatabaseCredential : System.Management.Automation.PSCredential
```

## PARAMETERS
Expand Down
18 changes: 17 additions & 1 deletion docs/Remove-SqlTestLocalInstance.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Removes a test SQL server.
## SYNTAX

```
Remove-SqlTestLocalInstance [-Name] <String> [<CommonParameters>]
Remove-SqlTestLocalInstance [-Name] <String> [-WhatIf] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -44,6 +44,22 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -WhatIf
Shows what would happen if the cmdlet runs.
The cmdlet is not run.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
Expand Down
1 change: 1 addition & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-minimal
2 changes: 1 addition & 1 deletion src/PsSqlTestServer.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PsSqlTestServer.psm1'

# Version number of this module.
ModuleVersion = '1.3.0'
ModuleVersion = '1.4.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
24 changes: 24 additions & 0 deletions src/Public/Clear-LocalInstance.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function Clear-LocalInstance {

<#
.SYNOPSIS
Remove all localdb test instances
.DESCRIPTION
Remove all instances created by New-LocalInstance. These are identified using the 'test-' prefix.
.EXAMPLE
PS> Clear-SqlTestLocalInstance
#>

[CmdletBinding()]
param (
[Parameter()]
[switch] $WhatIf
)

Import-Module PsSqlLocalDb -ErrorAction Stop

Get-LocalInstance -First $null | Where-Object Name -Like test-* | Remove-LocalInstance -WhatIf:$WhatIf
}
7 changes: 6 additions & 1 deletion src/Public/Get-LocalInstance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ function Get-LocalInstance {

Import-Module PsSqlLocalDb -ErrorAction Stop

Get-LocalDbInstance | Select-Object -First $First | ForEach-Object {
$selectParam = @{}
if ( $First ) {
$selectParam.First = $First
}

Get-LocalDbInstance | Select-Object @selectParam | ForEach-Object {
$instance = $PSItem

# add metadata
Expand Down
44 changes: 25 additions & 19 deletions src/Public/New-DockerInstance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,25 @@ function New-DockerInstance {
.EXAMPLE
PS> New-SqlTestDockerInstance -AcceptEula
Name : Sandbox
Hostname : localhost
UserId : sa
ConnectionString : Server='localhost';Encrypt=False;User Id='sa';Password='pa$$w0rd'
IsDocker : True
Id : 693d5e79169c50af4ab5b10e1af9069a987ec8902033f3c55f325e12199a61c1
Names : {Sandbox}
Image : mcr.microsoft.com/mssql/server
Command : "/opt/mssql/bin/permissions_check.sh /opt/mssql/bin/sqlservr"
LocalVolumes : {0}
Labels : {com.microsoft.product=Microsoft SQL Server, com.microsoft.version=15.0.4153.1, vendor=Microsoft}
Mounts : {}
Networks : {bridge}
Ports : {0.0.0.0:1433->1433/tcp}
CreatedAt : 2021-12-01 00:00:00 +0100 CET
RunningFor : 2 seconds ago
Status : Up 1 second
Size : 0B (virtual 1.54GB)
Name : Sandbox
Hostname : localhost
UserId : sa
ConnectionString : Server='localhost';Encrypt=False;User Id='sa';Password='pa$$w0rd'
IsDocker : True
Id : 693d5e79169c50af4ab5b10e1af9069a987ec8902033f3c55f325e12199a61c1
Names : {Sandbox}
Image : mcr.microsoft.com/mssql/server
Command : "/opt/mssql/bin/permissions_check.sh /opt/mssql/bin/sqlservr"
LocalVolumes : {0}
Labels : {com.microsoft.product=Microsoft SQL Server, com.microsoft.version=15.0.4153.1, vendor=Microsoft}
Mounts : {}
Networks : {bridge}
Ports : {0.0.0.0:1433->1433/tcp}
CreatedAt : 2021-12-01 00:00:00 +0100 CET
RunningFor : 2 seconds ago
Status : Up 1 second
Size : 0B (virtual 1.54GB)
DatabaseCredential : System.Management.Automation.PSCredential
#>

Expand Down Expand Up @@ -88,10 +89,15 @@ function New-DockerInstance {
$container | Add-Member 'DataSource' 'localhost'
$container | Add-Member 'Port' $Port
$container | Add-Member 'UserId' 'sa'
$container | Add-Member 'SecurePassword' ( ConvertTo-SecureString $ServerAdminPassword -AsPlainText -Force )
$container | Add-Member 'SecurePassword' (
ConvertTo-SecureString $ServerAdminPassword -AsPlainText -Force
)
$container | Add-Member 'ConnectTimeout' 30
$container | Add-Member 'ConnectionString' "Server='$( $container.Hostname ),$( $container.Port )';Connect Timeout=$( $container.ConnectTimeout );Encrypt=False;User Id='$( $container.UserId )';Password='$ServerAdminPassword'"
$container | Add-Member 'IsDocker' $true
$container | Add-Member 'DatabaseCredential' (
New-Object System.Management.Automation.PSCredential ($container.UserId, $container.SecurePassword)
)

# return
$container | Write-Output
Expand Down
11 changes: 9 additions & 2 deletions src/Public/Remove-LocalInstance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ function Remove-LocalInstance {
# Specifies the name of the instance to remove.
[Parameter( Mandatory, ValueFromPipelineByPropertyName )]
[ValidateNotNullOrEmpty()]
[string] $Name
[string] $Name,

[Parameter()]
[switch] $WhatIf

)

Expand All @@ -29,6 +32,10 @@ function Remove-LocalInstance {
}

process {
Remove-LocalDbInstance -Name $Name
if ( $WhatIf.IsPresent ) {
Write-Verbose "Remove $Name" -Verbose
} else {
Remove-LocalDbInstance -Name $Name
}
}
}
33 changes: 33 additions & 0 deletions test/Clear-LocalInstance.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#Requires -Modules @{ ModuleName='Pester'; ModuleVersion='5.0.0' }

Describe Clear-LocalInstance {

BeforeAll {
Import-Module $PSScriptRoot\..\src\PsSqlTestServer.psd1 -Force -ErrorAction Stop
}

Context LocalInstance {
BeforeEach {
$Instance = @((New-SqlTestLocalInstance), (New-SqlTestLocalInstance))

Import-Module PsSqlLocalDb -ErrorAction Stop
}

It Works-with-WhatIf {
Clear-SqlTestLocalInstance -ErrorAction Stop -WhatIf

(
Get-LocalDbInstance |
Where-Object Name -in ( $Instance | Select-Object -ExpandProperty Name )
).Count | Should -Be $Instance.Count
}

It Works {
Clear-SqlTestLocalInstance -ErrorAction Stop

Get-LocalDbInstance |
Where-Object Name -in ( $Instance | Select-Object -ExpandProperty Name ) |
Should -BeNullOrEmpty
}
}
}

0 comments on commit e362621

Please sign in to comment.