Skip to content

Commit

Permalink
Moved helpers into src.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Jun 7, 2024
1 parent d7a699f commit ac9939a
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 14 deletions.
2 changes: 1 addition & 1 deletion tools/src/OpenSearchHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { Option } from '@commander-js/extra-typings'
import axios, { type AxiosInstance, type AxiosRequestConfig, type AxiosResponse } from 'axios'
import * as https from 'node:https'
import { sleep } from '../helpers'
import { sleep } from './helpers'

const DEFAULT_URL = 'https://localhost:9200'
const DEFAULT_USER = 'admin'
Expand Down
2 changes: 1 addition & 1 deletion tools/src/coverage/CoverageCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { type OpenAPIV3 } from 'openapi-types'
import { HTTP_METHODS, read_yaml, write_json } from '../../helpers'
import { HTTP_METHODS, read_yaml, write_json } from '../helpers'

export default class CoverageCalculator {
private readonly _cluster_spec: OpenAPIV3.Document
Expand Down
2 changes: 1 addition & 1 deletion tools/src/dump-cluster-spec/dump-cluster-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { Command, Option } from '@commander-js/extra-typings'
import { resolve } from 'path'
import * as process from 'node:process'
import { write_yaml } from '../../helpers'
import { write_yaml } from '../helpers'
import {
get_opensearch_opts_from_cli,
OPENSEARCH_INSECURE_OPTION,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tools/src/linter/components/NamespaceFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { type OperationSpec, type ValidationError } from 'types'
import OperationGroup from './OperationGroup'
import _ from 'lodash'
import Operation from './Operation'
import { resolve_ref, sort_by_keys } from '../../../helpers'
import { resolve_ref, sort_by_keys } from '../../helpers'
import FileValidator from './base/FileValidator'

const HTTP_METHODS = ['get', 'head', 'post', 'put', 'patch', 'delete', 'options', 'trace']
Expand Down
2 changes: 1 addition & 1 deletion tools/src/linter/components/SupersededOperationsFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import _ from 'lodash'
import { sort_array_by_keys } from '../../../helpers'
import { sort_array_by_keys } from '../../helpers'
import FileValidator from './base/FileValidator'
import { type ValidationError } from 'types'
import { type OpenAPIV3 } from 'openapi-types'
Expand Down
2 changes: 1 addition & 1 deletion tools/src/linter/components/base/FileValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import ValidatorBase from './ValidatorBase'
import { type ValidationError } from 'types'
import { type OpenAPIV3 } from 'openapi-types'
import { read_yaml } from '../../../../helpers'
import { read_yaml } from '../../../helpers'
import AJV from 'ajv'
import addFormats from 'ajv-formats'

Expand Down
2 changes: 1 addition & 1 deletion tools/src/merger/GlobalParamsGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import { type OpenAPIV3 } from 'openapi-types'
import _ from 'lodash'
import { read_yaml } from '../../helpers'
import { read_yaml } from '../helpers'

export default class GlobalParamsGenerator {
global_params: Record<string, OpenAPIV3.ParameterObject>
Expand Down
2 changes: 1 addition & 1 deletion tools/src/merger/OpenApiMerger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { type OpenAPIV3 } from 'openapi-types'
import fs from 'fs'
import _ from 'lodash'
import { read_yaml, write_yaml } from '../../helpers'
import { read_yaml, write_yaml } from '../helpers'
import SupersededOpsGenerator from './SupersededOpsGenerator'
import GlobalParamsGenerator from './GlobalParamsGenerator'
import { Logger } from '../Logger'
Expand Down
2 changes: 1 addition & 1 deletion tools/src/merger/OpenDistro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { type HttpVerb, type OperationPath, type SupersededOperationMap } from 'types'
import { read_yaml, write_yaml } from '../../helpers'
import { read_yaml, write_yaml } from '../helpers'

// One-time script to generate _superseded_operations.yaml file for OpenDistro
// Keeping this for now in case we need to update the file in the near future. Can be removed after a few months.
Expand Down
2 changes: 1 addition & 1 deletion tools/src/merger/SupersededOpsGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import { type OperationSpec, type SupersededOperationMap } from 'types'
import _ from 'lodash'
import { read_yaml } from '../../helpers'
import { read_yaml } from '../helpers'
import { type Logger } from '../Logger'

export default class SupersededOpsGenerator {
Expand Down
2 changes: 1 addition & 1 deletion tools/src/tester/OperationLocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { type OpenAPIV3 } from 'openapi-types'
import { resolve_ref } from '../../helpers'
import { resolve_ref } from '../helpers'
import { type Chapter } from './types/story.types'
import { type ParsedOperation } from './types/spec.types'
import _ from 'lodash'
Expand Down
2 changes: 1 addition & 1 deletion tools/src/tester/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type StoryEvaluator from './StoryEvaluator'
import { type StoryFile } from './StoryEvaluator'
import fs from 'fs'
import { type Story } from './types/story.types'
import { read_yaml } from '../../helpers'
import { read_yaml } from '../helpers'
import { Result, type StoryEvaluation } from './types/eval.types'
import { type ResultLogger } from './ResultLogger'
import { basename, resolve } from 'path'
Expand Down
2 changes: 1 addition & 1 deletion tools/src/tester/_generate_story_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import * as js2ts from 'json-schema-to-typescript'
import fs from 'fs'
import { read_yaml } from '../../helpers'
import { read_yaml } from '../helpers'

const schema = read_yaml('json_schemas/test_story.schema.yaml')
void js2ts.compile(schema, 'Story',
Expand Down
28 changes: 28 additions & 0 deletions tools/tests/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 { sort_array_by_keys } from '../src/helpers'

describe('helpers', () => {
describe('sort_array_by_keys', () => {
test('sorts arrays of string', () => {
expect(sort_array_by_keys([])).toEqual([])
expect(sort_array_by_keys(['GET', 'POST'], ['GET', 'POST'])).toEqual(['GET', 'POST'])
expect(sort_array_by_keys(['GET', 'POST'], ['POST', 'GET'])).toEqual(['POST', 'GET'])
expect(sort_array_by_keys(['GET', 'POST'], ['POST', 'GET', 'DELETE'])).toEqual(['POST', 'GET'])
expect(sort_array_by_keys(['DELETE', 'POST', 'GET'], ['POST', 'GET', 'DELETE'])).toEqual(['POST', 'GET', 'DELETE'])
})

test('does not modify the original object', () => {
const arr = ['GET', 'POST']
expect(sort_array_by_keys(arr, ['POST', 'GET'])).toEqual(['POST', 'GET'])
expect(arr).toEqual(['GET', 'POST'] )
})
})
})
2 changes: 1 addition & 1 deletion tools/tests/tester/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import YAML from 'yaml'
import type { ChapterEvaluation, Evaluation, StoryEvaluation } from '../../src/tester/types/eval.types'
import { read_yaml } from '../../helpers'
import { read_yaml } from 'helpers'
import StoryEvaluator from '../../src/tester/StoryEvaluator'
import OperationLocator from '../../src/tester/OperationLocator'
import ChapterReader from '../../src/tester/ChapterReader'
Expand Down

0 comments on commit ac9939a

Please sign in to comment.