Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Fix prettier issues in test files #1710

Merged
merged 2 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/datasource/specs/dbConnector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const getAllMock = jest.fn().mockReturnValue([{ id: 42, name: 'foo', meta: {} }]
jest.mock('@grafana/runtime', () => ({
getDataSourceSrv: () => ({
get: loadDatasourceMock,
getList: getAllMock
getList: getAllMock,
}),
}));

Expand All @@ -17,7 +17,7 @@ describe('DBConnector', () => {
beforeEach(() => {
ctx.options = {
datasourceId: 42,
datasourceName: undefined
datasourceName: undefined,
};

loadDatasourceMock.mockClear();
Expand Down
48 changes: 39 additions & 9 deletions src/datasource/specs/timeseries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@
import ts from '../timeseries';

describe('timeseries processing functions', () => {

describe('sumSeries()', () => {
it('should properly sum series', (done) => {
let series = [
[[0, 1], [1, 2], [1, 3]],
[[2, 1], [3, 2], [4, 3]]
[
[0, 1],
[1, 2],
[1, 3],
],
[
[2, 1],
[3, 2],
[4, 3],
],
];

let expected = [[2, 1], [4, 2], [5, 3]];
let expected = [
[2, 1],
[4, 2],
[5, 3],
];

let result = ts.sumSeries(series);
expect(result).toEqual(expected);
Expand All @@ -20,21 +31,40 @@ describe('timeseries processing functions', () => {
it('should properly sum series with nulls', (done) => {
// issue #286
let series = [
[[1, 1], [1, 2], [1, 3]],
[[3, 2], [4, 3]]
[
[1, 1],
[1, 2],
[1, 3],
],
[
[3, 2],
[4, 3],
],
];

let expected = [[1, 1], [4, 2], [5, 3]];
let expected = [
[1, 1],
[4, 2],
[5, 3],
];

let result = ts.sumSeries(series);
expect(result).toEqual(expected);
done();
});

it('should properly offset metric', (done) => {
let points = [[1, 1], [-4, 2], [2, 3]];
let points = [
[1, 1],
[-4, 2],
[2, 3],
];

let expected = [[101, 1], [96, 2], [102, 3]];
let expected = [
[101, 1],
[96, 2],
[102, 3],
];

let result = ts.offset(points, 100);
expect(result).toEqual(expected);
Expand Down
79 changes: 44 additions & 35 deletions src/datasource/specs/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,27 @@ import _ from 'lodash';
import * as utils from '../utils';

describe('Utils', () => {

describe('expandItemName()', () => {

it('should properly expand unquoted params', (done) => {
let test_cases = [
{
name: `CPU $2 time`,
key: `system.cpu.util[,user,avg1]`,
expected: "CPU user time"
expected: 'CPU user time',
},
{
name: `CPU $2 time - $3`,
key: `system.cpu.util[,system,avg1]`,
expected: "CPU system time - avg1"
expected: 'CPU system time - avg1',
},
{
name: `CPU - $1 - $2 - $3`,
key: `system.cpu.util[,system,avg1]`,
expected: "CPU - - system - avg1"
}
expected: 'CPU - - system - avg1',
},
];

_.each(test_cases, test_case => {
_.each(test_cases, (test_case) => {
let expandedName = utils.expandItemName(test_case.name, test_case.key);
expect(expandedName).toBe(test_case.expected);
});
Expand All @@ -36,26 +34,26 @@ describe('Utils', () => {
{
name: `CPU $2 time`,
key: `system.cpu.util["type=user,value=avg",user]`,
expected: "CPU user time"
expected: 'CPU user time',
},
{
name: `CPU $1 time`,
key: `system.cpu.util["type=user,value=avg","user"]`,
expected: "CPU type=user,value=avg time"
expected: 'CPU type=user,value=avg time',
},
{
name: `CPU $1 time $3`,
key: `system.cpu.util["type=user,value=avg",,"user"]`,
expected: "CPU type=user,value=avg time user"
expected: 'CPU type=user,value=avg time user',
},
{
name: `CPU $1 $2 $3`,
key: `system.cpu.util["type=user,value=avg",time,"user"]`,
expected: "CPU type=user,value=avg time user"
}
expected: 'CPU type=user,value=avg time user',
},
];

_.each(test_cases, test_case => {
_.each(test_cases, (test_case) => {
let expandedName = utils.expandItemName(test_case.name, test_case.key);
expect(expandedName).toBe(test_case.expected);
});
Expand All @@ -67,21 +65,21 @@ describe('Utils', () => {
{
name: `CPU $2 - $3 time`,
key: `system.cpu.util[,[user,system],avg1]`,
expected: "CPU user,system - avg1 time"
expected: 'CPU user,system - avg1 time',
},
{
name: `CPU $2 - $3 time`,
key: `system.cpu.util[,["user,system",iowait],avg1]`,
expected: `CPU "user,system",iowait - avg1 time`
expected: `CPU "user,system",iowait - avg1 time`,
},
{
name: `CPU - $2 - $3 - $4`,
key: `system.cpu.util[,[],["user,system",iowait],avg1]`,
expected: `CPU - - "user,system",iowait - avg1`
}
expected: `CPU - - "user,system",iowait - avg1`,
},
];

_.each(test_cases, test_case => {
_.each(test_cases, (test_case) => {
let expandedName = utils.expandItemName(test_case.name, test_case.key);
expect(expandedName).toBe(test_case.expected);
});
Expand All @@ -90,21 +88,20 @@ describe('Utils', () => {
});

describe('splitTemplateQuery()', () => {

// Backward compatibility
it('should properly split query in old format', (done) => {
let test_cases = [
{
query: `/alu/./tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9{2}/`,
expected: ['/alu/', '/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9{2}/']
expected: ['/alu/', '/tw-(nyc|que|brx|dwt|brk)-sta_(w|d)*-alu-[0-9{2}/'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\w\d got turned into wd. i think this is a correct prettier-transform, but the original text looks very regex-ish... maybe the "before" situation was already wrong?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right the query to escape w properly needs double backslash.

},
{
query: `a.b.c.d`,
expected: ['a', 'b', 'c', 'd']
}
expected: ['a', 'b', 'c', 'd'],
},
];

_.each(test_cases, test_case => {
_.each(test_cases, (test_case) => {
let splitQuery = utils.splitTemplateQuery(test_case.query);
expect(splitQuery).toEqual(test_case.expected);
});
Expand All @@ -115,23 +112,23 @@ describe('Utils', () => {
let test_cases = [
{
query: `{alu}{/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]*/}`,
expected: ['alu', '/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]*/']
expected: ['alu', '/tw-(nyc|que|brx|dwt|brk)-sta_(w|d)*-alu-[0-9]*/'],
},
{
query: `{alu}{/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]{2}/}`,
expected: ['alu', '/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]{2}/']
expected: ['alu', '/tw-(nyc|que|brx|dwt|brk)-sta_(w|d)*-alu-[0-9]{2}/'],
},
{
query: `{a}{b}{c}{d}`,
expected: ['a', 'b', 'c', 'd']
expected: ['a', 'b', 'c', 'd'],
},
{
query: `{a}{b.c.d}`,
expected: ['a', 'b.c.d']
}
expected: ['a', 'b.c.d'],
},
];

_.each(test_cases, test_case => {
_.each(test_cases, (test_case) => {
let splitQuery = utils.splitTemplateQuery(test_case.query);
expect(splitQuery).toEqual(test_case.expected);
});
Expand All @@ -144,19 +141,31 @@ describe('Utils', () => {
const test_cases = [
{
array: [],
depth: 1
depth: 1,
},
{
array: [1, 2, 3],
depth: 1
depth: 1,
},
{
array: [[1, 2], [3, 4]],
depth: 2
array: [
[1, 2],
[3, 4],
],
depth: 2,
},
{
array: [[[1, 2], [3, 4]], [[1, 2], [3, 4]]],
depth: 3
array: [
[
[1, 2],
[3, 4],
],
[
[1, 2],
[3, 4],
],
],
depth: 3,
},
];

Expand Down
4 changes: 2 additions & 2 deletions src/datasource/zabbix/connectors/zabbix_api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export interface JSONRPCError {
data?: string;
}

export type JSONRPCRequestParams = {[key: string]: any};
export type JSONRPCRequestParams = { [key: string]: any };

export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'CONNECT' | 'OPTIONS' | 'TRACE';

export type GFRequestOptions = {[key: string]: any};
export type GFRequestOptions = { [key: string]: any };

export interface ZabbixRequestResponse {
data?: JSONRPCResponse<any>;
Expand Down