Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Mapping files lost when restarting an Azure app service #173

Closed
craigt00 opened this issue Aug 7, 2018 · 5 comments
Closed

Feature: Mapping files lost when restarting an Azure app service #173

craigt00 opened this issue Aug 7, 2018 · 5 comments
Assignees
Labels

Comments

@craigt00
Copy link

craigt00 commented Aug 7, 2018

I've found that when hosting WireMock.Net in an Azure app service the mappings are lost when the app service restarts. I presume this is due to the resolved location of Directory.GetCurrentDirectory() when running in Azure which may be getting cleaned out during a restart.

If this is the case, could I suggest that the base directory is injected in (via IFluentMockServerSettings?) and, if set, used instead of GetCurrentDirectory()? This can then be specifically set for the example projects which need to control the location of their files such as WireMock.Net.WebApplication.NETCore2.

As an alternative, the files could be stored within Azure File or Blob storage (again, via dependancy injecting in a new class to handle file system activity).

@StefH StefH added the feature label Aug 7, 2018
@StefH StefH self-assigned this Aug 7, 2018
@StefH
Copy link
Collaborator

StefH commented Aug 7, 2018

Good point. The same issue will probably be the case for a docker image.
The best solution would be via dependency injection / new classes to handle file system activity.

Example:

interface IDirectoryHandler
{
  string GetCurrent();

  bool Exists(string path);
}

interface IFileHandler
{
  string ReadAllText(string path);

  void WriteAllText(string text);
}

Or hide more to the user, so only this interface remains:

interface IStaticMappingHandler
{
    /// <summary>
    /// Reads a static mapping by the specified filename.
    /// </summary>
    /// <param name="filename">The mapping filename.</param>
    /// <param name="folder">The optional folder (when not defined, use `__admin/mappings`).</param>
    /// <returns>Mapping as text</returns>
    string Read(string filename, string folder = null);

    /// <summary>
    /// Writes the mapping to specified filename.
    /// </summary>
    /// <param name="text">The text.</param>
    /// <param name="filename">The mapping filename.</param>
    /// <param name="folder">The optional folder (when not defined, use `__admin/mappings`).</param>
    /// <returns>true in case saving was successful, else false.</returns>
    bool Write(string text, string filename, string folder = null);
}

Where by default these classes will handle the local file-system.

@StefH StefH changed the title Mapping files lost when restarting an Azure app service Feature: Mapping files lost when restarting an Azure app service Aug 8, 2018
@StefH
Copy link
Collaborator

StefH commented Aug 13, 2018

@craigt00

I've implemented this change into this branch:
https://github.com/WireMock-Net/WireMock.Net/blob/stef_issue_173_mappingfiles_location/src/WireMock.Net/Handlers/IFileSystemHandler.cs

Can you please review ? If it's good enough, I'll merge to master.

@craigt00
Copy link
Author

That looks great, and will allow me to create a azure-specific implementation. Thanks for working on this @StefH

Is the web application example intended to be Azure-specific? If so then I'll fork and update the web application to implement an AzureFileSystemHandler which places the mapping files alongside the site.

@StefH
Copy link
Collaborator

StefH commented Aug 14, 2018

The web-application can run as standalone, web-IIS or Azure.

So for your idea, maybe best to create a new example project called WireMock.Net.Azure.NETCore2 which implements that AzureFileSystemHandler.

Or update the original example to use a switch in the configuration to choose the FileHandler.

I'll create a PR merge tho master in some time today.

@StefH
Copy link
Collaborator

StefH commented Aug 14, 2018

Linked #180

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants