From 20bcdafcec32e33a8abb26980456acbb92d96751 Mon Sep 17 00:00:00 2001 From: Tianle Huang <60111637+tianleh@users.noreply.github.com> Date: Wed, 9 Nov 2022 17:51:59 -0800 Subject: [PATCH] fix lint and introduce a link checker workflow (#387) * fix lint Signed-off-by: Tianle Huang * run lint Signed-off-by: Tianle Huang * add .lycheeexclude Signed-off-by: Tianle Huang * update workflow Signed-off-by: Tianle Huang * fix Signed-off-by: Tianle Huang * test fail Signed-off-by: Tianle Huang * update Signed-off-by: Tianle Huang Signed-off-by: Tianle Huang --- .github/workflows/lint_checker.yml | 30 +++++++++++++++++ .../aggregation_view.js | 33 +++++++++---------- cypress/utils/commands.js | 8 ++--- .../security-dashboards-plugin/commands.js | 2 +- .../security-dashboards-plugin/constants.js | 10 +++--- 5 files changed, 55 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/lint_checker.yml diff --git a/.github/workflows/lint_checker.yml b/.github/workflows/lint_checker.yml new file mode 100644 index 000000000..aa2cb3d2e --- /dev/null +++ b/.github/workflows/lint_checker.yml @@ -0,0 +1,30 @@ +# Copyright OpenSearch Contributors +# SPDX-License-Identifier: Apache-2.0 + +name: Lint Checker +on: + pull_request: + branches: + - main + - dev-* +jobs: + tests: + name: Lint Checker + runs-on: ubuntu-latest + env: + # prevents extra Cypress installation progress messages + CI: 1 + # avoid warnings like "tput: No value for $TERM and no -T specified" + TERM: xterm + steps: + - name: Checkout cypress-test + uses: actions/checkout@v2 + with: + repository: ${{github.repository}} + path: cypress-test + - name: Run Lint + working-directory: cypress-test + run: | + echo "VERSION=$(yarn --silent pkg-version)" >> $GITHUB_ENV + npm install + yarn lint diff --git a/cypress/integration/plugins/security-dashboards-plugin/aggregation_view.js b/cypress/integration/plugins/security-dashboards-plugin/aggregation_view.js index f8c9b9c44..098c767e9 100644 --- a/cypress/integration/plugins/security-dashboards-plugin/aggregation_view.js +++ b/cypress/integration/plugins/security-dashboards-plugin/aggregation_view.js @@ -3,14 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { - SAVED_OBJECTS_PATH, -} from '../../../utils/dashboards/constants'; +import { SAVED_OBJECTS_PATH } from '../../../utils/dashboards/constants'; -import { - ADMIN_AUTH, - CURRENT_TENANT, - } from '../../../utils/commands'; +import { ADMIN_AUTH, CURRENT_TENANT } from '../../../utils/commands'; import tenantDescription from '../../../fixtures/plugins/security-dashboards-plugin/tenants/testTenant'; import testUsersSetUp from '../../../fixtures/plugins/security-dashboards-plugin/users/testUser'; @@ -27,7 +22,7 @@ const userName2 = 'test2'; const password = 'password'; const roleName1 = 'roleWithTest'; const roleName2 = 'roleWithoutTest'; -const kibanaRoleName = 'kibana_user' +const kibanaRoleName = 'kibana_user'; if (Cypress.env('SECURITY_ENABLED') && Cypress.env('AGGREGATION_VIEW')) { describe('Saved objects table test', () => { @@ -41,13 +36,15 @@ if (Cypress.env('SECURITY_ENABLED') && Cypress.env('AGGREGATION_VIEW')) { title: 's*', timeFieldName: 'timestamp', }); - cy.createIndexPattern('index-pattern2', { - title: 'se*', - timeFieldName: 'timestamp', - }, - indexPatternTenantHeaderSetUp + cy.createIndexPattern( + 'index-pattern2', + { + title: 'se*', + timeFieldName: 'timestamp', + }, + indexPatternTenantHeaderSetUp ); - + cy.createInternalUser(userName1, testUsersSetUp); cy.createInternalUser(userName2, testUsersSetUp); @@ -60,7 +57,7 @@ if (Cypress.env('SECURITY_ENABLED') && Cypress.env('AGGREGATION_VIEW')) { cy.wait(300000); }); - + it('should check the saved objects as global tenant', () => { CURRENT_TENANT.newTenant = 'global'; cy.visit(SAVED_OBJECTS_PATH); @@ -86,7 +83,7 @@ if (Cypress.env('SECURITY_ENABLED') && Cypress.env('AGGREGATION_VIEW')) { cy.contains('a', 'se*'); }); - it('should login as test1 and check saved object', () =>{ + it('should login as test1 and check saved object', () => { CURRENT_TENANT.newTenant = 'private'; ADMIN_AUTH.newUser = userName1; ADMIN_AUTH.newPassword = password; @@ -95,13 +92,13 @@ if (Cypress.env('SECURITY_ENABLED') && Cypress.env('AGGREGATION_VIEW')) { cy.url().should((url) => { expect(url).to.contain('/management'); }); - + cy.wait(5000); cy.contains('a', 'se*'); cy.contains('a', 's*').should('not.exist'); }); - it('should login as test2 and check saved object', () =>{ + it('should login as test2 and check saved object', () => { CURRENT_TENANT.newTenant = 'private'; ADMIN_AUTH.newUser = userName2; ADMIN_AUTH.newPassword = password; diff --git a/cypress/utils/commands.js b/cypress/utils/commands.js index f974c1960..21fdafba1 100644 --- a/cypress/utils/commands.js +++ b/cypress/utils/commands.js @@ -9,7 +9,7 @@ export const ADMIN_AUTH = { username: Cypress.env('username'), password: Cypress.env('password'), set newUser(changedUsername) { - this.username = changedUsername + this.username = changedUsername; }, set newPassword(changedPassword) { this.password = changedPassword; @@ -17,11 +17,11 @@ export const ADMIN_AUTH = { }; export const CURRENT_TENANT = { - defaultTenant:'private', + defaultTenant: 'private', set newTenant(changedTenant) { - this.defaultTenant = changedTenant; + this.defaultTenant = changedTenant; }, -} +}; export const supressNoRequestOccurred = () => { cy.on('fail', (err) => { diff --git a/cypress/utils/plugins/security-dashboards-plugin/commands.js b/cypress/utils/plugins/security-dashboards-plugin/commands.js index 4d432210b..a0d901af0 100644 --- a/cypress/utils/plugins/security-dashboards-plugin/commands.js +++ b/cypress/utils/plugins/security-dashboards-plugin/commands.js @@ -11,7 +11,7 @@ import { SEC_API } from '../../constants'; ***************************** */ - Cypress.Commands.add('createTenant', (tenantID, tenantJson) => { +Cypress.Commands.add('createTenant', (tenantID, tenantJson) => { cy.request( 'PUT', `${Cypress.env('openSearchUrl')}${SEC_API.TENANTS_BASE}/${tenantID}`, diff --git a/cypress/utils/plugins/security-dashboards-plugin/constants.js b/cypress/utils/plugins/security-dashboards-plugin/constants.js index b065c523a..be30a4653 100644 --- a/cypress/utils/plugins/security-dashboards-plugin/constants.js +++ b/cypress/utils/plugins/security-dashboards-plugin/constants.js @@ -12,8 +12,8 @@ //Security API Constants export const SEC_API_PREFIX = '/_plugins/_security/api'; export const SEC_API = { - TENANTS_BASE: `${SEC_API_PREFIX}/tenants`, - INTERNALUSERS_BASE: `${SEC_API_PREFIX}/internalusers`, - ROLE_BASE: `${SEC_API_PREFIX}/roles`, - ROLE_MAPPING_BASE: `${SEC_API_PREFIX}/rolesmapping`, -} + TENANTS_BASE: `${SEC_API_PREFIX}/tenants`, + INTERNALUSERS_BASE: `${SEC_API_PREFIX}/internalusers`, + ROLE_BASE: `${SEC_API_PREFIX}/roles`, + ROLE_MAPPING_BASE: `${SEC_API_PREFIX}/rolesmapping`, +};