Browse Source

Fixed issue #620 (#621)

* Fixed issue #620

* Produce a useful error message if the path of a project file is incorrect in tye.yaml.
* Added a test.

* Fixed test on Linux and OSX.

* Check full exception message in test and fixed test name.

* More deterministic behavior considering directory check and test execution.

Moved directory check one level higher from EnsureMSBuildRegistered() to the caller ReadProjectDetailsAsync(). This means that this code is always executed. In EnsureMSBuildRegistered() it was only executed once per proces because of the static field "registered". The placement of the check after evaluation of the the field "registered" was the reason why the test WrongProjectPathProducesCorrectErrorMessage worked when executed alone but not when any other test that called EnsureMSBuildRegistered() was executed before.

With this change the directory check is always executed now, even if the EnsureMSBuildRegistered() was already executed successfully. But the performance impact should not be significant while the type of generated error message is more deterministic and not dependent on execution order.
pull/639/head
Christian Kadluba 6 years ago
committed by GitHub
parent
commit
a4cf135c08
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      src/Microsoft.Tye.Core/ProjectReader.cs
  2. 14
      test/E2ETest/ApplicationFactoryTests.cs
  3. 8
      test/E2ETest/testassets/projects/frontend-backend/tye-wrong-projectpath.yaml

5
src/Microsoft.Tye.Core/ProjectReader.cs

@ -73,6 +73,11 @@ namespace Microsoft.Tye
throw new ArgumentNullException(nameof(project));
}
if (!Directory.Exists(project.ProjectFile.DirectoryName))
{
throw new CommandException($"Failed to locate directory: '{project.ProjectFile.DirectoryName}'.");
}
EnsureMSBuildRegistered(output, project.ProjectFile);
EvaluateProject(output, project);

14
test/E2ETest/ApplicationFactoryTests.cs

@ -107,5 +107,19 @@ services:
Assert.Equal("redis2", ((ContainerServiceBuilder)redisService).Image);
}
[Fact]
public async Task WrongProjectPathProducesCorrectErrorMessage()
{
using var projectDirectory = TestHelpers.CopyTestProjectDirectory("frontend-backend");
var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "tye-wrong-projectpath.yaml"));
var outputContext = new OutputContext(_sink, Verbosity.Debug);
var exception = await Assert.ThrowsAsync<CommandException>(async () =>
await ApplicationFactory.CreateAsync(outputContext, projectFile));
var wrongProjectPath = Path.Combine(projectDirectory.DirectoryPath, "backend1");
Assert.Equal($"Failed to locate directory: '{wrongProjectPath}'.", exception.Message);
}
}
}

8
test/E2ETest/testassets/projects/frontend-backend/tye-wrong-projectpath.yaml

@ -0,0 +1,8 @@
# tye application configuration file
# read all about it at https://github.com/dotnet/tye
name: frontend-backend
services:
- name: backend
project: backend1/backend.csproj
- name: frontend
project: frontend/frontend.csproj
Loading…
Cancel
Save