Skip to content

Commit 8c9b964

Browse files
Merge pull request #26 from grafana/julienduchesne/add-jsonnetfmt-test
Ensure that all files are `jsonnetfmt`ed
2 parents 4a094f7 + ce6f93b commit 8c9b964

24 files changed

+324
-259
lines changed

.github/workflows/jsonnetfmt.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: jsonnetfmt
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request: {}
7+
jobs:
8+
jsonnetfmt:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Format
13+
uses: docker://bitnami/jsonnet:latest
14+
with:
15+
entrypoint: ./scripts/jsonnetfmt.sh
16+
- run: |
17+
STATUS="$(git status --porcelain)"
18+
test -z "${STATUS}" || {
19+
echo "Found changes after formatting. Run jsonnetfmt on the following files:"
20+
echo "${STATUS}"
21+
exit 1
22+
}

pkg/server/definition_test.go

+59-59
Original file line numberDiff line numberDiff line change
@@ -61,53 +61,53 @@ func TestDefinition(t *testing.T) {
6161
{
6262
name: "test goto inner definition",
6363
filename: "./testdata/test_goto_definition_multi_locals.jsonnet",
64-
position: protocol.Position{Line: 6, Character: 11},
64+
position: protocol.Position{Line: 6, Character: 9},
6565
targetRange: protocol.Range{
66-
Start: protocol.Position{Line: 4, Character: 10},
67-
End: protocol.Position{Line: 4, Character: 28},
66+
Start: protocol.Position{Line: 4, Character: 8},
67+
End: protocol.Position{Line: 4, Character: 26},
6868
},
6969
targetSelectionRange: protocol.Range{
70-
Start: protocol.Position{Line: 4, Character: 10},
71-
End: protocol.Position{Line: 4, Character: 18},
70+
Start: protocol.Position{Line: 4, Character: 8},
71+
End: protocol.Position{Line: 4, Character: 16},
7272
},
7373
},
7474
{
7575
name: "test goto super index",
7676
filename: "./testdata/test_combined_object.jsonnet",
77-
position: protocol.Position{Line: 5, Character: 13},
77+
position: protocol.Position{Line: 5, Character: 11},
7878
targetRange: protocol.Range{
79-
Start: protocol.Position{Line: 1, Character: 4},
80-
End: protocol.Position{Line: 3, Character: 5},
79+
Start: protocol.Position{Line: 1, Character: 2},
80+
End: protocol.Position{Line: 3, Character: 3},
8181
},
8282
targetSelectionRange: protocol.Range{
83-
Start: protocol.Position{Line: 1, Character: 4},
84-
End: protocol.Position{Line: 1, Character: 5},
83+
Start: protocol.Position{Line: 1, Character: 2},
84+
End: protocol.Position{Line: 1, Character: 3},
8585
},
8686
},
8787
{
8888
name: "test goto super nested",
8989
filename: "./testdata/test_combined_object.jsonnet",
90-
position: protocol.Position{Line: 5, Character: 15},
90+
position: protocol.Position{Line: 5, Character: 13},
9191
targetRange: protocol.Range{
92-
Start: protocol.Position{Line: 2, Character: 8},
93-
End: protocol.Position{Line: 2, Character: 22},
92+
Start: protocol.Position{Line: 2, Character: 4},
93+
End: protocol.Position{Line: 2, Character: 18},
9494
},
9595
targetSelectionRange: protocol.Range{
96-
Start: protocol.Position{Line: 2, Character: 8},
97-
End: protocol.Position{Line: 2, Character: 9},
96+
Start: protocol.Position{Line: 2, Character: 4},
97+
End: protocol.Position{Line: 2, Character: 5},
9898
},
9999
},
100100
{
101101
name: "test goto self object field function",
102102
filename: "./testdata/test_basic_lib.libsonnet",
103-
position: protocol.Position{Line: 4, Character: 19},
103+
position: protocol.Position{Line: 4, Character: 17},
104104
targetRange: protocol.Range{
105-
Start: protocol.Position{Line: 1, Character: 4},
106-
End: protocol.Position{Line: 3, Character: 20},
105+
Start: protocol.Position{Line: 1, Character: 2},
106+
End: protocol.Position{Line: 3, Character: 16},
107107
},
108108
targetSelectionRange: protocol.Range{
109-
Start: protocol.Position{Line: 1, Character: 4},
110-
End: protocol.Position{Line: 1, Character: 9},
109+
Start: protocol.Position{Line: 1, Character: 2},
110+
End: protocol.Position{Line: 1, Character: 7},
111111
},
112112
},
113113
{
@@ -152,27 +152,27 @@ func TestDefinition(t *testing.T) {
152152
{
153153
name: "test goto local obj field from 'self.attr' from other obj",
154154
filename: "./testdata/goto-indexes.jsonnet",
155-
position: protocol.Position{Line: 9, Character: 18},
155+
position: protocol.Position{Line: 9, Character: 16},
156156
targetRange: protocol.Range{
157-
Start: protocol.Position{Line: 2, Character: 8},
158-
End: protocol.Position{Line: 2, Character: 23},
157+
Start: protocol.Position{Line: 2, Character: 4},
158+
End: protocol.Position{Line: 2, Character: 19},
159159
},
160160
targetSelectionRange: protocol.Range{
161-
Start: protocol.Position{Line: 2, Character: 8},
162-
End: protocol.Position{Line: 2, Character: 11},
161+
Start: protocol.Position{Line: 2, Character: 4},
162+
End: protocol.Position{Line: 2, Character: 7},
163163
},
164164
},
165165
{
166166
name: "test goto local object 'obj' via obj index 'obj.foo'",
167167
filename: "./testdata/goto-indexes.jsonnet",
168-
position: protocol.Position{Line: 8, Character: 15},
168+
position: protocol.Position{Line: 8, Character: 13},
169169
targetRange: protocol.Range{
170-
Start: protocol.Position{Line: 1, Character: 4},
171-
End: protocol.Position{Line: 3, Character: 5},
170+
Start: protocol.Position{Line: 1, Character: 2},
171+
End: protocol.Position{Line: 3, Character: 3},
172172
},
173173
targetSelectionRange: protocol.Range{
174-
Start: protocol.Position{Line: 1, Character: 4},
175-
End: protocol.Position{Line: 1, Character: 7},
174+
Start: protocol.Position{Line: 1, Character: 2},
175+
End: protocol.Position{Line: 1, Character: 5},
176176
},
177177
},
178178
{
@@ -192,29 +192,29 @@ func TestDefinition(t *testing.T) {
192192
{
193193
name: "test goto imported file at lhs index",
194194
filename: "./testdata/goto-imported-file.jsonnet",
195-
position: protocol.Position{Line: 3, Character: 18},
195+
position: protocol.Position{Line: 3, Character: 16},
196196
targetFilename: "testdata/goto-basic-object.jsonnet",
197197
targetRange: protocol.Range{
198-
Start: protocol.Position{Line: 3, Character: 4},
199-
End: protocol.Position{Line: 3, Character: 14},
198+
Start: protocol.Position{Line: 3, Character: 2},
199+
End: protocol.Position{Line: 3, Character: 12},
200200
},
201201
targetSelectionRange: protocol.Range{
202-
Start: protocol.Position{Line: 3, Character: 4},
203-
End: protocol.Position{Line: 3, Character: 7},
202+
Start: protocol.Position{Line: 3, Character: 2},
203+
End: protocol.Position{Line: 3, Character: 5},
204204
},
205205
},
206206
{
207207
name: "test goto imported file at rhs index",
208208
filename: "./testdata/goto-imported-file.jsonnet",
209-
position: protocol.Position{Line: 4, Character: 18},
209+
position: protocol.Position{Line: 4, Character: 16},
210210
targetFilename: "testdata/goto-basic-object.jsonnet",
211211
targetRange: protocol.Range{
212-
Start: protocol.Position{Line: 5, Character: 4},
213-
End: protocol.Position{Line: 5, Character: 14},
212+
Start: protocol.Position{Line: 5, Character: 2},
213+
End: protocol.Position{Line: 5, Character: 12},
214214
},
215215
targetSelectionRange: protocol.Range{
216-
Start: protocol.Position{Line: 5, Character: 4},
217-
End: protocol.Position{Line: 5, Character: 7},
216+
Start: protocol.Position{Line: 5, Character: 2},
217+
End: protocol.Position{Line: 5, Character: 5},
218218
},
219219
},
220220
{
@@ -223,26 +223,26 @@ func TestDefinition(t *testing.T) {
223223
position: protocol.Position{Line: 0, Character: 48},
224224
targetFilename: "testdata/goto-basic-object.jsonnet",
225225
targetRange: protocol.Range{
226-
Start: protocol.Position{Line: 5, Character: 4},
227-
End: protocol.Position{Line: 5, Character: 14},
226+
Start: protocol.Position{Line: 5, Character: 2},
227+
End: protocol.Position{Line: 5, Character: 12},
228228
},
229229
targetSelectionRange: protocol.Range{
230-
Start: protocol.Position{Line: 5, Character: 4},
231-
End: protocol.Position{Line: 5, Character: 7},
230+
Start: protocol.Position{Line: 5, Character: 2},
231+
End: protocol.Position{Line: 5, Character: 5},
232232
},
233233
},
234234
{
235235
name: "goto attribute of nested import",
236236
filename: "testdata/goto-nested-imported-file.jsonnet",
237-
position: protocol.Position{Line: 2, Character: 15},
237+
position: protocol.Position{Line: 2, Character: 13},
238238
targetFilename: "testdata/goto-basic-object.jsonnet",
239239
targetRange: protocol.Range{
240-
Start: protocol.Position{Line: 3, Character: 4},
241-
End: protocol.Position{Line: 3, Character: 14},
240+
Start: protocol.Position{Line: 3, Character: 2},
241+
End: protocol.Position{Line: 3, Character: 12},
242242
},
243243
targetSelectionRange: protocol.Range{
244-
Start: protocol.Position{Line: 3, Character: 4},
245-
End: protocol.Position{Line: 3, Character: 7},
244+
Start: protocol.Position{Line: 3, Character: 2},
245+
End: protocol.Position{Line: 3, Character: 5},
246246
},
247247
},
248248
{
@@ -287,29 +287,29 @@ func TestDefinition(t *testing.T) {
287287
{
288288
name: "goto attribute of nested import no object intermediary",
289289
filename: "testdata/goto-nested-import-file-no-inter-obj.jsonnet",
290-
position: protocol.Position{Line: 2, Character: 15},
290+
position: protocol.Position{Line: 2, Character: 13},
291291
targetFilename: "testdata/goto-basic-object.jsonnet",
292292
targetRange: protocol.Range{
293-
Start: protocol.Position{Line: 3, Character: 4},
294-
End: protocol.Position{Line: 3, Character: 14},
293+
Start: protocol.Position{Line: 3, Character: 2},
294+
End: protocol.Position{Line: 3, Character: 12},
295295
},
296296
targetSelectionRange: protocol.Range{
297-
Start: protocol.Position{Line: 3, Character: 4},
298-
End: protocol.Position{Line: 3, Character: 7},
297+
Start: protocol.Position{Line: 3, Character: 2},
298+
End: protocol.Position{Line: 3, Character: 5},
299299
},
300300
},
301301
{
302302
name: "goto self in import in binary",
303303
filename: "testdata/goto-self-within-binary.jsonnet",
304-
position: protocol.Position{Line: 4, Character: 15},
304+
position: protocol.Position{Line: 4, Character: 13},
305305
targetFilename: "testdata/goto-basic-object.jsonnet",
306306
targetRange: protocol.Range{
307-
Start: protocol.Position{Line: 3, Character: 4},
308-
End: protocol.Position{Line: 3, Character: 14},
307+
Start: protocol.Position{Line: 3, Character: 2},
308+
End: protocol.Position{Line: 3, Character: 12},
309309
},
310310
targetSelectionRange: protocol.Range{
311-
Start: protocol.Position{Line: 3, Character: 4},
312-
End: protocol.Position{Line: 3, Character: 7},
311+
Start: protocol.Position{Line: 3, Character: 2},
312+
End: protocol.Position{Line: 3, Character: 5},
313313
},
314314
},
315315
{
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
local somevar = "hello";
1+
local somevar = 'hello';
22

33
{
4-
foo: "bar"
4+
foo: 'bar',
55
} + {
6-
bar: "foo"
7-
}
6+
bar: 'foo',
7+
}
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// This is a comment
22
{
3-
foo: "bar"
4-
}
3+
foo: 'bar',
4+
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
local foo = (import "goto-basic-object.jsonnet").bar;
2-
{}
1+
local foo = (import 'goto-basic-object.jsonnet').bar;
2+
{}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
otherFile: (import 'goto-basic-object.jsonnet')
3-
}
2+
otherFile: (import 'goto-basic-object.jsonnet'),
3+
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
(import 'goto-basic-object.jsonnet')
1+
(import 'goto-basic-object.jsonnet')
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
local otherfile = import "goto-basic-object.jsonnet";
1+
local otherfile = import 'goto-basic-object.jsonnet';
22

33
{
4-
a: otherfile.foo,
5-
b: otherfile.bar
4+
a: otherfile.foo,
5+
b: otherfile.bar,
66
}
+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
local obj = {
2-
foo: {
3-
bar: "innerfoo"
4-
},
5-
bar: "foo"
2+
foo: {
3+
bar: 'innerfoo',
4+
},
5+
bar: 'foo',
66
};
77

88
{
9-
attr: obj.foo,
10-
s: self.attr.bar
9+
attr: obj.foo,
10+
s: self.attr.bar,
1111
}
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
local util(k) = {
22
serviceFor(deployment, ignored_labels=[], nameFormat='%(container)s-%(port)s')::
3-
local container = k.core.v1.container;
4-
local service = k.core.v1.service;
5-
local servicePort = k.core.v1.servicePort;
6-
local ports = [
7-
servicePort.newNamed(
8-
name=(nameFormat % { container: c.name, port: port.name }),
9-
port=port.containerPort,
10-
targetPort=port.containerPort
11-
) +
12-
if std.objectHas(port, 'protocol')
13-
then servicePort.withProtocol(port.protocol)
14-
else {}
15-
for c in deployment.spec.template.spec.containers
16-
for port in (c + container.withPortsMixin([])).ports
17-
];
18-
local labels = {
19-
[x]: deployment.spec.template.metadata.labels[x]
20-
for x in std.objectFields(deployment.spec.template.metadata.labels)
21-
if std.count(ignored_labels, x) == 0
22-
};
23-
24-
service.new(
25-
deployment.metadata.name, // name
26-
labels, // selector
27-
ports,
3+
local container = k.core.v1.container;
4+
local service = k.core.v1.service;
5+
local servicePort = k.core.v1.servicePort;
6+
local ports = [
7+
servicePort.newNamed(
8+
name=(nameFormat % { container: c.name, port: port.name }),
9+
port=port.containerPort,
10+
targetPort=port.containerPort
2811
) +
29-
service.mixin.metadata.withLabels({ name: deployment.metadata.name }),
12+
if std.objectHas(port, 'protocol')
13+
then servicePort.withProtocol(port.protocol)
14+
else {}
15+
for c in deployment.spec.template.spec.containers
16+
for port in (c + container.withPortsMixin([])).ports
17+
];
18+
local labels = {
19+
[x]: deployment.spec.template.metadata.labels[x]
20+
for x in std.objectFields(deployment.spec.template.metadata.labels)
21+
if std.count(ignored_labels, x) == 0
22+
};
23+
24+
service.new(
25+
deployment.metadata.name, // name
26+
labels, // selector
27+
ports,
28+
) +
29+
service.mixin.metadata.withLabels({ name: deployment.metadata.name }),
3030
antiAffinity:
31-
{
32-
local deployment = k.apps.v1.deployment,
33-
local podAntiAffinity = deployment.mixin.spec.template.spec.affinity.podAntiAffinity,
34-
local name = super.spec.template.metadata.labels.name,
31+
{
32+
local deployment = k.apps.v1.deployment,
33+
local podAntiAffinity = deployment.mixin.spec.template.spec.affinity.podAntiAffinity,
34+
local name = super.spec.template.metadata.labels.name,
3535

36-
spec+: podAntiAffinity.withRequiredDuringSchedulingIgnoredDuringExecution([
37-
podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecutionType.new() +
38-
podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecutionType.mixin.labelSelector.withMatchLabels({ name: name }) +
39-
podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecutionType.withTopologyKey('kubernetes.io/hostname'),
40-
]).spec,
41-
},
36+
spec+: podAntiAffinity.withRequiredDuringSchedulingIgnoredDuringExecution([
37+
podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecutionType.new() +
38+
podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecutionType.mixin.labelSelector.withMatchLabels({ name: name }) +
39+
podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecutionType.withTopologyKey('kubernetes.io/hostname'),
40+
]).spec,
41+
},
4242
};
43-
{}
43+
{}

0 commit comments

Comments
 (0)