Skip to content

Commit 2521f96

Browse files
committed
format
1 parent c033881 commit 2521f96

File tree

4 files changed

+42
-60
lines changed

4 files changed

+42
-60
lines changed

src/expression.spec.ts

+29-45
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,83 @@
1-
import { Expression } from "./expression";
2-
import { LabelSelector, LabelsWithValues, MatchingOperator } from "./types";
1+
import { Expression } from './expression';
2+
import { LabelSelector, LabelsWithValues, MatchingOperator } from './types';
33

4-
describe("Expression", () => {
4+
describe('Expression', () => {
55
it.each([
66
{
7-
metric: "",
7+
metric: '',
88
values: {},
99
defaultOperator: MatchingOperator.equal,
1010
defaultSelectors: [],
1111
additionalSelectors: [],
12-
expected: "{}",
12+
expected: '{}',
1313
},
1414
{
15-
metric: "test_metric",
15+
metric: 'test_metric',
1616
values: {},
1717
defaultOperator: MatchingOperator.equal,
1818
defaultSelectors: [],
1919
additionalSelectors: [],
20-
expected: "test_metric{}",
20+
expected: 'test_metric{}',
2121
},
2222
{
23-
metric: "test_metric",
24-
values: { cluster: "test/cluster" },
23+
metric: 'test_metric',
24+
values: { cluster: 'test/cluster' },
2525
defaultOperator: MatchingOperator.equal,
2626
expected: 'test_metric{cluster="test/cluster"}',
2727
},
2828
{
29-
metric: "test_metric",
30-
values: { cluster: "test/cluster" },
29+
metric: 'test_metric',
30+
values: { cluster: 'test/cluster' },
3131
defaultOperator: MatchingOperator.notEqual,
3232
expected: 'test_metric{cluster!="test/cluster"}',
3333
},
3434
{
35-
metric: "test_metric",
36-
values: { cluster: "test/cluster" },
35+
metric: 'test_metric',
36+
values: { cluster: 'test/cluster' },
3737
defaultOperator: MatchingOperator.regexMatch,
3838
expected: 'test_metric{cluster=~"test/cluster"}',
3939
},
4040
{
41-
metric: "test_metric",
42-
values: { cluster: "test/cluster" },
41+
metric: 'test_metric',
42+
values: { cluster: 'test/cluster' },
4343
defaultOperator: MatchingOperator.notRegexMatch,
4444
expected: 'test_metric{cluster!~"test/cluster"}',
4545
},
4646
{
47-
metric: "test_metric",
47+
metric: 'test_metric',
4848
values: {},
4949
defaultOperator: MatchingOperator.equal,
50-
defaultSelectors: [
51-
{ operator: MatchingOperator.notEqual, label: "container", value: "" },
52-
],
50+
defaultSelectors: [{ operator: MatchingOperator.notEqual, label: 'container', value: '' }],
5351
additionalSelectors: [],
5452
expected: 'test_metric{container!=""}',
5553
},
5654
{
57-
metric: "test_metric",
58-
values: { cluster: "test/cluster" },
55+
metric: 'test_metric',
56+
values: { cluster: 'test/cluster' },
5957
defaultOperator: MatchingOperator.equal,
60-
defaultSelectors: [
61-
{ operator: MatchingOperator.notEqual, label: "container", value: "" },
62-
],
58+
defaultSelectors: [{ operator: MatchingOperator.notEqual, label: 'container', value: '' }],
6359
additionalSelectors: [],
6460
expected: 'test_metric{container!="", cluster="test/cluster"}',
6561
},
6662
{
67-
metric: "test_metric",
68-
values: { cluster: "test/cluster", container: undefined },
63+
metric: 'test_metric',
64+
values: { cluster: 'test/cluster', container: undefined },
6965
defaultOperator: MatchingOperator.equal,
70-
defaultSelectors: [
71-
{ operator: MatchingOperator.notEqual, label: "container", value: "" },
72-
],
66+
defaultSelectors: [{ operator: MatchingOperator.notEqual, label: 'container', value: '' }],
7367
additionalSelectors: [],
7468
expected: 'test_metric{container!="", cluster="test/cluster"}',
7569
},
7670
{
77-
metric: "test_metric",
78-
values: { cluster: "test/cluster", container: "test-container" },
71+
metric: 'test_metric',
72+
values: { cluster: 'test/cluster', container: 'test-container' },
7973
defaultOperator: MatchingOperator.equal,
80-
defaultSelectors: [
81-
{ operator: MatchingOperator.notEqual, label: "container", value: "" },
82-
],
74+
defaultSelectors: [{ operator: MatchingOperator.notEqual, label: 'container', value: '' }],
8375
additionalSelectors: [],
84-
expected:
85-
'test_metric{container="test-container", cluster="test/cluster"}',
76+
expected: 'test_metric{container="test-container", cluster="test/cluster"}',
8677
},
8778
])(
88-
"Generate PromQL query: $expected",
89-
({
90-
metric,
91-
values,
92-
defaultOperator,
93-
defaultSelectors,
94-
additionalSelectors,
95-
expected,
96-
}) => {
79+
'Generate PromQL query: $expected',
80+
({ metric, values, defaultOperator, defaultSelectors, additionalSelectors, expected }) => {
9781
const expr = new Expression({
9882
metric,
9983
values: values as LabelsWithValues,

src/expression.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LabelSelector, LabelsWithValues, MatchingOperator } from "./types";
1+
import { LabelSelector, LabelsWithValues, MatchingOperator } from './types';
22

33
export class Expression {
44
metric: string;
@@ -35,10 +35,8 @@ export class Expression {
3535

3636
toString(): string {
3737
const selectors = Array.from(this.selectors)
38-
.map(
39-
([label, selector]) => `${label}${selector.operator}"${selector.value}"`
40-
)
41-
.join(", ");
38+
.map(([label, selector]) => `${label}${selector.operator}"${selector.value}"`)
39+
.join(', ');
4240
return `${this.metric}{${selectors}}`;
4341
}
4442
}

src/test/rate.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { promql } from "../promql";
1+
import { promql } from '../promql';
22

33
// https://prometheus.io/docs/prometheus/latest/querying/functions/#rate
4-
describe("Functions: rate", () => {
4+
describe('Functions: rate', () => {
55
it.each([
66
{
7-
actual: () => promql.rate(""),
8-
expected: "rate([$__rate_interval])",
7+
actual: () => promql.rate(''),
8+
expected: 'rate([$__rate_interval])',
99
},
1010
{
11-
actual: () => promql.rate('foo{bar="baz"}', "5m"),
11+
actual: () => promql.rate('foo{bar="baz"}', '5m'),
1212
expected: 'rate(foo{bar="baz"}[5m])',
1313
},
14-
])("Generate PromQL rate qyert: $expected", ({ actual, expected }) => {
14+
])('Generate PromQL rate qyert: $expected', ({ actual, expected }) => {
1515
expect(actual()).toStrictEqual(expected);
1616
});
1717
});

src/types.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export enum MatchingOperator {
2-
equal = "=",
3-
notEqual = "!=",
4-
regexMatch = "=~",
5-
notRegexMatch = "!~",
2+
equal = '=',
3+
notEqual = '!=',
4+
regexMatch = '=~',
5+
notRegexMatch = '!~',
66
}
77

88
export type LabelSelector = {

0 commit comments

Comments
 (0)