Skip to content

Commit

Permalink
test: use test-cache-dir to reduce reduce duplicate package download …
Browse files Browse the repository at this point in the history
…execution test

Signed-off-by: Lenin Mehedy <[email protected]>
  • Loading branch information
leninmehedy committed Nov 16, 2023
1 parent 6a31048 commit 49160cd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import { describe, expect, it } from '@jest/globals'
import {describe, expect, it} from '@jest/globals'

Check notice on line 1 in fullstack-network-manager/test/e2e/core/package_downloader_e2e.test.mjs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

fullstack-network-manager/test/e2e/core/package_downloader_e2e.test.mjs#L1

A space is required after '{'.
import * as fs from 'fs'
import * as path from 'path'
import * as os from 'os'
import { logging, PackageDownloader, Templates } from '../../../src/core/index.mjs'
import {logging, PackageDownloader, Templates} from '../../../src/core/index.mjs'

Check notice on line 5 in fullstack-network-manager/test/e2e/core/package_downloader_e2e.test.mjs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

fullstack-network-manager/test/e2e/core/package_downloader_e2e.test.mjs#L5

A space is required after '{'.

describe('PackageDownloaderE2E', () => {
const testLogger = logging.NewLogger('debug')
const downloader = new PackageDownloader(testLogger)

it('should succeed with a valid Hedera release tag', async () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'downloader-'))
const testCacheDir = 'test/data/tmp'

const tag = 'v0.42.5'
const releasePrefix = Templates.prepareReleasePrefix(tag)

const destPath = `${tmpDir}/${releasePrefix}/build-${tag}.zip`
await expect(downloader.fetchPlatform(tag, tmpDir)).resolves.toBe(destPath)
const destPath = `${testCacheDir}/${releasePrefix}/build-${tag}.zip`
await expect(downloader.fetchPlatform(tag, testCacheDir)).resolves.toBe(destPath)
expect(fs.existsSync(destPath)).toBeTruthy()
testLogger.showUser(destPath)

// remove the downloaded files to reduce disk usage
fs.rmSync(`${tmpDir}`, { recursive: true })
}, 100000)
}, 200000)
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from '@jest/globals'
import { PackageDownloader, PlatformInstaller, constants, logging, Kubectl } from '../../../src/core/index.mjs'
import {beforeAll, describe, expect, it} from '@jest/globals'

Check notice on line 1 in fullstack-network-manager/test/e2e/core/platform_installer_e2e.test.mjs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

fullstack-network-manager/test/e2e/core/platform_installer_e2e.test.mjs#L1

A space is required after '{'.
import {PackageDownloader, PlatformInstaller, constants, logging, Kubectl, Templates} from '../../../src/core/index.mjs'

Check notice on line 2 in fullstack-network-manager/test/e2e/core/platform_installer_e2e.test.mjs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

fullstack-network-manager/test/e2e/core/platform_installer_e2e.test.mjs#L2

A space is required after '{'.
import * as fs from 'fs'
import * as path from 'path'
import * as os from 'os'
Expand All @@ -9,10 +9,17 @@ describe('PackageInstallerE2E', () => {
const kubectl = new Kubectl(testLogger)
const installer = new PlatformInstaller(testLogger, kubectl)
const downloader = new PackageDownloader(testLogger)
const testCacheDir = 'test/data/tmp'
const podName = 'network-node0-0'
const packageTag = 'v0.42.5'
let packageFile = ''

beforeAll(() => {
if (!fs.existsSync(testCacheDir)) {
fs.mkdirSync(testCacheDir)
}
})

describe('setupHapiDirectories', () => {
it('should succeed with valid pod', async () => {
expect.assertions(1)
Expand All @@ -26,22 +33,28 @@ describe('PackageInstallerE2E', () => {
})

describe('copyPlatform', () => {
it('should succeed fetching platform release', async () => {
const releasePrefix = Templates.prepareReleasePrefix(packageTag)
const destPath = `${testCacheDir}/${releasePrefix}/build-${packageTag}.zip`
await expect(downloader.fetchPlatform(packageTag, testCacheDir)).resolves.toBe(destPath)
expect(fs.existsSync(destPath)).toBeTruthy()
testLogger.showUser(destPath)

// do not delete the cache dir
}, 200000)

it('should succeed with valid tag and pod', async () => {
expect.assertions(1)
try {
const tmpDir = 'test/data/tmp'
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir)
}
packageFile = await downloader.fetchPlatform(packageTag, tmpDir)
packageFile = await downloader.fetchPlatform(packageTag, testCacheDir)
await expect(installer.copyPlatform(podName, packageFile, true)).resolves.toBeTruthy()
const outputs = await kubectl.execContainer(podName, constants.ROOT_CONTAINER, `ls -la ${constants.HAPI_PATH}`)
testLogger.showUser(outputs)
} catch (e) {
console.error(e)
expect(e).toBeNull()
}
}, 20000)
})
})

describe('prepareConfigTxt', () => {
Expand Down Expand Up @@ -69,7 +82,7 @@ describe('PackageInstallerE2E', () => {
// verify file content matches
expect(fileContents).toBe(configLines.join('\n'))

fs.rmSync(tmpDir, { recursive: true })
fs.rmSync(tmpDir, {recursive: true})

Check notice on line 85 in fullstack-network-manager/test/e2e/core/platform_installer_e2e.test.mjs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

fullstack-network-manager/test/e2e/core/platform_installer_e2e.test.mjs#L85

A space is required after '{'.
})
})

Expand All @@ -88,7 +101,7 @@ describe('PackageInstallerE2E', () => {
// verify copy of local-node data is at staging area
expect(fs.existsSync(`${tmpDir}/templates`)).toBeTruthy()

fs.rmSync(tmpDir, { recursive: true })
fs.rmSync(tmpDir, {recursive: true})
})
})

Expand Down Expand Up @@ -159,7 +172,7 @@ describe('PackageInstallerE2E', () => {
expect(fileList).toContain(`${constants.HAPI_PATH}/data/config/api-permission.properties`)
expect(fileList).toContain(`${constants.HAPI_PATH}/data/config/application.properties`)
expect(fileList).toContain(`${constants.HAPI_PATH}/data/config/bootstrap.properties`)
fs.rmSync(tmpDir, { recursive: true })
fs.rmSync(tmpDir, {recursive: true})
}, 10000)
})
})

0 comments on commit 49160cd

Please sign in to comment.