Skip to content

Commit

Permalink
package manager tests
Browse files Browse the repository at this point in the history
  • Loading branch information
musdotdigital committed Dec 1, 2023
1 parent e4eabb4 commit c7a75f7
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ jobs:
- uses: actions/checkout@v3
- uses: ./
with:
dockerfile: ./__tests__/data/Dockerfile
dockerfile: ./__tests__/data/Dockerfile.apk
dependencies: ./__tests__/data/dependencies.json
File renamed without changes.
1 change: 1 addition & 0 deletions __tests__/data/Dockerfile.apt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM ubuntu:latest
10 changes: 9 additions & 1 deletion __tests__/dockerfile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ import * as path from 'path'
import {load} from '../src/dockerfile'

test('load alpine dockerfile', async () => {
const dockerfilePath = path.join(__dirname, 'data', 'Dockerfile')
const dockerfilePath = path.join(__dirname, 'data', 'Dockerfile.apk')
const dockerfile = await load(dockerfilePath)
expect(dockerfile.pkgManager).toBe('apk')
expect(dockerfile.name).toBe('alpine:latest')
})

test('load ubuntu dockerfile', async () => {
const dockerfilePath = path.join(__dirname, 'data', 'Dockerfile.apt')
const dockerfile = await load(dockerfilePath)
expect(dockerfile.pkgManager).toBe('apt')
expect(dockerfile.name).toBe('ubuntu:latest')
})

test('load dockerfile with unsupported package manager', async () => {
const dockerfilePath = path.join(__dirname, 'data', 'Dockerfile.unsupported')
await expect(load(dockerfilePath)).rejects.toThrow(
Expand Down
6 changes: 5 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import {test} from '@jest/globals'

// shows how the runner will run a javascript action with env / stdout protocol
test('test runs', () => {
process.env['INPUT_DOCKERFILE'] = path.join(__dirname, 'data', 'Dockerfile')
process.env['INPUT_DOCKERFILE'] = path.join(
__dirname,
'data',
'Dockerfile.apk'
)
process.env['INPUT_DEPENDENCIES'] = path.join(
__dirname,
'data',
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ exports.Image = void 0;
const docker_cli_js_1 = __nccwpck_require__(771);
const packageManagers = [
{ command: 'apk --version', name: 'apk' },
{ command: 'apt-get --version', name: 'apt-get' }
{ command: 'apt-get --version', name: 'apt' }
];
class Image {
constructor(name) {
Expand Down Expand Up @@ -146,7 +146,7 @@ class Image {
switch (this.pkgManager) {
case 'apk':
return this.get_latest_version_apk(installed_package);
case 'apt-get':
case 'apt':
return this.get_latest_version_apt(installed_package);
default:
throw Error('Unable to get package manager');
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/image.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {Docker, Options} from 'docker-cli-js'
import {Package} from './dependencies'

export type PackageManager = 'apk' | 'apt-get'
export type PackageManager = 'apk' | 'apt'

const packageManagers: {
command: string
name: PackageManager
}[] = [
{command: 'apk --version', name: 'apk'},
{command: 'apt-get --version', name: 'apt-get'}
{command: 'apt-get --version', name: 'apt'}
]

export class Image {
Expand Down Expand Up @@ -47,7 +47,7 @@ export class Image {
switch (this.pkgManager) {
case 'apk':
return this.get_latest_version_apk(installed_package)
case 'apt-get':
case 'apt':
return this.get_latest_version_apt(installed_package)
default:
throw Error('Unable to get package manager')
Expand Down

0 comments on commit c7a75f7

Please sign in to comment.