Skip to content

Commit

Permalink
use bash-tools-framework pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
fchastanet committed Nov 11, 2023
1 parent 73e61e1 commit cbee165
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 97 deletions.
101 changes: 23 additions & 78 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ repos:
fail_fast: true
stages: [commit]

- repo: local
hooks:
- id: fixShebangExecutionBit
name: fixShebangExecutionBit
entry: bash -c './bin/findShebangFiles chmod +x'
language: system
always_run: true
fail_fast: true
stages: [commit]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand Down Expand Up @@ -76,31 +66,26 @@ repos:
- id: prettier
stages: [commit]

- repo: local
- repo: https://github.com/fchastanet/bash-tools-framework
rev: 1.0.4
hooks:
- id: fixShebangExecutionBit
- id: frameworkLinter
args:
[
--expected-warnings-count,
'6',
--format,
plain,
--theme,
default-force,
]
- id: shellcheckLint
name: shellcheckLint
entry: bash -c './bin/shellcheckLint --staged -f tty'
language: system
always_run: true
fail_fast: true
stages: [commit]

- repo: local
hooks:
- id: frameworkLint
name: frameworkLint
entry: |
bash -c './bin/frameworkLint --verbose --expected-warnings-count 6'
language: system
always_run: true
fail_fast: true
stages: [commit]

- repo: local
hooks:
- id: build-sh-files
name: build-sh-files
- id: buildShFiles
name: build sh files
entry: bash -c './bin/buildBinFiles --ignore-missing'
language: system
always_run: true
Expand All @@ -110,60 +95,20 @@ repos:

- repo: local
hooks:
- id: build-doc-files
name: build-doc-files
- id: buildDocFiles
name: build doc files
entry: bash -c './bin/doc'
language: system
always_run: true
require_serial: true
fail_fast: true
stages: [push]

- repo: local
hooks:
- id: run-unit-tests
name: run-unit-tests
entry: bash -c './bin/test -r src -j 1'
language: system
always_run: true
require_serial: true
fail_fast: true
stages: [commit]

- repo: local
hooks:
- id: megalinter-check-version
name: megalinter-check-version
language: system
entry: ./bin/megalinter
args:
[
--image,
'oxsecurity/megalinter-terraform:v7.5.0',
--check-megalinter-version,
]
pass_filenames: false
always_run: true
fail_fast: true
stages: [push]

- repo: local
- repo: https://github.com/fchastanet/bash-tools-framework
rev: 1.0.4
hooks:
- id: runUnitTests
- id: plantuml
- id: megalinterCheckVersion
- id: megalinter
name: megalinter
language: system
entry: ./bin/megalinter
args:
[
--image,
'oxsecurity/megalinter-terraform:v7.5.0',
--config-file,
'.mega-linter-light.yml',
--fix,
]
pass_filenames: false
require_serial: true
always_run: true
fail_fast: true
verbose: true
stages: [push]
- id: megalinterGithubAction
11 changes: 8 additions & 3 deletions src/_binaries/DbImport/dbImportProfile.bats
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ function Database::dbImportProfile::remote_db_fully_functional_default_ratio { #
assert_output --partial "Profile generated - 1/3 tables bigger than 70% of max table size (29MB) automatically excluded"
diff >&3 "${HOME}/tableSizeQuery.sql" "${BATS_TEST_DIRNAME}/testsData/expectedDbImportProfileTableListQuery.sql"
[[ -f "${HOME}/.bash-tools/dbImportProfiles/auto_default.local_fromDb.sh" ]]
[[ "$(md5sum "${HOME}/.bash-tools/dbImportProfiles/auto_default.local_fromDb.sh" | awk '{ print $1 }')" == "$(md5sum "${BATS_TEST_DIRNAME}/testsData/auto_default.local_fromDb_70.sh" | awk '{ print $1 }')" ]]
diff -u "${HOME}/.bash-tools/dbImportProfiles/auto_default.local_fromDb.sh" \
"${BATS_TEST_DIRNAME}/testsData/auto_default.local_fromDb_70.sh"
}

