Skip to content

Commit

Permalink
Split unit and integration tests.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Jun 5, 2024
1 parent 6f71b12 commit 03ff440
Show file tree
Hide file tree
Showing 24 changed files with 89 additions and 82 deletions.
1 change: 1 addition & 0 deletions tools/src/tester/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const options = {

// The fallback password must match the default password specified in .github/opensearch-cluster/docker-compose.yml
process.env.OPENSEARCH_PASSWORD = process.env.OPENSEARCH_PASSWORD ?? 'myStrongPassword123!'

const spec = (new OpenApiMerger(opts.specPath, LogLevel.error)).merge()
const runner = new TestsRunner(spec, opts.testsPath, options)
void runner.run().then(() => { _.noop() })
51 changes: 0 additions & 51 deletions tools/tests/tester/StoryEvaluator.test.ts

This file was deleted.

55 changes: 55 additions & 0 deletions tools/tests/tester/integration/StoryEvaluator.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

import { create_shared_resources, load_actual_evaluation, load_expected_evaluation } from './helpers'
import { read_yaml } from '../../../helpers'
import { type OpenAPIV3 } from 'openapi-types'

describe('Story Evaluator', () => {
beforeAll(() => {
const spec = read_yaml('tools/tests/tester/integration/fixtures/specs/indices_excerpt.yaml')
create_shared_resources(spec as OpenAPIV3.Document)

Check failure on line 17 in tools/tests/tester/integration/StoryEvaluator.test.ts

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed
})

test('passed', async () => {
const actual = await load_actual_evaluation('passed')
const expected = await load_expected_evaluation('passed')
expect(actual).toEqual(expected)
})

test('skipped', async () => {
const actual = await load_actual_evaluation('skipped')
const expected = await load_expected_evaluation('skipped')
expect(actual).toEqual(expected)
})

test('failed/not_found', async () => {
const actual = await load_actual_evaluation('failed/not_found')
const expected = await load_expected_evaluation('failed/not_found')
expect(actual).toEqual(expected)
})

test('failed/invalid_data', async () => {
const actual = await load_actual_evaluation('failed/invalid_data')
const expected = await load_expected_evaluation('failed/invalid_data')
expect(actual).toEqual(expected)
})

test('error/prologue_error', async () => {
const actual = await load_actual_evaluation('error/prologue_error')
const expected = await load_expected_evaluation('error/prologue_error')
expect(actual).toEqual(expected)
})

test('error/chapter_error', async () => {
const actual = await load_actual_evaluation('error/chapter_error')
const expected = await load_expected_evaluation('error/chapter_error')
expect(actual).toEqual(expected)
})
})

Check failure on line 55 in tools/tests/tester/integration/StoryEvaluator.test.ts

View workflow job for this annotation

GitHub Actions / test

Newline required at end of file but not found
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
* compatible open source license.
*/

import { read_yaml } from '../../helpers'
import TestsRunner from '../../src/tester/TestsRunner'
import { read_yaml } from '../../../helpers'
import TestsRunner from '../../../src/tester/TestsRunner'
import { type OpenAPIV3 } from 'openapi-types'
import { load_expected_evaluation, scrub_errors } from './helpers'

test('stories folder', async () => {
// The fallback password must match the default password specified in .github/opensearch-cluster/docker-compose.yml
process.env.OPENSEARCH_PASSWORD = process.env.OPENSEARCH_PASSWORD ?? 'myStrongPassword123!'
const spec = read_yaml('tools/tests/tester/fixtures/specs/indices_excerpt.yaml')
const runner = new TestsRunner(spec as OpenAPIV3.Document, 'tools/tests/tester/fixtures/stories', {})
const spec = read_yaml('tools/tests/tester/integration/fixtures/specs/indices_excerpt.yaml')
const runner = new TestsRunner(
spec as OpenAPIV3.Document,
'tools/tests/tester/integration/fixtures/stories', {})
const actual_evaluations = await runner.run(true) as any[]
for (const evaluation of actual_evaluations) scrub_errors(evaluation)
for (const evaluation of actual_evaluations) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
display_path: error/chapter_error.yaml
full_path: tools/tests/tester/fixtures/stories/error/chapter_error.yaml
full_path: tools/tests/tester/integration/fixtures/stories/error/chapter_error.yaml

result: ERROR
description: This story should failed due to missing info in the spec.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
display_path: error/prologue_error.yaml
full_path: tools/tests/tester/fixtures/stories/error/prologue_error.yaml
full_path: tools/tests/tester/integration/fixtures/stories/error/prologue_error.yaml

result: ERROR
description: This story should failed due to missing info in the spec.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
display_path: failed/invalid_data.yaml
full_path: tools/tests/tester/fixtures/stories/failed/invalid_data.yaml
full_path: tools/tests/tester/integration/fixtures/stories/failed/invalid_data.yaml

result: FAILED
description: This story should failed due invalid data.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
display_path: failed/not_found.yaml
full_path: tools/tests/tester/fixtures/stories/failed/not_found.yaml
full_path: tools/tests/tester/integration/fixtures/stories/failed/not_found.yaml

result: FAILED
description: This story should failed due to missing info in the spec.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
display_path: passed.yaml
full_path: tools/tests/tester/fixtures/stories/passed.yaml
full_path: tools/tests/tester/integration/fixtures/stories/passed.yaml

result: PASSED
description: This story should pass.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
display_path: skipped.yaml
full_path: "tools/tests/tester/fixtures/stories/skipped.yaml"
full_path: "tools/tests/tester/integration/fixtures/stories/skipped.yaml"

result: SKIPPED
description: This story should be skipped.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
* compatible open source license.
*/

import ChapterReader from '../../src/tester/ChapterReader'
import SpecParser from '../../src/tester/SpecParser'
import SchemaValidator from '../../src/tester/SchemaValidator'
import SharedResources from '../../src/tester/SharedResources'
import ChapterReader from '../../../src/tester/ChapterReader'
import SpecParser from '../../../src/tester/SpecParser'
import SchemaValidator from '../../../src/tester/SchemaValidator'
import SharedResources from '../../../src/tester/SharedResources'
import { type OpenAPIV3 } from 'openapi-types'
import YAML from 'yaml'
import type { StoryEvaluation } from '../../src/tester/types/eval.types'
import type { Story } from '../../src/tester/types/story.types'
import { read_yaml } from '../../helpers'
import StoryEvaluator from '../../src/tester/StoryEvaluator'
import type { StoryEvaluation } from '../../../src/tester/types/eval.types'
import type { Story } from '../../../src/tester/types/story.types'
import { read_yaml } from '../../../helpers'
import StoryEvaluator from '../../../src/tester/StoryEvaluator'

export function create_shared_resources (spec: any): void {
// The fallback password must match the default password specified in .github/opensearch-cluster/docker-compose.yml
Expand All @@ -34,21 +34,21 @@ export function print_yaml (obj: any): void {
export function scrub_errors (obj: any): void {
for (const key in obj) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
if (key === 'error') obj[key] = obj[key].message
if (key === 'error') obj[key] = obj[key]?.message
else if (typeof obj[key] === 'object') scrub_errors(obj[key])
}
}

export async function load_expected_evaluation (name: string, exclude_full_path: boolean = false): Promise<any> {
const expected = read_yaml(`tools/tests/tester/fixtures/evals/${name}.yaml`)
const expected = read_yaml(`tools/tests/tester/integration/fixtures/evals/${name}.yaml`)
if (exclude_full_path) delete expected.full_path
return expected
}

export async function load_actual_evaluation (name: string): Promise<StoryEvaluation> {
const story: Story = read_yaml(`tools/tests/tester/fixtures/stories/${name}.yaml`)
const story: Story = read_yaml(`tools/tests/tester/integration/fixtures/stories/${name}.yaml`)
const display_path = `${name}.yaml`
const full_path = `tools/tests/tester/fixtures/stories/${name}.yaml`
const full_path = `tools/tests/tester/integration/fixtures/stories/${name}.yaml`
const actual = await new StoryEvaluator({ display_path, full_path, story }).evaluate()
scrub_errors(actual)
return actual
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* compatible open source license.
*/

import { overall_result } from '../../src/tester/helpers'
import { type Evaluation, Result } from '../../src/tester/types/eval.types'
import { overall_result } from '../../../src/tester/helpers'
import { type Evaluation, Result } from '../../../src/tester/types/eval.types'

function e (...results: Result[]): Evaluation[] {
return results.map(result => ({ result }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* compatible open source license.
*/

import * as ansi from '../../src/tester/Ansi'
import * as ansi from '../../../src/tester/Ansi'

test('b', () => {
expect(ansi.b('xyz')).toEqual('\x1b[1mxyz\x1b[0m')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { spawnSync } from 'child_process'
import * as ansi from '../../src/tester/Ansi'
import * as ansi from '../../../src/tester/Ansi'
import * as path from 'path'

const spec = (args: string[]): any => {
Expand All @@ -30,28 +30,28 @@ test('--invalid', async () => {
})

test('displays story filename', async () => {
expect(spec(['--tests', 'tools/tests/tester/fixtures/empty_story']).stdout).toContain(
expect(spec(['--tests', 'tools/tests/tester/unit/fixtures/empty_story']).stdout).toContain(
`${ansi.green('PASSED ')} ${ansi.cyan(ansi.b('empty.yaml'))}`
)
})

test('displays story description', async () => {
expect(spec(['--tests', 'tools/tests/tester/fixtures/empty_with_description.yaml']).stdout).toContain(
expect(spec(['--tests', 'tools/tests/tester/unit/fixtures/empty_with_description.yaml']).stdout).toContain(
`${ansi.green('PASSED ')} ${ansi.cyan(ansi.b('A story with no beginning or end.'))}`
)
})

test.todo('--tab-width')

test('--dry-run', async () => {
const test_yaml = 'tools/tests/tester/fixtures/empty_with_all_the_parts.yaml'
const test_yaml = 'tools/tests/tester/unit/fixtures/empty_with_all_the_parts.yaml'
const s = spec(['--dry-run', '--tests', test_yaml]).stdout
const full_path = path.join(__dirname, '../../../' + test_yaml)
const full_path = path.join(__dirname, '../../../../' + test_yaml)
expect(s).toEqual(`${ansi.yellow('SKIPPED')} ${ansi.cyan(ansi.b('A story with all its parts.'))} ${ansi.gray('(' + full_path + ')')}\n\n\n`)
})

test('--dry-run --verbose', async () => {
const s = spec(['--dry-run', '--verbose', '--tests', 'tools/tests/tester/fixtures/empty_with_all_the_parts.yaml']).stdout
const s = spec(['--dry-run', '--verbose', '--tests', 'tools/tests/tester/unit/fixtures/empty_with_all_the_parts.yaml']).stdout
expect(s).toContain(`${ansi.yellow('SKIPPED')} ${ansi.cyan(ansi.b('A story with all its parts.'))}`)
expect(s).toContain(`${ansi.yellow('SKIPPED')} CHAPTERS`)
expect(s).toContain(`${ansi.yellow('SKIPPED')} EPILOGUES`)
Expand Down

0 comments on commit 03ff440

Please sign in to comment.