microsoft / navcontainerhelper

Official Microsoft repository for BcContainerHelper, a PowerShell module, which makes it easier to work with Business Central Containers on Docker.
MIT License
382 stars 245 forks source link

Issue with Get-TestsInNavContainer BC14 #998

Closed GreatScott000 closed 4 years ago

GreatScott000 commented 4 years ago

Describe the issue I am debugging issues I am having with the CI.YML in the https://dev.azure.com/businesscentralapps/HelloWorld repository as I make adjustments for BC14 I have published the APP and TEST apps to a container outside the build pipeline to test and unless I manually add scripts to the DEFAULT Test Suite no tests are found by Get-TestsInNavContainer

Is Get-TestsInNAVContainer supposed to add the tests to the Test Suite?
How can I get this work? Am I missing something in the CI.YML? Is there a step that adds the tests to the Test Suite?

Without the tests being found, the pipeline fails as the TempTestResultFile is not created and then the Run-Tests script errors out. You will note the output from the pipeline matches the output from the Get-Tests scripts when no test added to the default container as opposed to the Get-Test script output when the tests are added to the Default Test Suite manually.

I have run this against the BC16 (in my training class from Kevin Smet) and it works as expected. So I am wondering if it is a BC14 issue.

Scripts used to create container and cause the issue Script to build container

$parameters = @{
    "Accept_Eula" = $true
    "Accept_Outdated" = $true
}

$containerName = 'Test-BC1401'
$imageName = 'mcr.microsoft.com/businesscentral/onprem:14.8.38658.0-gb-ltsc2019'
$licenseFile = 'C:\users\todd.scott\License\BC14License.flf'

$alwaysPull = $true

$userName = 'admin'
$password = 'P@ssword1'

$securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$credential = New-Object PSCredential -ArgumentList $userName, $SecurePassword

$workspaceFolder = (Get-Item (Join-Path $PSScriptRoot "..")).FullName
$additionalParameters = @("--volume ""${workspaceFolder}:C:\Source""") 

New-BCContainer @Parameters `
                    -doNotCheckHealth `
                    -updateHosts `
                    -useBestContainerOS `
                    -containerName $containerName `
                    -imageName $imageName `
                    -alwaysPull:$alwaysPull `
                    -auth "UserPassword" `
                    -Credential $credential `
                    -additionalParameters $additionalParameters `
                    -includeTestToolkit `
                    -includeTestLibrariesOnly `
                    -doNotUseRuntimePackages `
                    -licenseFile $licenseFile `
                    -shortcuts Desktop `
                    -includeCSide `
                    -includeAL

Script to get tests

$userName = 'admin'
$password = 'P@ssword1'

$containerName = 'Test-BC1401'

$securePassword =  ConvertTo-SecureString -String $password -AsPlainText -Force
$credential = New-Object PSCredential -ArgumentList $userName, $SecurePassword

$testSuite = "DEFAULT"

$tests = Get-TestsFromBCContainer `
    -containerName $containerName `
    -credential $credential `
    -ignoreGroups `
    -testSuite $testSuite -debugMode

$tests

Full output of scripts Script output for Create-BCContainer script

