code review and test
This commit is contained in:
parent
962b96fffc
commit
fb1ecbb5c9
|
@ -1,8 +1,11 @@
|
||||||
import os from "os"
|
import os from "os"
|
||||||
import process from "process"
|
import process from "process"
|
||||||
import { env } from "@budibase/backend-core"
|
import { env } from "@budibase/backend-core"
|
||||||
|
import { GetDiagnosticsResponse, UserCtx } from "@budibase/types"
|
||||||
|
|
||||||
export async function systemDebugInfo(ctx: any) {
|
export async function systemDebugInfo(
|
||||||
|
ctx: UserCtx<void, GetDiagnosticsResponse>
|
||||||
|
) {
|
||||||
const { days, hours, minutes } = secondsToHMS(os.uptime())
|
const { days, hours, minutes } = secondsToHMS(os.uptime())
|
||||||
const totalMemory = convertBytes(os.totalmem())
|
const totalMemory = convertBytes(os.totalmem())
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
||||||
|
const setup = require("./utilities")
|
||||||
|
import os from "os"
|
||||||
|
|
||||||
|
jest.mock("process", () => ({
|
||||||
|
arch: "arm64",
|
||||||
|
version: "v14.20.1",
|
||||||
|
platform: "darwin",
|
||||||
|
}))
|
||||||
|
|
||||||
|
describe("/component", () => {
|
||||||
|
let request = setup.getRequest()
|
||||||
|
let config = setup.getConfig()
|
||||||
|
|
||||||
|
afterAll(setup.afterAll)
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await config.init()
|
||||||
|
os.cpus = () => [
|
||||||
|
{
|
||||||
|
model: "test",
|
||||||
|
speed: 12323,
|
||||||
|
times: {
|
||||||
|
user: 0,
|
||||||
|
nice: 0,
|
||||||
|
sys: 0,
|
||||||
|
idle: 0,
|
||||||
|
irq: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
os.uptime = () => 123123123123
|
||||||
|
os.totalmem = () => 10000000000
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("/api/debug", () => {
|
||||||
|
it("should return debug information to the frontend", async () => {
|
||||||
|
const res = await request
|
||||||
|
.get(`/api/debug/diagnostics`)
|
||||||
|
.set(config.defaultHeaders())
|
||||||
|
.expect("Content-Type", /json/)
|
||||||
|
.expect(200)
|
||||||
|
expect(res.body).toEqual({
|
||||||
|
budibaseVersion: "0.0.0",
|
||||||
|
cpuArch: "arm64",
|
||||||
|
cpuCores: 1,
|
||||||
|
cpuInfo: "test",
|
||||||
|
hosting: "docker-compose",
|
||||||
|
nodeVersion: "v14.20.1",
|
||||||
|
platform: "darwin",
|
||||||
|
totalMemory: "9.313225746154785GB",
|
||||||
|
uptime: "1425036 day(s), 3 hour(s), 32 minute(s)",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should apply authorization to endpoint", async () => {
|
||||||
|
await checkBuilderEndpoint({
|
||||||
|
config,
|
||||||
|
method: "GET",
|
||||||
|
url: `/api/debug/diagnostics`,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
|
@ -0,0 +1,11 @@
|
||||||
|
export interface GetDiagnosticsResponse {
|
||||||
|
budibaseVersion: string
|
||||||
|
hosting: string
|
||||||
|
nodeVersion: string
|
||||||
|
platform: string
|
||||||
|
cpuArch: string
|
||||||
|
cpuCores: number
|
||||||
|
cpuInfo: string
|
||||||
|
totalMemory: string
|
||||||
|
uptime: string
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ export * from "./analytics"
|
||||||
export * from "./auth"
|
export * from "./auth"
|
||||||
export * from "./user"
|
export * from "./user"
|
||||||
export * from "./errors"
|
export * from "./errors"
|
||||||
|
export * from "./debug"
|
||||||
export * from "./schedule"
|
export * from "./schedule"
|
||||||
export * from "./system"
|
export * from "./system"
|
||||||
export * from "./app"
|
export * from "./app"
|
||||||
|
|
Loading…
Reference in New Issue