Add mocks to tests

This commit is contained in:
Nick Cipollo
2019-08-26 20:35:39 -04:00
parent 4e291a9639
commit 028c2af361
7 changed files with 137 additions and 36 deletions

View File

@@ -2,7 +2,19 @@ import * as core from '@actions/core';
import { Context } from "@actions/github/lib/context";
import { readFileSync, statSync } from 'fs';
export class Inputs {
export interface Inputs {
readonly artifact: string
readonly artifactContentType: string
readonly artifactContentLength: number
readonly body: string
readonly commit: string
readonly draft: boolean
readonly name: string
readonly tag: string
readonly token: string
}
export class CoreInputs implements Inputs {
private context: Context
constructor(context: Context) {
@@ -26,22 +38,27 @@ export class Inputs {
return statSync(this.artifact).size
}
get body(): string {
const body = core.getInput('body')
if (body) {
return body
}
const bodyFile = core.getInput('bodyFile')
if (bodyFile) {
return this.stringFromFile(bodyFile)
}
return ''
}
get commit(): string {
return core.getInput('commit')
}
get description(): string {
const description = core.getInput('description')
if (description) {
return description
}
const descriptionFile = core.getInput('descriptionFile')
if (descriptionFile) {
return this.stringFromFile(descriptionFile)
}
return ''
get draft(): boolean {
const draft = core.getInput('draft')
return draft == 'true'
}
get name(): string {
@@ -72,7 +89,7 @@ export class Inputs {
return core.getInput('token', { required: true })
}
private stringFromFile(path: string): string {
stringFromFile(path: string): string {
return readFileSync(path, 'utf-8')
}
}