Skip to content

Commit

Permalink
Fix: Fix regression that resulted variant files not being generated
Browse files Browse the repository at this point in the history
Fixes a critical regression in #32 that resulted in the compiled variant configuration not being used, leading to no files being generated.

This bug affects all version since `v0.3.0`
  • Loading branch information
leojonathanoh committed Sep 12, 2021
1 parent 73cf527 commit 095cc79
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


Describe 'Generate-DockerImageVariants' -Tag 'Integration' {

$PROJECT_DIR = Convert-Path "$PSScriptRoot/../../"
Expand Down Expand Up @@ -32,16 +30,16 @@ Describe 'Generate-DockerImageVariants' -Tag 'Integration' {

Generate-DockerImageVariants -Init -ProjectPath $testProjectDir 6>&1 > $null

$testProjectGenerateDir | Get-Item | Should -BeOfType [System.IO.DirectoryInfo]
$testProjectGenerateDefinitionsDir | Get-Item | Should -BeOfType [System.IO.DirectoryInfo]
$testProjectGenerateTemplatesDir | Get-Item | Should -BeOfType [System.IO.DirectoryInfo]
$testProjectGenerateDir | Get-Item -Force | Should -BeOfType [System.IO.DirectoryInfo]
$testProjectGenerateDefinitionsDir | Get-Item -Force | Should -BeOfType [System.IO.DirectoryInfo]
$testProjectGenerateTemplatesDir | Get-Item -Force| Should -BeOfType [System.IO.DirectoryInfo]

$testProjectGenerateDefinitionsFiles | Get-Item | Should -BeOfType [System.IO.FileInfo]
$testProjectGenerateDefinitionsVariants | Get-Item | Should -BeOfType [System.IO.FileInfo]
$testProjectGenerateDefinitionsFiles | Get-Item -Force | Should -BeOfType [System.IO.FileInfo]
$testProjectGenerateDefinitionsVariants | Get-Item -Force | Should -BeOfType [System.IO.FileInfo]

$testProjectGenerateTemplatesDockerfile | Get-Item | Should -BeOfType [System.IO.FileInfo]
$testProjectGenerateTemplatesReadmeMd | Get-Item | Should -BeOfType [System.IO.FileInfo]
$testProjectGenerateTemplatesGitlabCiYml | Get-Item | Should -BeOfType [System.IO.FileInfo]
$testProjectGenerateTemplatesDockerfile | Get-Item -Force | Should -BeOfType [System.IO.FileInfo]
$testProjectGenerateTemplatesReadmeMd | Get-Item -Force | Should -BeOfType [System.IO.FileInfo]
$testProjectGenerateTemplatesGitlabCiYml | Get-Item -Force | Should -BeOfType [System.IO.FileInfo]

# Cleanup
Get-Item $testProjectDir | Remove-Item -Recurse -Force
Expand Down Expand Up @@ -84,6 +82,22 @@ Describe 'Generate-DockerImageVariants' -Tag 'Integration' {
Get-Item $testProjectDir | Remove-Item -Recurse -Force
}

It 'Should generate files for default prototypes created by -Init' {
# Mock project
$testProjectDir = "TestDrive:\test-project"
New-Item $testProjectDir -ItemType Directory > $null

Generate-DockerImageVariants -ProjectPath $testProjectDir -Init -ErrorAction Stop #6>$null
Generate-DockerImageVariants -ProjectPath $testProjectDir -ErrorAction Stop 6>$null

Test-Path $testProjectDir/variants/curl/Dockerfile | Should -Be $true
Test-Path $testProjectDir/variants/curl-git/Dockerfile | Should -Be $true
Test-Path $testProjectDir/variants/my-cool-variant/Dockerfile | Should -Be $true

# Cleanup
Get-Item $testProjectDir | Remove-Item -Recurse -Force
}

It 'Should generate files for example: basic' {
{
$exampleProjectPath = Join-Path $DOCS_EXAMPLES_DIR 'basic'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function New-RepositoryVariantBuildContext {

if ($Variant.Contains('buildContextFiles')) {
# Generate files from templates
if ( $Variant['buildContextFiles'].Contains('templates') -and $Variant['buildContextFiles']['templates'] -is [hashtable] ) {
if ($VARIANT['buildContextFiles'].Contains('templates')) {
foreach ($k in $Variant['buildContextFiles']['templates'].Keys) {
$template = $Variant['buildContextFiles']['templates'][$k]
foreach ($pass in $template['passes']) {
Expand All @@ -43,7 +43,7 @@ function New-RepositoryVariantBuildContext {
Get-ContextFileContent @params
}
New-Item $pass['file'] -ItemType File -Force > $null
$content | Out-File $pass['file'] -Encoding Utf8 -Force -NoNewline -Force
$content | Out-File $pass['file'] -Encoding Utf8 -NoNewline -Force
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function Populate-GenerateConfig {

if ($VARIANT.Contains('buildContextFiles')) {
# Populate the templates object
if ( $VARIANT['buildContextFiles'].Contains('templates') -and $VARIANT['buildContextFiles']['templates'] -is [hashtable] ) {
if ($VARIANT['buildContextFiles'].Contains('templates')) {
foreach ($k in $VARIANT['buildContextFiles']['templates'].Keys) {
$VARIANT['buildContextFiles']['templates'][$k]['file'] = $k
# Dynamically determine the sub templates from the name of the variant. (E.g. 'foo-bar' will comprise of foo and bar variant sub templates for this template file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ Describe "Generate-DockerImageVariants" -Tag 'Unit' {
function Get-VariantsPrototype {}
function Get-FilesPrototype {}
function Validate-Object {}
function Populate-GenerateConfig {}
function Populate-GenerateConfig {
param (
$GenerateConfig
)
$GenerateConfig
}
function New-RepositoryVariantBuildContext {}
function New-RepositoryFile {}

Expand Down Expand Up @@ -148,7 +153,12 @@ Describe "Generate-DockerImageVariants" -Tag 'Unit' {
$GenerateConfig
}
Mock Test-Path -ParameterFilter { $Path -eq 'files.ps1' } { $true }
Mock Populate-GenerateConfig {}
Mock Populate-GenerateConfig {
param (
$GenerateConfig
)
$GenerateConfig
}

Generate-DockerImageVariants -ProjectPath $projectPath

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function Generate-DockerImageVariants {
}

# Populate and normalize definitions
Populate-GenerateConfig -GenerateConfig $GenerateConfig
$GenerateConfig = Populate-GenerateConfig -GenerateConfig $GenerateConfig

# Generate each Docker image variant's build context files
& {
Expand Down

0 comments on commit 095cc79

Please sign in to comment.