NavContainerHelper is version 0.6.5.11
NavContainerHelper is running as administrator
Host is Microsoft Windows 10 Pro - 1909
Docker Client Version is 19.03.8
Docker Server Version is 19.03.8
Pulling image mcr.microsoft.com/businesscentral/onprem:14.8.38658.0-gb-ltsc2019
14.8.38658.0-gb-ltsc2019: Pulling from businesscentral/onprem
Digest: sha256:8ccdec25afe346d91cf55d1bc4af71bad4104e4312fa56924f37b657f267f871
Status: Image is up to date for mcr.microsoft.com/businesscentral/onprem:14.8.38658.0-gb-ltsc2019
mcr.microsoft.com/businesscentral/onprem:14.8.38658.0-gb-ltsc2019
Using image mcr.microsoft.com/businesscentral/onprem:14.8.38658.0-gb-ltsc2019
Disabling Health Check (always report healthy)
Creating Container Test-BC1401
Version: 14.8.38658.0-gb
Style: onprem
Platform: 14.0.38650.0
Generic Tag: 0.0.9.97
Container OS Version: 10.0.17763.914 (ltsc2019)
Host OS Version: 10.0.18363.836 (1909)
A better Generic Container OS exists for your host (mcr.microsoft.com/dynamicsnav:10.0.18363.778-generic)
Using generic image mcr.microsoft.com/dynamicsnav:10.0.18363.778-generic
Pulling image mcr.microsoft.com/dynamicsnav:10.0.18363.778-generic
10.0.18363.778-generic: Pulling from dynamicsnav
Digest: sha256:8c5ec5728bcf2809277b3245985cbf385c61bd24173dca7f2a008cb679d2a326
Generic Container OS Version: 10.0.18363.778 (1909)
Generic Tag of better generic: 0.0.9.100
WARNING: The container operating system matches the host operating system, but the revision is different.
If you encounter issues, you might want to specify -isolation hyperv
Using locale en-GB
Using process isolation
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Using license file C:\users\todd.scott\License\BC14License.flf
Files in C:\ProgramData\NavContainerHelper\Extensions\Test-BC1401\my:
- AdditionalOutput.ps1
- AdditionalSetup.ps1
- license.flf
- MainLoop.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container Test-BC1401 from image mcr.microsoft.com/dynamicsnav:10.0.18363.778-generic
dd75278e2a736748d4f11f01cee0c5029789c44a2e7001f60927b135121bfce9
Waiting for container Test-BC1401 to be ready
Installing Business Central
Installing Url Rewrite
Installing OpenXML
Installing DotNetCore
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
Copying Web Client Files
Copying Windows Client Files
Copying PowerShell Scripts
Copying Test Assemblies
Copying TestToolKit
Copying UpgradeToolKit
Copying Extensions
Copying ClientUserSettings
Copying ReportBuilder
Changing Database Server Collation to Latin1_General_100_CI_AS
SQL Server 2017 transmits information about your installation experience, as well as other usage and performance data, to Microsoft to help improve the product. To learn more about SQL Server 2017 da
ta processing and privacy controls, please see the Privacy Statement.
Copying Cronus database
Modifying Business Central Service Tier Config File for Docker
Creating Business Central Service Tier
Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
Starting Business Central Service Tier
Installation took 260 seconds
Installation complete
Stopping Business Central Service Tier
Initializing...
Setting host.docker.internal to 192.168.1.99 in container hosts file (copy from host hosts file)
Setting gateway.docker.internal to 192.168.1.99 in container hosts file (copy from host hosts file)
Setting kubernetes.docker.internal to 127.0.0.1 in container hosts file (copy from host hosts file)
Setting host.containerhelper.internal to 172.31.176.1 in container hosts file
Starting Container
Hostname is Test-BC1401
PublicDnsName is Test-BC1401
Using NavUserPassword Authentication
Creating Self Signed Certificate
Self Signed Certificate Thumbprint 6F3553FC8EA8EA001ACA2F264B5A01D601D0C7BF
Modifying Service Tier Config File with Instance Specific Settings
Starting Service Tier
Registering event sources
Creating DotNetCore Web Server Instance
Using license file 'c:\run\my\license.flf'
Import License
Creating http download site
Setting SA Password and enabling SA
Creating admin as SQL User and add to sysadmin
Creating SUPER user
Container IP Address: 172.31.179.151
Container Hostname  : Test-BC1401
Container Dns Name  : Test-BC1401
Web Client          : http://Test-BC1401/NAV/
Dev. Server         : http://Test-BC1401
Dev. ServerInstance : NAV
Setting Test-BC1401 to 172.31.179.151 in host hosts file

Files:
http://Test-BC1401:8080/al-3.0.193882.vsix

Initialization took 159 seconds
Ready for connections!
Reading CustomSettings.config from Test-BC1401
Creating Desktop Shortcuts for Test-BC1401
Importing Objects from C:\TestToolKit\CALTestLibraries.GB.fob (container path)
TestToolkit successfully imported
Creating .net Assembly Reference Folder for VS Code
Copying DLLs from C:\Windows\assembly to assemblyProbingPath
Copying DLLs from C:\Program Files\Microsoft Dynamics NAV\140\Service to assemblyProbingPath
Copying DLLs from C:\Program Files (x86)\Microsoft Dynamics NAV\140\RoleTailored Client to assemblyProbingPath
Copying DLLs from C:\Program Files (x86)\Open XML SDK to assemblyProbingPath
Container Test-BC1401 successfully created

