Skip to content

Commit

Permalink
power up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GantMan committed Feb 4, 2018
1 parent e39526e commit d7037d7
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 56 deletions.
80 changes: 38 additions & 42 deletions __tests__/command_helpers/__snapshots__/solidarityReport.ts.snap
Original file line number Diff line number Diff line change
@@ -1,49 +1,45 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`solidarityReport structure the basic function generates the Result object 1`] = `
Object {
"addCLI": [Function],
"basicInfo": Array [
Array [
"System Basics",
"Value",
],
Array [
"OS",
"macOS High Sierra 10.13.3",
],
Array [
"CPU",
"x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz",
],
],
"cliRules": Array [
Array [
"Binary",
"Location",
"Version",
"Desired",
],
exports[`solidarityReport structure the basic function generates the Result object 1`] = `[Function]`;

exports[`solidarityReport structure the basic function generates the Result object 2`] = `
Array [
Array [
"Binary",
"Location",
"Version",
"Desired",
],
"envRules": Array [
Array [
"Environment Var",
"Value",
],
]
`;

exports[`solidarityReport structure the basic function generates the Result object 3`] = `undefined`;

exports[`solidarityReport structure the basic function generates the Result object 4`] = `
Array [
Array [
"Environment Var",
"Value",
],
"filesystemRules": Array [
Array [
"Location",
"Type",
"Exists",
],
]
`;

exports[`solidarityReport structure the basic function generates the Result object 5`] = `
Array [
Array [
"Location",
"Type",
"Exists",
],
"shellRules": Array [
Array [
"Command",
"Pattern",
"Matches",
],
]
`;

exports[`solidarityReport structure the basic function generates the Result object 6`] = `
Array [
Array [
"Command",
"Pattern",
"Matches",
],
}
]
`;
35 changes: 23 additions & 12 deletions __tests__/command_helpers/reviewRule.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import reviewRule from '../../src/extensions/functions/reviewRule'
import { SolidarityRunContext, SolidarityReportResults } from '../../src/types'
import { createReport } from '../../src/extensions/functions/solidarityReport'
const examplePlugin = require('examplePlugin')
let mockContext: SolidarityRunContext
let reportResults: SolidarityReportResults
describe('reviewRule', () => {
beforeEach(() => {
// fresh mock context
mockContext = require('mockContext')
mockContext = examplePlugin(require('mockContext'))
reportResults = createReport(mockContext)
})

Expand Down Expand Up @@ -60,24 +61,34 @@ describe('reviewRule', () => {
})
})

// TODO: Custom rule test
// describe('when rule: custom', () => {
// test('rule gets added', async () => {
// const rule = ['CUSTOM', [{ rule: 'custom', plugin: 'plugin', name: 'name' }]]
// Custom rule test
describe('when rule: custom', () => {
test('rule gets added', async () => {
const rule = ['CUSTOM', [{ rule: 'custom', plugin: 'Example Plugin', name: 'checkThing' }]]

expect(reportResults.cliRules.length).toBe(1)
const result = await reviewRule(rule, reportResults, mockContext)
// CUSTOM rule (which adds CLI report) was added
expect(reportResults.cliRules.length).toBe(2)
})

// const result = await reviewRule(rule, reportResults, mockContext)
// // CUSTOM rule was added
// expect(reportResults.customRules.length).toBe(2)
// })
// })
test('does nothing when no report exists', async () => {
const rule = ['CUSTOM', [{ rule: 'custom', plugin: 'Example Plugin', name: 'checkSecondThing' }]]

expect(reportResults.cliRules.length).toBe(1)
const result = await reviewRule(rule, reportResults, mockContext)
// should not change rules
expect(reportResults.cliRules.length).toBe(1)
})
})

describe('when rule: unknown', () => {
test('rule gets added', async () => {
const rule = ['UNKNOWN', [{ rule: 'UNKNOWN', command: 'ls', match: '.+' }]]

const numErrors = mockContext.print.error.mock.calls.length
const result = await reviewRule(rule, reportResults, mockContext)
// Failure in a specific rule
expect(mockContext.print.error.mock.calls.length).toBe(1)
expect(mockContext.print.error.mock.calls.length).toBe(numErrors + 1)
})
})
})
8 changes: 7 additions & 1 deletion __tests__/command_helpers/solidarityReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ let reportResults: SolidarityReportResults
describe('solidarityReport structure', () => {
test('the basic function generates the Result object', () => {
let report = createReport(context)
expect(report).toMatchSnapshot()
// Check everything but system stuff against snapshots
expect(report.addCLI).toMatchSnapshot()
expect(report.cliRules).toMatchSnapshot()
expect(report.customRules).toMatchSnapshot()
expect(report.envRules).toMatchSnapshot()
expect(report.filesystemRules).toMatchSnapshot()
expect(report.shellRules).toMatchSnapshot()
})
})
2 changes: 1 addition & 1 deletion src/extensions/functions/reviewRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = async (
break
case 'custom':
const customPluginRule = findPluginInfo(rule, context)
if (customPluginRule.success) {
if (customPluginRule.success && customPluginRule.plugin.report) {
// let plugin update the report
customPluginRule.plugin.report(rule, context, report)
} else {
Expand Down

0 comments on commit d7037d7

Please sign in to comment.