diff --git a/__tests__/buildkit/config.test.ts b/__tests__/buildkit/config.test.ts index bf345ff..4a8a1a2 100644 --- a/__tests__/buildkit/config.test.ts +++ b/__tests__/buildkit/config.test.ts @@ -15,22 +15,20 @@ */ import {describe, expect, jest, test, afterEach} from '@jest/globals'; -import * as fs from 'fs'; -import * as path from 'path'; +import fs from 'fs'; +import os from 'os'; +import path from 'path'; import * as rimraf from 'rimraf'; import {BuildKit} from '../../src/buildkit/buildkit'; import {Context} from '../../src/context'; const fixturesDir = path.join(__dirname, '..', 'fixtures'); -// prettier-ignore -const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildkit-config-jest'); +const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildkit-config-')); const tmpName = path.join(tmpDir, '.tmpname-jest'); jest.spyOn(Context, 'tmpDir').mockImplementation((): string => { - if (!fs.existsSync(tmpDir)) { - fs.mkdirSync(tmpDir, {recursive: true}); - } + fs.mkdirSync(tmpDir, {recursive: true}); return tmpDir; }); diff --git a/__tests__/buildx/bake.test.ts b/__tests__/buildx/bake.test.ts index 47f22d3..5e0f820 100644 --- a/__tests__/buildx/bake.test.ts +++ b/__tests__/buildx/bake.test.ts @@ -15,8 +15,9 @@ */ import {afterEach, describe, expect, it, jest, test} from '@jest/globals'; -import * as fs from 'fs'; -import * as path from 'path'; +import fs from 'fs'; +import os from 'os'; +import path from 'path'; import * as rimraf from 'rimraf'; import {Bake} from '../../src/buildx/bake'; @@ -27,15 +28,12 @@ import {BakeDefinition} from '../../src/types/buildx/bake'; import {BuildMetadata} from '../../src/types/buildx/build'; const fixturesDir = path.join(__dirname, '..', 'fixtures'); -// prettier-ignore -const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-bake-jest'); +const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildx-bake-')); const tmpName = path.join(tmpDir, '.tmpname-jest'); const metadata = JSON.parse(fs.readFileSync(path.join(fixturesDir, 'metadata-bake.json'), 'utf-8')); jest.spyOn(Context, 'tmpDir').mockImplementation((): string => { - if (!fs.existsSync(tmpDir)) { - fs.mkdirSync(tmpDir, {recursive: true}); - } + fs.mkdirSync(tmpDir, {recursive: true}); return tmpDir; }); diff --git a/__tests__/buildx/build.test.ts b/__tests__/buildx/build.test.ts index f7bc83c..b50dd32 100644 --- a/__tests__/buildx/build.test.ts +++ b/__tests__/buildx/build.test.ts @@ -15,23 +15,21 @@ */ import {afterEach, beforeEach, describe, expect, it, jest, test} from '@jest/globals'; -import * as fs from 'fs'; -import * as path from 'path'; +import fs from 'fs'; +import os from 'os'; +import path from 'path'; import * as rimraf from 'rimraf'; import {Context} from '../../src/context'; import {Build} from '../../src/buildx/build'; const fixturesDir = path.join(__dirname, '..', 'fixtures'); -// prettier-ignore -const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-build-jest'); +const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildx-build-')); const tmpName = path.join(tmpDir, '.tmpname-jest'); const metadata = JSON.parse(fs.readFileSync(path.join(fixturesDir, 'metadata-build.json'), 'utf-8')); jest.spyOn(Context, 'tmpDir').mockImplementation((): string => { - if (!fs.existsSync(tmpDir)) { - fs.mkdirSync(tmpDir, {recursive: true}); - } + fs.mkdirSync(tmpDir, {recursive: true}); return tmpDir; }); diff --git a/__tests__/buildx/buildx.test.itg.ts b/__tests__/buildx/buildx.test.itg.ts index cf7bcdc..5ebb0fa 100644 --- a/__tests__/buildx/buildx.test.itg.ts +++ b/__tests__/buildx/buildx.test.itg.ts @@ -15,8 +15,9 @@ */ import {describe, expect, it} from '@jest/globals'; -import * as fs from 'fs'; -import * as path from 'path'; +import fs from 'fs'; +import os from 'os'; +import path from 'path'; import * as core from '@actions/core'; import {Buildx} from '../../src/buildx/buildx'; @@ -25,9 +26,7 @@ import {Bake} from '../../src/buildx/bake'; import {Exec} from '../../src/exec'; const fixturesDir = path.join(__dirname, '..', 'fixtures'); - -// prettier-ignore -const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-jest'); +const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildx-buildx-itg-')); const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip; diff --git a/__tests__/buildx/buildx.test.ts b/__tests__/buildx/buildx.test.ts index a876780..3c0793d 100644 --- a/__tests__/buildx/buildx.test.ts +++ b/__tests__/buildx/buildx.test.ts @@ -15,8 +15,9 @@ */ import {describe, expect, it, jest, test, beforeEach, afterEach} from '@jest/globals'; -import * as fs from 'fs'; -import * as path from 'path'; +import fs from 'fs'; +import os from 'os'; +import path from 'path'; import * as rimraf from 'rimraf'; import * as semver from 'semver'; @@ -27,14 +28,11 @@ import {Exec} from '../../src/exec'; import {Cert, LocalState} from '../../src/types/buildx/buildx'; const fixturesDir = path.join(__dirname, '..', 'fixtures'); -// prettier-ignore -const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-jest'); +const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildx-buildx-')); const tmpName = path.join(tmpDir, '.tmpname-jest'); jest.spyOn(Context, 'tmpDir').mockImplementation((): string => { - if (!fs.existsSync(tmpDir)) { - fs.mkdirSync(tmpDir, {recursive: true}); - } + fs.mkdirSync(tmpDir, {recursive: true}); return tmpDir; }); diff --git a/__tests__/buildx/history.test.itg.ts b/__tests__/buildx/history.test.itg.ts index efcf1e8..0671286 100644 --- a/__tests__/buildx/history.test.itg.ts +++ b/__tests__/buildx/history.test.itg.ts @@ -15,8 +15,9 @@ */ import {afterEach, beforeEach, describe, expect, it, jest, test} from '@jest/globals'; -import * as fs from 'fs'; -import * as path from 'path'; +import fs from 'fs'; +import os from 'os'; +import path from 'path'; import {Buildx} from '../../src/buildx/buildx'; import {Bake} from '../../src/buildx/bake'; @@ -25,9 +26,7 @@ import {History} from '../../src/buildx/history'; import {Exec} from '../../src/exec'; const fixturesDir = path.join(__dirname, '..', 'fixtures'); - -// prettier-ignore -const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-history-jest'); +const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildx-history-itg-')); const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip; diff --git a/__tests__/buildx/install.test.ts b/__tests__/buildx/install.test.ts index 92ae0b3..ed5b358 100644 --- a/__tests__/buildx/install.test.ts +++ b/__tests__/buildx/install.test.ts @@ -15,15 +15,15 @@ */ import {describe, expect, it, jest, test, afterEach} from '@jest/globals'; -import * as fs from 'fs'; -import * as path from 'path'; +import fs from 'fs'; +import os from 'os'; +import path from 'path'; import * as rimraf from 'rimraf'; import osm = require('os'); import {Install} from '../../src/buildx/install'; -// prettier-ignore -const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-jest'); +const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildx-install-')); afterEach(function () { rimraf.sync(tmpDir); diff --git a/__tests__/cache.test.itg.ts b/__tests__/cache.test.itg.ts index ad295f7..02d3b88 100644 --- a/__tests__/cache.test.itg.ts +++ b/__tests__/cache.test.itg.ts @@ -14,15 +14,15 @@ * limitations under the License. */ -import path from 'path'; import {describe, expect, it} from '@jest/globals'; +import fs from 'fs'; +import os from 'os'; +import path from 'path'; import {Cache} from '../src/cache'; -// prettier-ignore -const tmpDir = path.join(process.env.TEMP || '/tmp', 'cache-jest'); - const fixturesDir = path.join(__dirname, 'fixtures'); +const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'cache-itg-')); describe('cache', () => { it('github-repo', async () => { diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index 325655c..0f97583 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -14,21 +14,19 @@ * limitations under the License. */ -import * as fs from 'fs'; -import * as path from 'path'; -import * as rimraf from 'rimraf'; import {describe, expect, jest, it, afterEach} from '@jest/globals'; +import fs from 'fs'; +import os from 'os'; +import path from 'path'; +import * as rimraf from 'rimraf'; import {Context} from '../src/context'; -// prettier-ignore -const tmpDir = path.join(process.env.TEMP || '/tmp', 'context-jest'); +const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'context-')); const tmpName = path.join(tmpDir, '.tmpname-jest'); jest.spyOn(Context, 'tmpDir').mockImplementation((): string => { - if (!fs.existsSync(tmpDir)) { - fs.mkdirSync(tmpDir, {recursive: true}); - } + fs.mkdirSync(tmpDir, {recursive: true}); return tmpDir; }); diff --git a/__tests__/docker/docker.test.ts b/__tests__/docker/docker.test.ts index ea4f78f..0b13113 100644 --- a/__tests__/docker/docker.test.ts +++ b/__tests__/docker/docker.test.ts @@ -15,7 +15,8 @@ */ import {afterEach, beforeEach, describe, expect, it, jest} from '@jest/globals'; -import * as fs from 'fs'; +import fs from 'fs'; +import os from 'os'; import path from 'path'; import * as io from '@actions/io'; import osm = require('os'); @@ -26,9 +27,7 @@ import {Docker} from '../../src/docker/docker'; import {ConfigFile} from '../../src/types/docker/docker'; const fixturesDir = path.join(__dirname, '..', 'fixtures'); - -// prettier-ignore -const tmpDir = path.join(process.env.TEMP || '/tmp', 'docker-jest'); +const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'docker-docker-')); afterEach(function () { rimraf.sync(tmpDir); diff --git a/__tests__/docker/install.test.itg.ts b/__tests__/docker/install.test.itg.ts index c55f43a..679fa85 100644 --- a/__tests__/docker/install.test.itg.ts +++ b/__tests__/docker/install.test.itg.ts @@ -14,15 +14,16 @@ * limitations under the License. */ -import path from 'path'; import {jest, describe, expect, test, beforeEach, afterEach} from '@jest/globals'; +import fs from 'fs'; +import os from 'os'; +import path from 'path'; import {Install} from '../../src/docker/install'; import {Docker} from '../../src/docker/docker'; import {Exec} from '../../src/exec'; -// prettier-ignore -const tmpDir = path.join(process.env.TEMP || '/tmp', 'docker-install-jest'); +const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'docker-install-itg-')); describe('install', () => { const originalEnv = process.env; diff --git a/__tests__/docker/install.test.ts b/__tests__/docker/install.test.ts index ab92131..80ecc29 100644 --- a/__tests__/docker/install.test.ts +++ b/__tests__/docker/install.test.ts @@ -15,15 +15,15 @@ */ import {describe, expect, jest, test, beforeEach, afterEach, it} from '@jest/globals'; -import * as fs from 'fs'; -import * as path from 'path'; +import fs from 'fs'; +import os from 'os'; +import path from 'path'; import * as rimraf from 'rimraf'; import osm = require('os'); import {Install} from '../../src/docker/install'; -// prettier-ignore -const tmpDir = path.join(process.env.TEMP || '/tmp', 'docker-install-jest'); +const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'docker-install-')); afterEach(function () { rimraf.sync(tmpDir); diff --git a/__tests__/github.test.itg.ts b/__tests__/github.test.itg.ts index b720ece..cfa63ad 100644 --- a/__tests__/github.test.itg.ts +++ b/__tests__/github.test.itg.ts @@ -16,7 +16,8 @@ import {describe, expect, it, test} from '@jest/globals'; import fs from 'fs'; -import * as path from 'path'; +import os from 'os'; +import path from 'path'; import {Buildx} from '../src/buildx/buildx'; import {Bake} from '../src/buildx/bake'; @@ -26,9 +27,7 @@ import {GitHub} from '../src/github'; import {History} from '../src/buildx/history'; const fixturesDir = path.join(__dirname, 'fixtures'); - -// prettier-ignore -const tmpDir = path.join(process.env.TEMP || '/tmp', 'github-jest'); +const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'github-itg-')); const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip; diff --git a/__tests__/oci/oci.test.ts b/__tests__/oci/oci.test.ts index 54dadf5..f4201d9 100644 --- a/__tests__/oci/oci.test.ts +++ b/__tests__/oci/oci.test.ts @@ -15,16 +15,15 @@ */ import {afterEach, describe, expect, test} from '@jest/globals'; -import * as fs from 'fs'; +import fs from 'fs'; +import os from 'os'; import path from 'path'; import * as rimraf from 'rimraf'; import {OCI} from '../../src/oci/oci'; const fixturesDir = path.join(__dirname, '..', 'fixtures'); - -// prettier-ignore -const tmpDir = path.join(process.env.TEMP || '/tmp', 'docker-jest'); +const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'oci-oci-')); afterEach(function () { rimraf.sync(tmpDir);