question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[0.14.0] Working directory doesn't seem to be relative to workspace directory

See original GitHub issue

Description of the bug

The working directory of the hoverfly instance seems to be located in the temproary folder instead of the workspace/project directory. And since hoverfly requires relative paths this makes it almost impossible to reliably specify your response files let alone specify them in a way that is not machine dependent.

Instead the working directory should in the default path (src/test/resources/hoverfly) or where the simulation file is so relative paths can be used easily

Steps to reproduce the issue

Start a simulation from a simulation file. Specify a path relative to the default path or the simulation JSON.

Example gist: https://gist.github.com/BrainStone/14b5facb30a17e3d0c658d12ba49796d

Observed result

Hoverfly errors out:

[02:05:12.589][Test worker][WARN ][i.s.h.junit.api.HoverflyClient]: Failed to set simulation: Unexpected response (code=500, message={"error":"An error occurred: open test.json: The system cannot find the path specified."}{"data":{"pairs":[],"globalActions":{"delays":[],"delaysLogNormal":[]}},"meta":{"schemaVersion":"v5.1","hoverflyVersion":"v1.3.1","timeExported":"2020-11-29T02:05:12+01:00"}}
)

Expected result

The simulation just working fine and being able to find the files.

Additional relevant information

  • Hoverfly Java version: 0.13.2-SNAPSHOT - 0.14.0
  • OS: Windows 10

Only way I was able to get it working was using a pseudo absolut path. So just a bunch of ../../../.. until you eventually reach the root dir, then specify the path like you would with an absolute path, excluding the drive specification on Windows (needs to be on the same drive)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
BrainStonecommented, Dec 4, 2020

That worked great!

Looking forward to having that being done automatically.

For people that might stumble across this in the future, here is my code:

public class TestApi {
  private static final String simulationFile = "simulation.json";

  @ClassRule
  public static final HoverflyRule hoverflyRule =
      HoverflyRule.inSimulationMode(
          SimulationSource.defaultPath(simulationFile),
          HoverflyConfig.localConfigs()
              .addCommands(
                  "-response-body-files-path",
                  getPathOfResource(simulationFile).getParent().toAbsolutePath().toString()));

  private static URL findResourceOnClasspath(String resourceName) {
    final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    return Optional.ofNullable(classLoader.getResource(resourceName))
        .orElseThrow(
            () -> new IllegalArgumentException("Resource not found with name: " + resourceName));
  }

  @SneakyThrows(URISyntaxException.class)
  private static Path getPathOfResource(String resource) {
    return Paths.get(
        findResourceOnClasspath(HoverflyConstants.DEFAULT_HOVERFLY_RESOURCE_DIR + '/' + resource)
            .toURI());
  }
}

(@SneakyThrows is from lombok. If you don’t have that, just catch the exception and rethrow it wrapped in a RuntimeException)

1reaction
BrainStonecommented, Dec 3, 2020

Ok. Will give that a shot. Thanks very much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · SpectoLabs/hoverfly-java - GitHub
[0.14.0] Working directory doesn't seem to be relative to workspace directory enhancement. #247 opened on Nov 28, 2020 by BrainStone.
Read more >
Setting working directory in PyCham doesn't seem to work
I've set the working directory in my run configuration to project-root/api/src , but the relative paths to resources don't resolve properly.
Read more >
[Notebook] ScreenPad Plus with ScreenXpert 2 - Introduction
1.4 Enter in the new window: ⑨[ .\install.bat], and then press the Enter key on the keyboard. Back to directory. 2. App ...
Read more >
Changelog — conan 1.4.5 documentation
The command conan install doesn't accept cwd anymore, to change the directory where the generator files are written, use the --install-folder parameter.
Read more >
1.1.7 (core) / 0.17.7 (libraries) - Dagster Docs
[dagster-airbyte] A list of connection directories can now be specified in ... [dagit] Fixed the Job page to change the latest run tag...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found