Williamhe/1546176 project spotlight golang (#1411)

* Add custom logging for golang build

* Add custom logging for golang build test

* Update to redirect STDERR to STDOUT

* Update recommendation message

* Update with comment
This commit is contained in:
william-msft 2022-06-02 21:10:44 -07:00 коммит произвёл GitHub
Родитель 9dbab9750c
Коммит 5c29212719
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 49 добавлений и 3 удалений

Просмотреть файл

@ -25,7 +25,7 @@ function LogErrorWithTryCatch()
# try
set +e
output=$( $cmd )
output=$( $cmd 2>&1) # captures STDERR/STDOUT
exitCode=${PIPESTATUS[0]}
set -e

Просмотреть файл

@ -23,7 +23,12 @@ echo " "
# TODO: add support for nested dirs
echo "building go app..."
go build -o oryxBuildBinary
doc="https://aka.ms/troubleshoot-go"
suggestion="Please check your go.mod is valid.
Try building locally first with the following command: go build"
msg="${suggestion} | ${doc}"
cmd="go build -o oryxBuildBinary"
LogErrorWithTryCatch "$cmd" "$msg"
echo "list of module dependencies"
go list -m

Просмотреть файл

@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using Microsoft.Oryx.BuildScriptGenerator.Common;
using Microsoft.Oryx.BuildScriptGeneratorCli;
using Microsoft.Oryx.Tests.Common;
@ -36,7 +37,7 @@ namespace Microsoft.Oryx.BuildImage.Tests
}
[Fact]
public void GeneratesScript_AndBuildSinatraAppWithDynamicInstall()
public void GeneratesScript_AndBuildGolangAppWithDynamicInstall()
{
var imageTestHelper = new ImageTestHelper();
@ -69,5 +70,45 @@ namespace Microsoft.Oryx.BuildImage.Tests
},
result.GetDebugInfo());
}
[Fact]
public void GeneratesScript_AndBuildGolangAppWithoutGoMod()
{
var imageTestHelper = new ImageTestHelper();
// Arrange
var appName = "hello-world";
var volume = CreateSampleAppVolume(appName);
var appDir = volume.ContainerDir;
var appOutputDir = "/tmp/app-output";
var script = new ShellScriptBuilder()
.AddDefaultTestEnvironmentVariables()
.AddCommand($"echo RandomText > {appDir}/go.mod") // triggers a failure
.AddBuildCommand($"{appDir} -o {appOutputDir}")
.ToString();
// Regex will match:
// "yyyy-mm-dd hh:mm:ss"|ERROR|go: errors parsing go.mod
Regex regex = new Regex(@"""[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (0[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])""\|ERROR\|go:\serrors\sparsing\sgo\.mod.*");
// Act
var result = _dockerCli.Run(new DockerRunArguments
{
ImageId = imageTestHelper.GetLtsVersionsBuildImage(),
EnvironmentVariables = new List<EnvironmentVariable> { CreateAppNameEnvVar(appName) },
Volumes = new List<DockerVolume> { volume },
CommandToExecuteOnRun = "/bin/bash",
CommandArguments = new[] { "-c", script }
});
// Assert
RunAsserts(
() =>
{
Assert.False(result.IsSuccess);
Match match = regex.Match(result.StdOut);
Assert.True(match.Success);
},
result.GetDebugInfo());
}
}
}