https://linen.dev logo
#help
Title
# help
v

Venkatesh Babu

08/16/2023, 6:43 PM
Hi all, I am looking for some help regarding wiremock standalone and running in github using github actions. my github actions file has following steps
Copy code
- name: Download WireMock
  run: |
    wget -O wiremock-standalone.jar <https://repo1.maven.org/maven2/com/github/tomakehurst/wiremock-standalone/2.9.0/wiremock-standalone-2.9.0.jar>

- name: Build project with Maven
  run: mvn clean install -DskipTests

- name: Start WireMock
  id: start-wiremock
  run: java -jar wiremock-standalone.jar --port 8081 --root-dir ${{ github.workspace }}/src/main/resources/mappings --verbose --local-response-templating &
    # Add additional steps for your tests, if needed

- name: Test Simple Endpoint
  run: |
    curl <http://localhost:8081/__admin>
    curl <http://localhost:8081/__admin/mappings>
    curl <http://localhost:8081/simple-endpoint>
  continue-on-error: true
I could see in the github actions log that wiremock instance is starting in port 8081 (image has the log confirmation that my wiremock instance has started) I have the mappings in the directory mentioned
/src/main/resources/mappings
contents of the mapping file in the above mentioned directory: simple-mapping.json
Copy code
{
  "request": {
    "method": "GET",
    "urlPattern": "/simple-endpoint"
  },
  "response": {
    "status": 200,
    "body": "This is a simple response from WireMock"
  }
}
when I try to hit the urls:
Copy code
curl <http://localhost:8081/__admin>
curl <http://localhost:8081/__admin/mappings>
curl <http://localhost:8081/simple-endpoint>
I could see that the admin urls are accessible but the mappings are not set and in the logs, I get 404 not found which is reasonable as the mappings are not set but why is it referring to
/__files/simple-endpoint
Copy code
<html>
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 404 </title>
</head>
<body>
<h2>HTTP ERROR: 404</h2>
<p>Problem accessing /__files/simple-endpoint. Reason:
<pre>    Not Found</pre></p>
<hr /><i><small>Powered by Jetty://</small></i>
</body>
</html>
also let me know how can I fix this issue.
t

Tom

08/16/2023, 7:19 PM
It looks to me like you’re setting the
root-dir
parameter 1 level too deep. Try chopping the
mappings
part of the end.
Also 2.9.0 is truly ancient. I’d definitely recommend updating at least to the latest 2.x version - 2.35.0
v

Venkatesh Babu

08/16/2023, 8:13 PM
Thank you @Tom, it indeed fixed that issue. Now, I see that I have another issue with the request mapping
Copy code
"request": {
  "method": "GET",
  "urlPattern": "/test-in-int/cars?limit=300"
},
"response": {
  "status": 200,
  "headers": {
    "Content-Type": "application/json"
  },
  "body": "{\n   \"limit\":1,\n   \"offset\":0,\n   \"count\":1,\n   \"total\":441,\n   \"results\":[\n      {\n         \"id\":\"e4841772-bb61-4a5d-8715-98c844667a2d\",\n         \"version\":474,\n ........
but when I try to call the mock using the pattern mapped, I get the following error (in image). I do not seem to find answers online except changing urlPattern to urlPathPattern. Do you know what could be the issue with this?
t

Tom

08/16/2023, 8:19 PM
Since your URL is a literal not a regex use
"url"
instead of
"urlPattern"
❤️ 1
v

Venkatesh Babu

08/16/2023, 8:28 PM
Thanks Tom! it works 🙂
2 Views