Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 67 additions & 67 deletions __tests__/e2e/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,47 @@ function executeAction(env): string | Buffer {
return output
}

function createJob(gitRepo: GitRepo): string | Buffer {
const env = {
function createSampleJob(gitRepo: GitRepo, payload: String): string | Buffer {
return executeAction({
...process.env,
INPUT_QUEUE_NAME: 'queue-name',
INPUT_GIT_REPO_DIR: gitRepo.getDirPath(),
INPUT_ACTION: 'create-job',
INPUT_JOB_PAYLOAD: dummyPayload(),
INPUT_GIT_COMMIT_NO_GPG_SIGN: true
}
INPUT_GIT_COMMIT_NO_GPG_SIGN: 'true',
INPUT_JOB_PAYLOAD: payload
})
}

function nextSampleJob(gitRepo: GitRepo): string | Buffer {
return executeAction({
...process.env,
INPUT_QUEUE_NAME: 'queue-name',
INPUT_GIT_REPO_DIR: gitRepo.getDirPath(),
INPUT_ACTION: 'next-job',
INPUT_GIT_COMMIT_NO_GPG_SIGN: 'true'
})
}

return executeAction(env)
function startSampleJob(gitRepo: GitRepo, payload: String): string | Buffer {
return executeAction({
...process.env,
INPUT_QUEUE_NAME: 'queue-name',
INPUT_GIT_REPO_DIR: gitRepo.getDirPath(),
INPUT_ACTION: 'start-job',
INPUT_GIT_COMMIT_NO_GPG_SIGN: 'true',
INPUT_JOB_PAYLOAD: payload
})
}

function finishSampleJob(gitRepo: GitRepo, payload: String): string | Buffer {
return executeAction({
...process.env,
INPUT_QUEUE_NAME: 'queue-name',
INPUT_GIT_REPO_DIR: gitRepo.getDirPath(),
INPUT_ACTION: 'finish-job',
INPUT_GIT_COMMIT_NO_GPG_SIGN: 'true',
INPUT_JOB_PAYLOAD: payload
})
}

/**
Expand All @@ -72,16 +102,7 @@ describe('GitHub Action', () => {
it('should print the git repo dir at the beginning of the action execution', async () => {
const gitRepo = await createInitializedGitRepo()

const env = {
...process.env,
INPUT_QUEUE_NAME: 'queue-name',
INPUT_GIT_REPO_DIR: gitRepo.getDirPath(),
INPUT_ACTION: 'next-job',
INPUT_JOB_PAYLOAD: dummyPayload(),
INPUT_GIT_COMMIT_NO_GPG_SIGN: true
}

const output = executeAction(env)
const output = nextSampleJob(gitRepo)

expect(output).toEqual(
expect.stringContaining(`git_repo_dir: ${gitRepo.getDirPath()}`)
Expand Down Expand Up @@ -112,16 +133,7 @@ describe('GitHub Action', () => {
it('should create a new job', async () => {
const gitRepo = await createInitializedGitRepo()

const env = {
...process.env,
INPUT_QUEUE_NAME: 'queue-name',
INPUT_GIT_REPO_DIR: gitRepo.getDirPath(),
INPUT_ACTION: 'create-job',
INPUT_JOB_PAYLOAD: dummyPayload(),
INPUT_GIT_COMMIT_NO_GPG_SIGN: true
}

const output = executeAction(env)
const output = createSampleJob(gitRepo, dummyPayload())

expect(getOutputVariable('job_created', output.toString())).toBe('true')
expect(getOutputVariable('job_commit', output.toString())).toBe(
Expand All @@ -132,17 +144,8 @@ describe('GitHub Action', () => {
it('should get the next job', async () => {
const gitRepo = await createInitializedGitRepo()

createJob(gitRepo)

const env = {
...process.env,
INPUT_QUEUE_NAME: 'queue-name',
INPUT_GIT_REPO_DIR: gitRepo.getDirPath(),
INPUT_ACTION: 'next-job',
INPUT_GIT_COMMIT_NO_GPG_SIGN: 'true'
}

const output = executeAction(env)
createSampleJob(gitRepo, dummyPayload())
const output = nextSampleJob(gitRepo)

expect(getOutputVariable('job_payload', output.toString())).toBe(
dummyPayload()
Expand All @@ -155,18 +158,9 @@ describe('GitHub Action', () => {
it('should mark the pending job as started', async () => {
const gitRepo = await createInitializedGitRepo()

createJob(gitRepo)
createSampleJob(gitRepo, dummyPayload())

const env = {
...process.env,
INPUT_QUEUE_NAME: 'queue-name',
INPUT_GIT_REPO_DIR: gitRepo.getDirPath(),
INPUT_ACTION: 'start-job',
INPUT_GIT_COMMIT_NO_GPG_SIGN: 'true',
INPUT_JOB_PAYLOAD: 'test'
}

const output = executeAction(env)
const output = startSampleJob(gitRepo, dummyPayload())

expect(getOutputVariable('job_started', output.toString())).toBe('true')
expect(getOutputVariable('job_commit', output.toString())).toBe(
Expand All @@ -177,32 +171,38 @@ describe('GitHub Action', () => {
it('should mark the pending job as finished', async () => {
const gitRepo = await createInitializedGitRepo()

createJob(gitRepo)

executeAction({
...process.env,
INPUT_QUEUE_NAME: 'queue-name',
INPUT_GIT_REPO_DIR: gitRepo.getDirPath(),
INPUT_ACTION: 'start-job',
INPUT_GIT_COMMIT_NO_GPG_SIGN: 'true',
INPUT_JOB_PAYLOAD: 'test'
})

const output = executeAction({
...process.env,
INPUT_QUEUE_NAME: 'queue-name',
INPUT_GIT_REPO_DIR: gitRepo.getDirPath(),
INPUT_ACTION: 'finish-job',
INPUT_GIT_COMMIT_NO_GPG_SIGN: 'true',
INPUT_JOB_PAYLOAD: 'test'
})
createSampleJob(gitRepo, dummyPayload())
startSampleJob(gitRepo, 'test')
const output = finishSampleJob(gitRepo, 'test')

expect(getOutputVariable('job_finished', output.toString())).toBe('true')
expect(getOutputVariable('job_commit', output.toString())).toBe(
getLatestCommitHash(gitRepo.getDir()).getHash()
)
})

it('should assign job id 0 to the first created job', async () => {
const gitRepo = await createInitializedGitRepo()

const output = createSampleJob(gitRepo, dummyPayload())

expect(getOutputVariable('job_id', output.toString())).toBe('0')
})

it('should assign job id 1 to the second created job', async () => {
const gitRepo = await createInitializedGitRepo()

const firstOutput = createSampleJob(gitRepo, dummyPayload())

expect(getOutputVariable('job_id', firstOutput.toString())).toBe('0')
startSampleJob(gitRepo, dummyPayload())
finishSampleJob(gitRepo, dummyPayload())

const output = createSampleJob(gitRepo, dummyPayload())

expect(getOutputVariable('job_id', output.toString())).toBe('1')
})

it('should allow to overwrite commit signing key', async () => {
const gitRepo = await createInitializedGitRepo()
const gnuPGHomeDir = await createInitializedTempGnuPGHomeDir()
Expand Down
3 changes: 2 additions & 1 deletion __tests__/unit/commit-body.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {CommitBody} from '../../src/commit-body'
import {JobId} from '../../src/job-id'
import {NewJobMessage} from '../../src/message'
import {dummyCommitBodyText} from '../../src/__tests__/helpers'
import {nullCommitHash} from '../../src/commit-hash'
Expand Down Expand Up @@ -81,7 +82,7 @@ describe('CommitBody', () => {

it('could be built from a Message', () => {
const commitBody = CommitBody.fromMessage(
new NewJobMessage('message-payload')
new NewJobMessage('message-payload', new JobId(0))
)

const builtBody = JSON.stringify({
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/commit-message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {CommitSubjectParser} from '../../src/commit-subject-parser'
import {dummyCommitBodyText} from '../../src/__tests__/helpers'

function dummyCommitSubjectText(): string {
return '📝🈺: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
return '📝🈺: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
}

describe('CommitMessage', () => {
Expand Down
44 changes: 36 additions & 8 deletions __tests__/unit/commit-subject-parser.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {CommitHash} from '../../src/commit-hash'
import {CommitSubjectParser} from '../../src/commit-subject-parser'
import {JobId} from '../../src/job-id'

describe('CommitSubjectParser', () => {
it('should parse the message key from a commit subject', () => {
const parser = new CommitSubjectParser(
'📝🈺: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
'📝🈺: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
)

expect(parser.getMessageKey().toString()).toBe('🈺')
Expand All @@ -13,7 +14,7 @@ describe('CommitSubjectParser', () => {
it('should fail when the message key is missing in a commit subject', () => {
const fn = (): string => {
const parser = new CommitSubjectParser(
'📝: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
'📝: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
)
return parser.getMessageKey().toString()
}
Expand All @@ -23,7 +24,7 @@ describe('CommitSubjectParser', () => {

it('should parse the queue name from a commit subject', () => {
const parser = new CommitSubjectParser(
'📝🈺: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
'📝🈺: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
)

expect(parser.getQueueName().toString()).toBe('queue-name')
Expand All @@ -32,7 +33,7 @@ describe('CommitSubjectParser', () => {
it('should fail when the queue name is missing in a commit subject', () => {
const fn = (): string => {
const parser = new CommitSubjectParser(
'📝🈺: : job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
'📝🈺: : job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
)
return parser.getQueueName().toString()
}
Expand All @@ -42,7 +43,7 @@ describe('CommitSubjectParser', () => {

it('should parse the job reference (commit hash) from a commit subject', () => {
const parser = new CommitSubjectParser(
'📝🈺: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
'📝🈺: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
)

expect(parser.getJobRef().toString()).toBe(
Expand All @@ -60,7 +61,7 @@ describe('CommitSubjectParser', () => {
it('should fail when the job reference prefix exists but the reference value is invalid in a commit subject', () => {
const fn = (): string => {
const parser = new CommitSubjectParser(
'📝🈺: queue-name: job.ref.f1a69d48a01cc---af762e4ba685de7'
'📝🈺: queue-name: job.id.1 job.ref.f1a69d48a01cc---af762e4ba685de7'
)
return parser.getJobRef().toString()
}
Expand All @@ -70,18 +71,45 @@ describe('CommitSubjectParser', () => {

it('should fail when the job reference prefix exists but the reference value is missing in a commit subject', () => {
const fn = (): string => {
const parser = new CommitSubjectParser('📝🈺: queue-name: job.ref.')
const parser = new CommitSubjectParser(
'📝🈺: queue-name: job.id.1 job.ref.'
)
return parser.getJobRef().toString()
}

expect(fn).toThrowError()
})

it('should return a Null Commit when the job reference does not exist', () => {
const parser = new CommitSubjectParser('📝🈺: queue-name: NAME')
const parser = new CommitSubjectParser('📝🈺: queue-name: job.id.1 ')
const jobRef = parser.getJobRef()

expect(jobRef).toBeInstanceOf(CommitHash)
expect(jobRef.isNull()).toBe(true)
})

it('should fail when the job Id does not exist', () => {
const fn = (): JobId => {
const parser = new CommitSubjectParser(
'📝🈺: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
)
return parser.getJobId()
}

expect(fn).toThrowError()
})

it('should parse the job id from a commit subject', () => {
const parser = new CommitSubjectParser(
'📝🈺: queue-name: job.id.42 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
)

expect(parser.getJobId().toString()).toBe('42')
})

it('should parse the job id from a commit subject when there is no job ref', () => {
const parser = new CommitSubjectParser('📝🈺: queue-name: job.id.42')

expect(parser.getJobId().toString()).toBe('42')
})
})
8 changes: 4 additions & 4 deletions __tests__/unit/commit-subject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import {CommitSubjectParser} from '../../src/commit-subject-parser'
import {QueueName} from '../../src/queue-name'

function dummyCommitSubjectText(): string {
return '📝🈺: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
return '📝🈺: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
}

function dummyCommitSubjectText2(): string {
return '📝🈺: queue-name: job.ref.69062fe1104d187277aaec72ea56e8d993daca33'
return '📝🈺: queue-name: job.id.1 job.ref.69062fe1104d187277aaec72ea56e8d993daca33'
}

describe('CommitSubject', () => {
Expand All @@ -25,14 +25,14 @@ describe('CommitSubject', () => {
expect(commit.belongsToQueue(new QueueName('queue-name-two'))).toBe(false)

const commit2 = CommitSubjectParser.parseText(
'📝🈺: library aaa update: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
'📝🈺: library aaa update: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
)
expect(commit2.belongsToQueue(new QueueName('library aaa update'))).toBe(
true
)

const commit3 = CommitSubjectParser.parseText(
'standard commit: not queue commit-no prefix'
'📝🈺: other-queue: not queue job.id.1 commit-no prefix'
)
expect(commit3.belongsToQueue(new QueueName('standard commit'))).toBe(false)
})
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/committed-message-log.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {CommittedMessageLog} from '../../src/committed-message-log'
import {DefaultLogFields} from 'simple-git'

function dummyNewJobCommitSubjectText(): string {
return '📝🈺: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
return '📝🈺: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
}

function dummySimpleGitCommit(
Expand Down
6 changes: 3 additions & 3 deletions __tests__/unit/committed-message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {DefaultLogFields} from 'simple-git'
import {dummyCommitBodyText} from '../../src/__tests__/helpers'

function dummyNewJobCommitSubjectText(): string {
return '📝🈺: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
return '📝🈺: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
}

function dummyJobFinishedCommitSubjectText(): string {
return '📝✅: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
return '📝✅: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
}

describe('Queue', () => {
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('Queue', () => {
hash: 'f1a69d48a01cc130a64aeac5eaf762e4ba685de7',
date: 'not relevant',
message:
'📝INVALID: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7',
'📝INVALID: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7',
refs: 'not relevant',
body: 'not relevant',
author_name: 'not relevant',
Expand Down
Loading