Skip to content

Commit

Permalink
Merge pull request #92 from github/brrygrdn/manually-revert-recent-ch…
Browse files Browse the repository at this point in the history
…anges

Manually revert recent changes to `src/` that were not reflected in `dist/`
  • Loading branch information
Barry Gordon authored and GitHub committed Sep 28, 2021
2 parents a8d4309 + 8e61a83 commit 587b6eb
Show file tree
Hide file tree
Showing 15 changed files with 454 additions and 581 deletions.
Empty file removed __fixtures__/output/empty/.keep
Empty file.
1 change: 0 additions & 1 deletion __fixtures__/output/happy_path/output.json

This file was deleted.

1 change: 0 additions & 1 deletion __fixtures__/output/malformed/output.json

This file was deleted.

38 changes: 10 additions & 28 deletions __tests__/container-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,18 @@ describe('ContainerService', () => {
const docker = new Docker()
let container: any

describe('when a container runs successfully', () => {
beforeEach(async () => {
await ImageService.pull('alpine')
container = await docker.createContainer({
Image: 'alpine',
AttachStdout: true,
AttachStderr: true,
Cmd: ['/bin/sh', '-c', 'echo $VAR'],
Env: ['VAR=env-var']
})
})

test('it returns true', async () => {
expect(await ContainerService.run(container)).toBe(true)
beforeAll(async () => {
await ImageService.pull('alpine')
container = await docker.createContainer({
Image: 'alpine',
AttachStdout: true,
AttachStderr: true,
Cmd: ['/bin/sh', '-c', 'echo $VAR'],
Env: ['VAR=env-var']
})
})

describe('when a container runs unsuccessfully', () => {
beforeEach(async () => {
await ImageService.pull('alpine')
container = await docker.createContainer({
Image: 'alpine',
AttachStdout: true,
AttachStderr: true,
Cmd: ['/bin/sh', '-c', 'nosuchccommand']
})
})

test('raises an exception', async () => {
await expect(ContainerService.run(container)).rejects.toThrow()
})
test('runs containers', async () => {
await ContainerService.run(container)
})
})
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {ApiClient} from '../src/api-client'
import {APIClient, PackageManager} from '../src/api-client'

describe('ApiClient', () => {
describe('APIClient', () => {
const mockAxios: any = {
get: jest.fn()
}
const api = new ApiClient(mockAxios, {
const api = new APIClient(mockAxios, {
jobId: 1,
jobToken: 'xxx',
credentialsToken: 'yyy',
Expand Down Expand Up @@ -34,6 +34,6 @@ describe('ApiClient', () => {

const jobDetails = await api.getJobDetails()
expect(jobDetails['allowed-updates'].length).toBe(1)
expect(jobDetails['package-manager']).toBe('npm_and_yarn')
expect(jobDetails['package-manager']).toBe(PackageManager.NpmAndYarn)
})
})
26 changes: 9 additions & 17 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from '@actions/core'
import {Context} from '@actions/github/lib/context'
import {ApiClient} from '../src/api-client'
import {APIClient} from '../src/api-client'
import {Updater} from '../src/updater'
import {ImageService} from '../src/image-service'
import * as inputs from '../src/inputs'
Expand All @@ -21,10 +21,10 @@ describe('run', () => {

beforeEach(async () => {
markJobAsProcessedSpy = jest.spyOn(
ApiClient.prototype,
APIClient.prototype,
'markJobAsProcessed'
)
reportJobErrorSpy = jest.spyOn(ApiClient.prototype, 'reportJobError')
reportJobErrorSpy = jest.spyOn(APIClient.prototype, 'reportJobError')

jest.spyOn(core, 'info').mockImplementation(jest.fn())
jest.spyOn(core, 'setFailed').mockImplementation(jest.fn())
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('run', () => {
describe('when there is an error retrieving job details from DependabotAPI', () => {
beforeEach(() => {
jest
.spyOn(ApiClient.prototype, 'getJobDetails')
.spyOn(APIClient.prototype, 'getJobDetails')
.mockImplementationOnce(
jest.fn(async () =>
Promise.reject(new Error('error getting job details'))
Expand All @@ -139,9 +139,7 @@ describe('run', () => {

expect(reportJobErrorSpy).toHaveBeenCalledWith({
'error-type': 'actions_workflow_unknown',
'error-details': {
'action-error': 'error getting job details'
}
'error-detail': 'error getting job details'
})
expect(markJobAsProcessedSpy).toHaveBeenCalled()
})
Expand All @@ -150,7 +148,7 @@ describe('run', () => {
describe('when there is an error retrieving job credentials from DependabotAPI', () => {
beforeEach(() => {
jest
.spyOn(ApiClient.prototype, 'getCredentials')
.spyOn(APIClient.prototype, 'getCredentials')
.mockImplementationOnce(
jest.fn(async () =>
Promise.reject(new Error('error getting credentials'))
Expand All @@ -175,9 +173,7 @@ describe('run', () => {

expect(reportJobErrorSpy).toHaveBeenCalledWith({
'error-type': 'actions_workflow_unknown',
'error-details': {
'action-error': 'error getting credentials'
}
'error-detail': 'error getting credentials'
})
expect(markJobAsProcessedSpy).toHaveBeenCalled()
})
Expand Down Expand Up @@ -211,9 +207,7 @@ describe('run', () => {

expect(reportJobErrorSpy).toHaveBeenCalledWith({
'error-type': 'actions_workflow_image',
'error-details': {
'action-error': 'error pulling an image'
}
'error-detail': 'error pulling an image'
})
expect(markJobAsProcessedSpy).toHaveBeenCalled()
})
Expand Down Expand Up @@ -247,9 +241,7 @@ describe('run', () => {

expect(reportJobErrorSpy).toHaveBeenCalledWith({
'error-type': 'actions_workflow_updater',
'error-details': {
'action-error': 'error running the update'
}
'error-detail': 'error running the update'
})
expect(markJobAsProcessedSpy).toHaveBeenCalled()
})
Expand Down
4 changes: 2 additions & 2 deletions __tests__/proxy-integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Docker from 'dockerode'
import {Credential, JobDetails} from '../src/api-client'
import {Credential, JobDetails, PackageManager} from '../src/api-client'
import {ImageService} from '../src/image-service'
import {PROXY_IMAGE_NAME} from '../src/main'
import {ProxyBuilder} from '../src/proxy'
Expand All @@ -17,7 +17,7 @@ describe('ProxyBuilder', () => {
'dependency-type': 'all'
}
],
'package-manager': 'npm_and_yarn'
'package-manager': PackageManager.NpmAndYarn
}
const credentials: Credential[] = [
{
Expand Down
4 changes: 2 additions & 2 deletions __tests__/updater-integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios'

import {ApiClient, JobParameters} from '../src/api-client'
import {APIClient, JobParameters} from '../src/api-client'
import {ImageService} from '../src/image-service'
import {UPDATER_IMAGE_NAME, PROXY_IMAGE_NAME} from '../src/main'
import {Updater} from '../src/updater'
Expand All @@ -27,7 +27,7 @@ describe('Updater', () => {
)

const client = axios.create({baseURL: dependabotApiUrl})
const apiClient = new ApiClient(client, params)
const apiClient = new APIClient(client, params)

beforeAll(async () => {
// Skip the test when we haven't preloaded the updater image
Expand Down
Loading

0 comments on commit 587b6eb

Please sign in to comment.