Output from Get-Tests script without tests added to DEFAULT Test Suite

Importing Objects from C:\ProgramData\NavContainerHelper\Extensions\Test-BC1401\PsTestTool-6\PSTestToolPage.fob (container path)
Objects successfully imported
Get-Tests, open page 130409
Index:  0, Offset: 0, Count:  2
Row - lineType = 0, run = True, CodeunitId = 0, codeunitName = '', name = ''
Index:  1, Offset: 0, Count:  2
Row - lineType = 0, run = True, CodeunitId = , codeunitName = '', name = ''
Index:  2, Offset: 0, Count:  2
Scroll
Index:  2, Offset: 0, Count:  2
Breaking - rowIndex: 2

Output from Get-Tests script with tests added to DEFAULT Test Suite

Get-Tests, open page 130409
Index:  0, Offset: 0, Count:  3
Row - lineType = 1, run = True, CodeunitId = 50133, codeunitName = '', name = 'HelloWorld Test'
Initialize Codeunit
Add codeunit to tests
Index:  1, Offset: 0, Count:  3
Row - lineType = 2, run = True, CodeunitId = 50133, codeunitName = 'HelloWorld Test', name = 'TestHelloWorldMessage'
Add test TestHelloWorldMessage
Index:  2, Offset: 0, Count:  3
Row - lineType = 0, run = True, CodeunitId = , codeunitName = 'HelloWorld Test', name = ''
Index:  3, Offset: 0, Count:  3
Scroll
Index:  3, Offset: 0, Count:  3
Breaking - rowIndex: 3

Tests                   Name            Id   
-----                   ----            --   
{TestHelloWorldMessage} HelloWorld Test 50133

Screenshots Test is installed and available image

Tests added to DEFAULT Test Suite image

Error in Run-Tests.ps1 from Pipeline image

Additional context

freddydk commented 4 years ago

the error is because it doesn't find and run the tests - so the test results.xml didn't get created. How does the run-tests.ps1 look?

GreatScott000 commented 4 years ago

Run-Tests.ps1 is unchanged from the original. I have extracted out the logic and the Get-TestsInNavContainer does not return any tests unless the DEFAULT Test Suite is populated BEFORE.

I extracted this code from Run-Tests.ps1 (to run in against another container) just to see what was happening and the $tests variable is null UNLESS I add something to DEFAULT Test Suite.

Why does Get-TestInNavContainer not find any tests?

$userName = 'admin'
$password = 'P@ssword1'

$containerName = 'Test-BC1401'

$securePassword =  ConvertTo-SecureString -String $password -AsPlainText -Force
$credential = New-Object PSCredential -ArgumentList $userName, $SecurePassword

$testSuite = "DEFAULT"

$tests = Get-TestsFromBCContainer `
    -containerName $containerName `
    -credential $credential `
    -ignoreGroups `
    -testSuite $testSuite -debugMode

$tests

Output - does not find any tests.

Importing Objects from C:\ProgramData\NavContainerHelper\Extensions\Test-BC1401\PsTestTool-6\PSTestToolPage.fob (container path) Objects successfully imported Get-Tests, open page 130409 Index: 0, Offset: 0, Count: 2 Row - lineType = 0, run = True, CodeunitId = 0, codeunitName = '', name = '' Index: 1, Offset: 0, Count: 2 Row - lineType = 0, run = True, CodeunitId = , codeunitName = '', name = '' Index: 2, Offset: 0, Count: 2 Scroll Index: 2, Offset: 0, Count: 2 Breaking - rowIndex: 2

freddydk commented 4 years ago

in BC14 you need to populate the test suite in code like described here: https://freddysblog.com/2019/04/13/running-tests-in-containers/ else the test suite will be empty. In BC15 and later you can specify an extension id, which will be added automatically.

GreatScott000 commented 4 years ago

Thank you for the information. I was unaware of the BC14 information but thought there must be something different.

This has resolved my issue.