Skip to content

Commit

Permalink
Move docker-compose into the test suite path.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <dblock@amazon.com>
  • Loading branch information
dblock committed Aug 7, 2024
1 parent d4a0c05 commit b4b5931
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
run: npm ci

- name: Run OpenSearch Cluster
working-directory: .github/opensearch-cluster/${{ matrix.entry.tests || 'default' }}
working-directory: tests/${{ matrix.entry.tests || 'default' }}
run: docker compose up -d

- name: Get Container ID
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-tools-integ.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
uses: actions/checkout@v4

- name: Run OpenSearch Cluster
working-directory: .github/opensearch-cluster/default
working-directory: tests/default
run: |
docker compose up -d
sleep 15
Expand Down
4 changes: 2 additions & 2 deletions TESTING_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Set up an OpenSearch cluster with Docker:
(Replace `<<your_password>>` with your desired password. If not provided, the default password inside the `docker-compose.yml` file will be used.)
```bash
export OPENSEARCH_PASSWORD=<<your_password>>
cd .github/opensearch-cluster/default
cd tests/default
docker compose up -d
```
Expand Down Expand Up @@ -71,7 +71,7 @@ curl -k -X PUT --user "admin:${OPENSEARCH_PASSWORD}" https://localhost:9200/_clu
The spec tests reside in the [tests/](tests) directory. Tests are organized in suites ([default](tests/default/), etc.), and subsequently in folders that match [namespaces](spec/namespaces). For example, tests for APIs defined in [spec/namespaces/indices.yaml](spec/namespaces/indices.yaml) can be found in [tests/default/indices/index.yaml](tests/default/indices/index.yaml) (for `/{index}`), and [tests/default/indices/doc.yaml](tests/default/indices/doc.yaml) (for `/{index}/_doc`).
Additional suites require custom configuration that is defined in a separate `docker-compose.yml`. For example [.github/opensearch-cluster/plugins/index_state_management/docker-compose.yml](.github/opensearch-cluster/plugins/index_state_management/docker-compose.yml) uses a custom setting of `plugins.index_state_management.job_interval=1` to cause the `/_nodes` API to return plugin information tested in [tests/plugins/index_state_management/nodes/plugins/index_state_management.yaml](tests/plugins/index_state_management/nodes/plugins/index_state_management.yaml).
Additional suites require custom configuration that is defined in a separate `docker-compose.yml`. For example [tests/plugins/index_state_management/docker-compose.yml](tests/plugins/index_state_management/docker-compose.yml) uses a custom setting of `plugins.index_state_management.job_interval=1` to cause the `/_nodes` API to return plugin information tested in [tests/plugins/index_state_management/nodes/plugins/index_state_management.yaml](tests/plugins/index_state_management/nodes/plugins/index_state_management.yaml).
Each yaml file in the tests directory represents a test story that tests a collection of related operations.
Expand Down
File renamed without changes.
22 changes: 18 additions & 4 deletions tools/src/tester/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ import { basename, resolve } from 'path'
import type StoryValidator from "./StoryValidator";
import { OpenSearchHttpClient } from 'OpenSearchHttpClient'
import * as ansi from './Ansi'
import _ from 'lodash'

const EXCLUDED_FILES = [
'docker-compose.yml'
]

export default class TestRunner {
private readonly _http_client: OpenSearchHttpClient
private readonly _story_validator: StoryValidator
private readonly _story_evaluator: StoryEvaluator
private readonly _result_logger: ResultLogger
private readonly _story_files: Record<string, StoryFile[]> = {}

constructor (http_client: OpenSearchHttpClient, story_validator: StoryValidator, story_evaluator: StoryEvaluator, result_logger: ResultLogger) {
this._http_client = http_client
Expand All @@ -34,7 +40,7 @@ export default class TestRunner {

async run (story_path: string, version?: string, dry_run: boolean = false): Promise<{ results: StoryEvaluations, failed: boolean }> {
let failed = false
const story_files = this.#sort_story_files(this.#collect_story_files(resolve(story_path), '', ''))
const story_files = this.story_files(story_path)
const results: StoryEvaluations = { evaluations: [] }

if (!dry_run) {
Expand All @@ -53,6 +59,12 @@ export default class TestRunner {
return { results, failed }
}

story_files(story_path: string): StoryFile[] {
if (this._story_files[story_path] !== undefined) return this._story_files[story_path]
this._story_files[story_path] = this.#sort_story_files(this.#collect_story_files(resolve(story_path), '', ''))
return this._story_files[story_path]
}

#collect_story_files (folder: string, file: string, prefix: string): StoryFile[] {
const path = file === '' ? folder : `${folder}/${file}`
const next_prefix = prefix === '' ? file : `${prefix}/${file}`
Expand All @@ -64,9 +76,11 @@ export default class TestRunner {
story
}]
} else {
return fs.readdirSync(path).flatMap(next_file => {
return this.#collect_story_files(path, next_file, next_prefix)
})
return _.compact(fs.readdirSync(path).flatMap(next_file => {
if (!EXCLUDED_FILES.includes(next_file)) {
return this.#collect_story_files(path, next_file, next_prefix)
}
}))
}
}

Expand Down
10 changes: 10 additions & 0 deletions tools/tests/tester/integ/TestRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,13 @@ test('stories folder', async () => {
const expected_evaluations = [passed, chapter_error, output_error, prologue_error, invalid_data, not_found, skipped]
expect(actual_evaluations).toEqual(expected_evaluations)
})

describe('story_files', () => {
const { test_runner } = construct_tester_components('tools/tests/tester/fixtures/specs/excerpt.yaml')

test('does not contain docker-compose.yml', () => {
expect(test_runner.story_files('tests/plugins/index_state_management').map(
story_file => story_file.display_path
)).not.toContain('nodes/plugins/docker-compose.yml')
})
})

0 comments on commit b4b5931

Please sign in to comment.