Skip to content

Commit

Permalink
[INTERNAL] Add test for URL rendering #536
Browse files Browse the repository at this point in the history
  • Loading branch information
kfdm authored Jul 29, 2024
2 parents 4f9e58d + 650c552 commit 968d142
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
10 changes: 10 additions & 0 deletions promgen/fixtures/testcases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,13 @@
job: node
port: 9100
enabled: false
- model: promgen.probe
pk: 1
fields:
module: fixture_test
- model: promgen.url
pk: 1
fields:
project: 1
probe: 1
url: probe.example.com
7 changes: 7 additions & 0 deletions promgen/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ def targets(self, request):
content_type="application/json",
)

@action(detail=False, methods=["get"], renderer_classes=[renderers.renderers.JSONRenderer])
def urls(self, request):
return HttpResponse(
prometheus.render_urls(),
content_type="application/json",
)


class ShardViewSet(viewsets.ModelViewSet):
queryset = models.Shard.objects.all()
Expand Down
2 changes: 1 addition & 1 deletion promgen/templates/promgen/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<li><a href="{% url 'api:api-root' %}">API</a></li>
<li><a href="{% url 'api:all-targets' %}">Export Targets</a></li>
<li><a href="{% url 'api:all-rules' %}">Export Rules</a></li>
<li><a href="{% url 'config-urls' %}">Export URL</a></li>
<li><a href="{% url 'api:all-urls' %}">Export URLs</a></li>
</ul>
</li>
{% include 'promgen/help_menu.inc.html' %}
Expand Down
12 changes: 12 additions & 0 deletions promgen/tests/examples/export.urls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"labels": {
"__param_module": "fixture_test",
"__shard": "test-shard",
"job": "fixture_test",
"project": "test-project",
"service": "test-service"
},
"targets": ["probe.example.com"]
}
]
6 changes: 6 additions & 0 deletions promgen/tests/test_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ def test_global_targets(self):
response = self.client.get(reverse("api:all-targets"))
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), expected)

def test_global_urls(self):
expected = tests.Data("examples", "export.urls.json").json()
response = self.client.get(reverse("api:all-urls"))
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), expected)

0 comments on commit 968d142

Please sign in to comment.