Skip to content

Commit

Permalink
Added persisting of server config between sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
lipkau authored and AtlassianPS Automated User committed Aug 15, 2019
1 parent 6f6cd04 commit 6d34977
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
9 changes: 8 additions & 1 deletion JiraPS/JiraPS.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ if (!("System.Net.Http" -as [Type])) {
#endregion Dependencies

#region Configuration
$script:serverConfig = ("{0}/AtlassianPS/JiraPS/server_config" -f [Environment]::GetFolderPath('ApplicationData'))

if (-not (Test-Path $script:serverConfig)) {
$null = New-Item -Path $script:serverConfig -ItemType File -Force
}
$script:JiraServerUrl = [Uri](Get-Content $script:serverConfig)

$script:DefaultContentType = "application/json; charset=utf-8"
$script:DefaultPageSize = 25
$script:DefaultHeaders= @{ "Accept-Charset" = "utf-8" }
$script:DefaultHeaders = @{ "Accept-Charset" = "utf-8" }
# Bug in PSv3's .Net API
if ($PSVersionTable.PSVersion.Major -gt 3) {
$script:DefaultHeaders["Accept"] = "application/json"
Expand Down
2 changes: 2 additions & 0 deletions JiraPS/Public/Set-JiraConfigServer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ function Set-JiraConfigServer {

process {
$script:JiraServerUrl = $Server

Set-Content -Value $Server -Path "$script:serverConfig"
}

end {
Expand Down
5 changes: 1 addition & 4 deletions Tests/Functions/Get-JiraConfigServer.Unit.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@ Describe "Get-JiraConfigServer" -Tag 'Unit' {

$jiraServer = 'http://jiraserver.example.com'

It "returns empty if no server has been set" {
Get-JiraConfigServer | Should -BeNullOrEmpty
}

It "returns the server stored in the module's session" {
$script:JiraServerUrl = $jiraServer

Get-JiraConfigServer | Should -Be $jiraServer
}
}
Expand Down
6 changes: 6 additions & 0 deletions Tests/Functions/Set-JiraConfigServer.Unit.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,11 @@ Describe "Set-JiraConfigServer" -Tag 'Unit' {

$script:JiraServerUrl | Should -Be "$jiraServer/"
}

It "stores the server address in a config file" {
$script:serverConfig | Should -Exist

Get-Content $script:serverConfig | Should -Be "$jiraServer/"
}
}
}
13 changes: 13 additions & 0 deletions Tests/JiraPS.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ Describe "General project validation" -Tag Unit {

Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue
# Import-Module $env:BHManifestToTest

$configFile = ("{0}/AtlassianPS/JiraPS/server_config" -f [Environment]::GetFolderPath('ApplicationData'))
$oldConfig = Get-Content $configFile
}
AfterAll {
Set-Content -Value $oldConfig -Path $configFile -Force

Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue
Remove-Module BuildHelpers -ErrorAction SilentlyContinue
Remove-Item -Path Env:\BH*
Expand Down Expand Up @@ -60,6 +65,14 @@ Describe "General project validation" -Tag Unit {
[Version](Get-Metadata -Path $env:BHManifestToTest -PropertyName ModuleVersion) | Should -BeOfType [Version]
}

It "module uses the previous server config when loaded" {
Set-Content -Value "https://example.com" -Path $configFile -Force

Import-Module $env:BHManifestToTest -Force

Get-JiraConfigServer | Should -Be "https://example.com/"
}

# It "module is imported with default prefix" {
# $prefix = Get-Metadata -Path $env:BHManifestToTest -PropertyName DefaultCommandPrefix

Expand Down

0 comments on commit 6d34977

Please sign in to comment.