More styling and mocking

This commit is contained in:
Dunemask 2022-08-06 21:21:41 +00:00
parent ea06cf2ebf
commit 360ff368e1
20 changed files with 354 additions and 109 deletions

View file

@ -7,8 +7,21 @@ import {
} from "../pg-query.js";
// Constants
const table = "silenced_tests";
const PG_DISABLED = process.env.POSTGRES_DISABLED;
const silencedMock = () => {
return [{
name: `single`,
class: `single.js`,
method: "FAKEMETHOD",
id: 0,
silencedUntil: new Date().toJSON(),
}]
};
// Queries
export const getSilencedTests = () => {
export const getSilencedTests = async () => {
if (PG_DISABLED) return silencedMock();
const query = `SELECT * from ${table}`;
return pg.query(query);
};

View file

@ -7,8 +7,94 @@ import {
} from "../pg-query.js";
// Constants
const table = "tests";
const PG_DISABLED = process.env.POSTGRES_DISABLED;
// Queries
export const getTests = () => {
const testsMock = () => {
return [
{
id: 0,
name: "single",
class: "single.js",
image: "node:latest",
isCompound: false,
type: "api",
description: "This is a single test",
tags: ["cron_1hour","reg_us", "env_ci", "proj_core", "skip_alt"],
path: "tests/assets/suite/single.js",
created: Date.now(),
mergeRequest: "https://example.com"
},
{
id: 1,
name: "failing",
class: "failing.js",
image: "node:latest",
isCompound: false,
type: "ui",
description: "This is a failing test",
tags: ["cron_1hour","reg_us", "env_ci", "proj_core"],
path: "tests/assets/suite/failing.js",
created: Date.now(),
mergeRequest: "https://example.com"
},
{
id: 2,
name: "primary",
class: "primary.js",
image: "node:latest",
isCompound: true,
type: "api",
description: "This is a primary test",
tags: ["cron_1hour","reg_us", "proj_core", "skip_alt", "compound_secondary"],
path: "tests/assets/suite/primary.js",
created: Date.now(),
mergeRequest: "https://example.com"
}, {
id: 3,
name: "secondary",
class: "secondary.js",
image: "node:latest",
isCompound: true,
type: "api",
description: "This is a secondary test",
tags: ["cron_1hour","reg_us", "proj_core", "compound_tertiary"],
path: "tests/assets/suite/secondary.js",
created: Date.now(),
mergeRequest: "https://example.com"
},
{
id: 4,
name: "tertiary",
class: "tertiary.js",
image: "node:latest",
isCompound: true,
type: "api",
description: "This is a single test",
tags: ["cron_1hour","reg_us", "proj_core"],
path: "tests/assets/suite/tertiary.js",
created: Date.now(),
mergeRequest: "https://example.com"
},
];
};
const mappingsMock = () => {
return [
["primary", "secondary1", "tertiary1"],
["primary", "secondary1", "tertiary2"],
["primary", "secondary2", "tertiary3"],
];
}
export const getTests = async () => {
if (PG_DISABLED) return testsMock();
const query = `SELECT * from ${table}`;
return pg.query(query);
};
export const getPipelineMappings = async () => {
if (PG_DISABLED) return mappingsMock();
const query = `SELECT * from ${table}`;
return pg.query(query);
};

View file

@ -8,6 +8,36 @@ import {
} from "../pg-query.js";
// Constants
const table = "test_results";
const PG_DISABLED = process.env.POSTGRES_DISABLED;
const failingMock = () => {
return [{
name: "failing",
class: "failing.js",
timestamp: new Date().toJSON(),
method: "FAKEMETHOD",
cron: "1hour",
type: "api",
dailyFails: 12,
screenshot: "https://picsum.photos/1920/1080",
recentResults: [1, 0, 0, 1, 0],
isCompound: false,
failedMessage: `Some Test FailureMessage`,
},{
name: "secondary",
class: "secondary.js",
timestamp: new Date().toJSON(),
method: "FAKEMETHOD",
cron: "1hour",
type: "api",
dailyFails: 1,
screenshot: "https://picsum.photos/1920/1080",
recentResults: [1, 0, 0, 1, 0],
isCompound: true,
failedMessage: `Some Test FailureMessage from Secondary`,
}]
};
// Queries
export const insertTestResult = (testResult) => {
const {
@ -46,7 +76,9 @@ export const insertTestResult = (testResult) => {
return pg.query(query);
};
export const getCurrentlyFailing = () => {
export const getCurrentlyFailing = async () => {
if (PG_DISABLED) return failingMock();
/**/
const query = `WITH recent as (SELECT * FROM test_results WHERE (timestamp BETWEEN NOW() - INTERVAL '24 HOURS' AND NOW()) AND NOT(failed AND retry)) SELECT * FROM recent WHERE timestamp = (SELECT MAX(timestamp) FROM recent r2 WHERE recent.name = r2.name) AND failed;
`;
return pg.query(query);

View file

@ -7,7 +7,7 @@ router.use(jsonMiddleware());
// Get Routes
router.get("/silenced", (req, res) => {
getSilencedTests().then(res.send);
getSilencedTests().then((t)=>res.send(t));
});
// Post Routes

View file

@ -1,5 +1,5 @@
import { Router, json as jsonMiddleware } from "express";
import { getTests } from "../database/queries/catalog.js";
import { getTests, getPipelineMappings } from "../database/queries/catalog.js";
const router = Router();
const maxSize = 1024 * 1024 * 100; // 100MB
@ -8,11 +8,14 @@ const maxSize = 1024 * 1024 * 100; // 100MB
router.use(jsonMiddleware({ limit: maxSize }));
// Get Routes
router.get("/tests", async (req, res) => {
const tests = await getTests();
res.json(tests);
router.get("/tests", (req, res) => {
getTests().then((t)=>res.json(t));
});
router.get("/pipeline-mappings", (req,res)=>{
getPipelineMappings().then((m)=>res.json(m));
})
// Post Routes
router.post("/update", (req, res) => {
// Update All Tests

View file

@ -7,7 +7,7 @@ router.use(jsonMiddleware());
// Get Routes
router.get("/failing", (req, res) => {
res.send([]);
getCurrentlyFailing().then((f)=>res.json(f));
});
// Post Routes