Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
btkostner committed Sep 20, 2024
1 parent 5e2e956 commit 03866c5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
6 changes: 5 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9661,7 +9661,10 @@ function getRunnerOSVersion() {

async function getUrlResponse(url, headers, attempt = 1) {
try {
const response = await fetch(url, { headers })
const response = await fetch(url, {
headers,
signal: AbortSignal.timeout(10000),
})
const contentType = response.headers.get('content-type') || ''

if (!response.ok) {
Expand Down Expand Up @@ -10157,6 +10160,7 @@ function debugLoggingEnabled() {
}

module.exports = {
get,
getOTPVersion,
getElixirVersion,
getGleamVersion,
Expand Down
6 changes: 5 additions & 1 deletion src/setup-beam.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,10 @@ function getRunnerOSVersion() {

async function getUrlResponse(url, headers, attempt = 1) {
try {
const response = await fetch(url, { headers })
const response = await fetch(url, {
headers,
signal: AbortSignal.timeout(10000),
})
const contentType = response.headers.get('content-type') || ''

if (!response.ok) {
Expand Down Expand Up @@ -1057,6 +1060,7 @@ function debugLoggingEnabled() {
}

module.exports = {
get,
getOTPVersion,
getElixirVersion,
getGleamVersion,
Expand Down
25 changes: 24 additions & 1 deletion test/setup-beam.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ simulateInput('github-token', process.env.GITHUB_TOKEN)
simulateInput('hexpm-mirrors', 'https://builds.hex.pm', { multiline: true })

const assert = require('assert')
const http = require('http')
const fs = require('fs')
const os = require('os')
const path = require('path')
Expand Down Expand Up @@ -71,8 +72,8 @@ async function all() {
await testRebar3Versions()

await testGetVersionFromSpec()

await testParseVersionFile()
await testGetRetry()

await testElixirMixCompileError()
await testElixirMixCompileWarning()
Expand Down Expand Up @@ -913,6 +914,28 @@ gleam ${gleam} \nrebar ${rebar3}`
simulateInput('rebar3-version', rebar3Version)
}

async function testGetRetry() {
let attempt = 0
const server = http.createServer((req, res) => {
attempt++
if (attempt == 2) {
res.write('correct!')
res.end()
}
})

try {
server.listen(0)
const port = server.address().port

const response = await setupBeam.get(`http://localhost:${port}`, [])
assert.equal(response, 'correct!')
assert.equal(attempt, 2)
} finally {
server.close()
}
}

async function testElixirMixCompileError() {
const [matcher] = problemMatcher.find(
({ owner }) => owner === 'elixir-mixCompileError',
Expand Down

0 comments on commit 03866c5

Please sign in to comment.