UNPKG

@applitools/execution-grid-tunnel

Version:

Allows user to run tests with exection-grid and navigate to private hosts and ips

63 lines (50 loc) 1.48 kB
const {extractEyesDataFromHeaders, generateEgTunnelError} = require('../../utils') const { INIT, INIT_TIMEOUT_ERROR, RECONNECT, ERROR, STOPPED, STOPPING, } = require('../../tunnel-process-manager/tunnel-status') module.exports = {handler, extractErrorLogFields} const TUNNEL_CONNECTIVITY_TEST_NAME = 'tunnel-connectivity-test' async function handler(request, reply) { //const {apiKey, eyesServerUrl} = extractEyesDataFromHeaders(request) const { params: {tunnelId}, } = request const status = this.tunnelProcessManager.getStatus(tunnelId) if (status === null) { throw generateEgTunnelError(`Tunnel ${tunnelId} doen't exist`, 404) } if (status === INIT) { throw generateEgTunnelError( `Tunnel ${tunnelId} isn'y ready yet. Try again in a few monents`, 503, ) } if (status === STOPPING) { throw generateEgTunnelError( `Tunnel ${tunnelId} is stopping. You asked to stop the tunnel before a few moments`, 400, ) } if ([INIT_TIMEOUT_ERROR, RECONNECT, ERROR, STOPPED].includes(status)) { throw generateEgTunnelError(`Tunnel ${tunnelId} isn't active. Tunnel status: ${status}`, 500) } return reply .code(200) .header('Content-Type', 'application/json') .send(JSON.stringify('Tunnel is up')) } function extractErrorLogFields(error, request) { const { params: {tunnelId}, } = request return { action: TUNNEL_CONNECTIVITY_TEST_NAME, tunnelId, error, } }