Skip to content

Commit

Permalink
Merge pull request #52 from theohbrothers/fix/tests-fix-unit-tests-fa…
Browse files Browse the repository at this point in the history
…iling-for-powershell-on-windows-nt

Fix (tests): Fix unit tests failing  for powershell on Windows_NT
  • Loading branch information
leojonathanoh authored May 30, 2021
2 parents de5f049 + 0407e3d commit 002850b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ Describe "Get-ContextFileContent" -Tag 'Unit' {
Mock Test-Path { $true }

$content = Get-ContextFileContent -Template $template
$content[0] | Should -Match "Some content from bar/foo.header.ps1"
$content[1] | Should -Match "Some content from bar/foo.ps1"
$content[0].Replace('\', '/') | Should -Match "Some content from bar/foo.header.ps1"
$content[1].Replace('\', '/') | Should -Match "Some content from bar/foo.ps1"
}

It 'Returns body content (based on template)' {
Expand All @@ -58,7 +58,7 @@ Describe "Get-ContextFileContent" -Tag 'Unit' {
Mock Test-Path { $true }

$content = Get-ContextFileContent -Template $template
$content | Should -Match "Some content from bar/foo.ps1"
$content.Replace('\', '/') | Should -Match "Some content from bar/foo.ps1"
}

It 'Returns body content (based on subtemplates)' {
Expand All @@ -73,8 +73,8 @@ Describe "Get-ContextFileContent" -Tag 'Unit' {
Mock Test-Path { $true }

$content = Get-ContextFileContent -Template $template
$content[0] | Should -Match "Some content from bar/john/john.ps1"
$content[1] | Should -Match "Some content from bar/doe/doe.ps1"
$content[0].Replace('\', '/') | Should -Match "Some content from bar/john/john.ps1"
$content[1].Replace('\', '/') | Should -Match "Some content from bar/doe/doe.ps1"
}

It 'Returns footer content' {
Expand All @@ -86,8 +86,8 @@ Describe "Get-ContextFileContent" -Tag 'Unit' {
Mock Test-Path { $true }

$content = Get-ContextFileContent -Template $template
$content[0] | Should -Match "Some content from bar/foo.ps1"
$content[1] | Should -Match "Some content from bar/foo.footer.ps1"
$content[0].Replace('\', '/') | Should -Match "Some content from bar/foo.ps1"
$content[1].Replace('\', '/') | Should -Match "Some content from bar/foo.footer.ps1"
}

It 'Returns header, body (based on template), and footer content' {
Expand All @@ -100,9 +100,9 @@ Describe "Get-ContextFileContent" -Tag 'Unit' {
Mock Test-Path { $true }

$content = Get-ContextFileContent -Template $template
$content[0] | Should -Match "Some content from bar/foo.header.ps1"
$content[1] | Should -Match "Some content from bar/foo.ps1"
$content[2] | Should -Match "Some content from bar/foo.footer.ps1"
$content[0].Replace('\', '/') | Should -Match "Some content from bar/foo.header.ps1"
$content[1].Replace('\', '/') | Should -Match "Some content from bar/foo.ps1"
$content[2].Replace('\', '/') | Should -Match "Some content from bar/foo.footer.ps1"
}

It 'Returns header, body (based on subtemplates), and footer content' {
Expand All @@ -119,10 +119,10 @@ Describe "Get-ContextFileContent" -Tag 'Unit' {
Mock Test-Path { $true }

$content = Get-ContextFileContent -Template $template
$content[0] | Should -Match "Some content from bar/foo.header.ps1"
$content[1] | Should -Match "Some content from bar/john/john.ps1"
$content[2] | Should -Match "Some content from bar/doe/doe.ps1"
$content[3] | Should -Match "Some content from bar/foo.footer.ps1"
$content[0].Replace('\', '/') | Should -Match "Some content from bar/foo.header.ps1"
$content[1].Replace('\', '/') | Should -Match "Some content from bar/john/john.ps1"
$content[2].Replace('\', '/') | Should -Match "Some content from bar/doe/doe.ps1"
$content[3].Replace('\', '/') | Should -Match "Some content from bar/foo.footer.ps1"
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Describe "Populate-GenerateConfig" -Tag 'Unit' {
$GenerateConfigAfter['VARIANTS'][0]['tag_as_latest'] | Should -Be $false
$GenerateConfigAfter['VARIANTS'][0]['tag_without_distro'] | Should -Be 'foo'
$GenerateConfigAfter['VARIANTS'][0]['components'] | Should -Be 'foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'] | Should -Be ([IO.Path]::Combine('variants', 'foo'))
$GenerateConfigAfter['VARIANTS'][0]['build_dir'] | Should -Be '/repo/variants/foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'].Replace('\', '/') | Should -Be 'variants/foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir'].Replace('\', '/') | Should -Be '/repo/variants/foo'
}

It 'Populates variant with specified distro (behind)' {
Expand All @@ -51,8 +51,8 @@ Describe "Populate-GenerateConfig" -Tag 'Unit' {
$GenerateConfigAfter['VARIANTS'][0]['tag_as_latest'] | Should -Be $false
$GenerateConfigAfter['VARIANTS'][0]['tag_without_distro'] | Should -Be 'foo'
$GenerateConfigAfter['VARIANTS'][0]['components'] | Should -Be 'foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'] | Should -Be ([IO.Path]::Combine('variants', 'foo-alpine'))
$GenerateConfigAfter['VARIANTS'][0]['build_dir'] | Should -Be (Join-Path '/repo' ([IO.Path]::Combine('variants', 'foo-alpine')))
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'].Replace('\', '/') | Should -Be 'variants/foo-alpine'
$GenerateConfigAfter['VARIANTS'][0]['build_dir'].Replace('\', '/') | Should -Be '/repo/variants/foo-alpine'
}

It 'Populates variant with specified distro (middle)' {
Expand All @@ -73,8 +73,8 @@ Describe "Populate-GenerateConfig" -Tag 'Unit' {
$GenerateConfigAfter['VARIANTS'][0]['tag_as_latest'] | Should -Be $false
$GenerateConfigAfter['VARIANTS'][0]['tag_without_distro'] | Should -Be 'foo-bar'
$GenerateConfigAfter['VARIANTS'][0]['components'] | Should -Be 'foo', 'bar'
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'] | Should -Be ([IO.Path]::Combine('variants', 'foo-alpine-bar'))
$GenerateConfigAfter['VARIANTS'][0]['build_dir'] | Should -Be (Join-Path '/repo' ([IO.Path]::Combine('variants', 'foo-alpine-bar')))
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'].Replace('\', '/') | Should -Be 'variants/foo-alpine-bar'
$GenerateConfigAfter['VARIANTS'][0]['build_dir'].Replace('\', '/') | Should -Be '/repo/variants/foo-alpine-bar'
}

It 'Populates variant with specified distro (front)' {
Expand All @@ -95,8 +95,8 @@ Describe "Populate-GenerateConfig" -Tag 'Unit' {
$GenerateConfigAfter['VARIANTS'][0]['tag_as_latest'] | Should -Be $false
$GenerateConfigAfter['VARIANTS'][0]['tag_without_distro'] | Should -Be 'foo'
$GenerateConfigAfter['VARIANTS'][0]['components'] | Should -Be 'foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'] | Should -Be ([IO.Path]::Combine('variants', 'alpine-foo'))
$GenerateConfigAfter['VARIANTS'][0]['build_dir'] | Should -Be (Join-Path '/repo' ([IO.Path]::Combine('variants', 'alpine-foo')))
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'].Replace('\', '/') | Should -Be 'variants/alpine-foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir'].Replace('\', '/') | Should -Be '/repo/variants/alpine-foo'
}

It 'Populates variant with tag_as_latest' {
Expand All @@ -116,8 +116,8 @@ Describe "Populate-GenerateConfig" -Tag 'Unit' {
$GenerateConfigAfter['VARIANTS'][0]['tag_as_latest'] | Should -Be $true
$GenerateConfigAfter['VARIANTS'][0]['tag_without_distro'] | Should -Be 'foo'
$GenerateConfigAfter['VARIANTS'][0]['components'] | Should -Be 'foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'] | Should -Be ([IO.Path]::Combine('variants', 'foo'))
$GenerateConfigAfter['VARIANTS'][0]['build_dir'] | Should -Be '/repo/variants/foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'].Replace('\', '/') | Should -Be 'variants/foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir'].Replace('\', '/') | Should -Be '/repo/variants/foo'
}

It 'Populates variant with specified components' {
Expand All @@ -140,8 +140,8 @@ Describe "Populate-GenerateConfig" -Tag 'Unit' {
$GenerateConfigAfter['VARIANTS'][0]['tag_as_latest'] | Should -Be $false
$GenerateConfigAfter['VARIANTS'][0]['tag_without_distro'] | Should -Be 'foo'
$GenerateConfigAfter['VARIANTS'][0]['components'] | Should -Be 'john', 'doe'
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'] | Should -Be ([IO.Path]::Combine('variants', 'foo'))
$GenerateConfigAfter['VARIANTS'][0]['build_dir'] | Should -Be '/repo/variants/foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'].Replace('\', '/') | Should -Be 'variants/foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir'].Replace('\', '/') | Should -Be '/repo/variants/foo'
}

It 'Populates variant with specified distro and components' {
Expand All @@ -166,8 +166,8 @@ Describe "Populate-GenerateConfig" -Tag 'Unit' {
$GenerateConfigAfter['VARIANTS'][0]['tag_as_latest'] | Should -Be $false
$GenerateConfigAfter['VARIANTS'][0]['tag_without_distro'] | Should -Be 'foo'
$GenerateConfigAfter['VARIANTS'][0]['components'] | Should -Be 'john', 'doe'
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'] | Should -Be ([IO.Path]::Combine('variants', 'foo-alpine'))
$GenerateConfigAfter['VARIANTS'][0]['build_dir'] | Should -Be (Join-Path '/repo' ([IO.Path]::Combine('variants', 'foo-alpine')))
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'].Replace('\', '/') | Should -Be 'variants/foo-alpine'
$GenerateConfigAfter['VARIANTS'][0]['build_dir'].Replace('\', '/') | Should -Be '/repo/variants/foo-alpine'
}

It 'Populates variant definition with buildContextFiles' {
Expand Down Expand Up @@ -212,20 +212,20 @@ Describe "Populate-GenerateConfig" -Tag 'Unit' {
$GenerateConfigAfter['VARIANTS'][0]['tag_as_latest'] | Should -Be $false
$GenerateConfigAfter['VARIANTS'][0]['tag_without_distro'] | Should -Be 'foo'
$GenerateConfigAfter['VARIANTS'][0]['components'] | Should -Be 'foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'] | Should -Be ([IO.Path]::Combine('variants', 'foo'))
$GenerateConfigAfter['VARIANTS'][0]['build_dir'] | Should -Be '/repo/variants/foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'].Replace('\', '/') | Should -Be 'variants/foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir'].Replace('\', '/') | Should -Be '/repo/variants/foo'

$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['common'] | Should -Be $true
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['includeHeader'] | Should -Be $true
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['includeFooter'] | Should -Be $true
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['passes'][0]['variables']['john'] | Should -Be 'doe'
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['passes'][0]['file'] | Should -Be '/repo/variants/foo/Dockerfile'
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['passes'][0]['file'].Replace('\', '/') | Should -Be '/repo/variants/foo/Dockerfile'
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['passes'][1]['variables']['john'] | Should -Be 'doe'
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['passes'][1]['file'] | Should -Be '/repo/variants/foo/Dockerfile2'
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['templateDirectory'] | Should -Be '/repo/path/to/templates'
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['passes'][1]['file'].Replace('\', '/') | Should -Be '/repo/variants/foo/Dockerfile2'
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['templateDirectory'].Replace('\', '/') | Should -Be '/repo/path/to/templates'
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['subTemplates'] | Should -Be @()

$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['copies'][0] | Should -Be '/repo/bar'
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['copies'][0].Replace('\', '/') | Should -Be '/repo/bar'
}

It 'Populates variant definition with shared definition' {
Expand Down Expand Up @@ -266,15 +266,15 @@ Describe "Populate-GenerateConfig" -Tag 'Unit' {
$GenerateConfigAfter['VARIANTS'][0]['tag_as_latest'] | Should -Be $false
$GenerateConfigAfter['VARIANTS'][0]['tag_without_distro'] | Should -Be 'foo'
$GenerateConfigAfter['VARIANTS'][0]['components'] | Should -Be 'foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'] | Should -Be ([IO.Path]::Combine('variants', 'foo'))
$GenerateConfigAfter['VARIANTS'][0]['build_dir'] | Should -Be '/repo/variants/foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'].Replace('\', '/') | Should -Be 'variants/foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir'].Replace('\', '/') | Should -Be '/repo/variants/foo'

$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['common'] | Should -Be $true
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['includeHeader'] | Should -Be $true
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['includeFooter'] | Should -Be $true
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['passes'][0]['variables']['john'] | Should -Be 'doe'

$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['copies'][0] | Should -Be '/repo/bar'
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['copies'][0].Replace('\', '/') | Should -Be '/repo/bar'
}

It 'Prioritises variant definition over shared definition' {
Expand Down Expand Up @@ -335,15 +335,15 @@ Describe "Populate-GenerateConfig" -Tag 'Unit' {
$GenerateConfigAfter['VARIANTS'][0]['tag_as_latest'] | Should -Be $false
$GenerateConfigAfter['VARIANTS'][0]['tag_without_distro'] | Should -Be 'foo'
$GenerateConfigAfter['VARIANTS'][0]['components'] | Should -Be 'foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'] | Should -Be ([IO.Path]::Combine('variants', 'foo'))
$GenerateConfigAfter['VARIANTS'][0]['build_dir'] | Should -Be '/repo/variants/foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir_rel'].Replace('\', '/') | Should -Be 'variants/foo'
$GenerateConfigAfter['VARIANTS'][0]['build_dir'].Replace('\', '/') | Should -Be '/repo/variants/foo'

$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['common'] | Should -Be $false
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['includeHeader'] | Should -Be $false
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['includeFooter'] | Should -Be $false
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['templates']['Dockerfile']['passes'][0]['variables']['john'] | Should -Be ''

$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['copies'][0] | Should -Be '/repo/bar'
$GenerateConfigAfter['VARIANTS'][0]['buildContextFiles']['copies'][0].Replace('\', '/') | Should -Be '/repo/bar'
}

It 'Populates variant with files' {
Expand All @@ -357,8 +357,8 @@ Describe "Populate-GenerateConfig" -Tag 'Unit' {
}
$GenerateConfigAfter = Populate-GenerateConfig -GenerateConfig $GenerateConfig

$GenerateConfigAfter['FILES'][0]['file'] | Should -Be '/repo/foo'
$GenerateConfigAfter['FILES'][0]['templateFile'] | Should -Be '/repo/path/to/templates/foo.ps1'
$GenerateConfigAfter['FILES'][0]['file'].Replace('\', '/') | Should -Be '/repo/foo'
$GenerateConfigAfter['FILES'][0]['templateFile'].Replace('\', '/') | Should -Be '/repo/path/to/templates/foo.ps1'
}

}
Expand Down

0 comments on commit 002850b

Please sign in to comment.