function Database::dbImportProfile::remote_db_fully_functional_ratio_20 { #@test
Expand All @@ -114,10 +115,14 @@ function Database::dbImportProfile::remote_db_fully_functional_ratio_20 { #@test
run "${binDir}/dbImportProfile" --verbose -f default.local -r 20 fromDb 2>&1

[[ -f "${HOME}/tableSizeQuery.sql" ]]
assert_output --partial "Profile generated - 2/3 tables bigger than 20% of max table size (29MB) automatically excluded"
assert_lines_count 3
assert_line --index 0 --partial "INFO - Using from dsn"
assert_line --index 1 --partial "Profile generated - 2/3 tables bigger than 20% of max table size (29MB) automatically excluded"
assert_line --index 2 --partial "INFO - File saved in"

[[ "$(md5sum "${HOME}/tableSizeQuery.sql" | awk '{ print $1 }')" == "$(md5sum "${BATS_TEST_DIRNAME}/testsData/expectedDbImportProfileTableListQuery.sql" | awk '{ print $1 }')" ]]

[[ -f "${HOME}/.bash-tools/dbImportProfiles/auto_default.local_fromDb.sh" ]]
[[ "$(md5sum "${HOME}/.bash-tools/dbImportProfiles/auto_default.local_fromDb.sh" | awk '{ print $1 }')" == "$(md5sum "${BATS_TEST_DIRNAME}/testsData/auto_default.local_fromDb_20.sh" | awk '{ print $1 }')" ]]
diff -u "${HOME}/.bash-tools/dbImportProfiles/auto_default.local_fromDb.sh" \
"${BATS_TEST_DIRNAME}/testsData/auto_default.local_fromDb_20.sh"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# cat represents the whole list of tables
cat |
grep -v '^table1$' | # table size 29MB
grep -v '^table2$' | # table size 10MB
# grep -v '^table3$' | # table size 4MB
cat
grep -v '^table1$' | # table size 29MB
grep -v '^table2$' | # table size 10MB
# grep -v '^table3$' | # table size 4MB
cat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# cat represents the whole list of tables
cat |
grep -v '^table1$' | # table size 29MB
# grep -v '^table2$' | # table size 10MB
# grep -v '^table3$' | # table size 4MB
cat
grep -v '^table1$' | # table size 29MB
# grep -v '^table2$' | # table size 10MB
# grep -v '^table3$' | # table size 4MB
cat
16 changes: 8 additions & 8 deletions src/_binaries/Utils/testsData/waitForIt.help.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
DESCRIPTION: wait for host:port to be available

USAGE: waitForIt [OPTIONS] [ARGUMENTS]
USAGE: waitForIt --host|-i <hostOrIp> --port|-p <port>
USAGE: waitForIt [--timeout|-t <timeout>] --host|-i <hostOrIp> --port|-p <port>
[--algorithm|--algo <algorithm>] [--exec-command-on-success-only|--strict|-s]
[--timeout|-t <timeout>] [--bash-framework-config <String>] [--config]
[--verbose|-v] [-vv] [-vvv] [--env-file <String>] [--no-color]
[--theme <String>] [--help|-h] [--version] [--quiet|-q] [--log-level <String>]
[--log-file <String>] [--display-level <String>]
[--bash-framework-config <String>] [--config] [--verbose|-v] [-vv] [-vvv]
[--env-file <String>] [--no-color] [--theme <String>] [--help|-h] [--version]
[--quiet|-q] [--log-level <String>] [--log-file <String>]
[--display-level <String>]

ARGUMENTS:
[commandArgs {list} (optional)]
Execute command with args after the test finishes or exit with status code i
f no command provided.

OPTIONS:
--timeout, -t <timeout> {single}
Timeout in seconds, zero for no timeout.
Default value: 15
--host, -i <hostOrIp> {single} (mandatory)
Host or IP under test.
--port, -p <port> {single} (mandatory)
Expand All @@ -23,9 +26,6 @@
n based on commands availability and timeout option value).
--exec-command-on-success-only, --strict, -s {single}
Only execute sub-command if the test succeeds.
--timeout, -t <timeout> {single}
Timeout in seconds, zero for no timeout.
Default value: 15

GLOBAL OPTIONS:
--bash-framework-config <String> {single}
Expand Down

0 comments on commit cbee165

Please sign in to comment.