From 37eedce72eb6d6a5753d1061c565329f366309fc Mon Sep 17 00:00:00 2001 From: AlteredCoder <64792091+AlteredCoder@users.noreply.github.com> Date: Tue, 5 Oct 2021 09:52:55 +0200 Subject: [PATCH] add functionnal test for hubtest (#996) * add hubtest in functionnal test --- .github/workflows/ci_hubtest.yml | 46 +++++++++---------- cmd/crowdsec-cli/hubtest.go | 2 +- .../tests_post-install_6hubtests.sh | 12 +++++ 3 files changed, 36 insertions(+), 24 deletions(-) create mode 100755 scripts/func_tests/tests_post-install_6hubtests.sh diff --git a/.github/workflows/ci_hubtest.yml b/.github/workflows/ci_hubtest.yml index 4211cbd02..6f4f2ca0a 100644 --- a/.github/workflows/ci_hubtest.yml +++ b/.github/workflows/ci_hubtest.yml @@ -9,11 +9,9 @@ on: - master jobs: - build: + hubtest: name: Hub tests runs-on: ubuntu-latest - env: - BRANCH_REF: ${{ github.ref }} steps: - name: Set up Go 1.16 uses: actions/setup-go@v1 @@ -52,25 +50,27 @@ jobs: echo "SCENARIOS_COV_NUMBER=$(cscli hubtest coverage --scenarios --percent | cut -d '=' -f2 | tr -d '%')" echo "PARSER_BADGE_COLOR=$(if [ $PARSERS_COV_NUMBER -lt '70' ]; then echo 'red'; else echo 'green'; fi)" >> $GITHUB_ENV echo "SCENARIO_BADGE_COLOR=$(if [ $SCENARIOS_COV_NUMBER -lt '70' ]; then echo 'red'; else echo 'green'; fi)" >> $GITHUB_ENV - - name: Create Parsers badge - if: ${{ env.BRANCH_REF }} == 'ref/head/master' - uses: schneegans/dynamic-badges-action@v1.1.0 - with: - auth: ${{ secrets.GIST_BADGES_SECRET }} - gistID: ${{ secrets.GIST_BADGES_ID }} - filename: crowdsec_parsers_badge.json - label: Hub Parsers - message: ${{ env.PARSERS_COV }} - color: ${{ env.SCENARIO_BADGE_COLOR }} - - name: Create Scenarios badge - if: ${{ env.BRANCH_REF }} == 'ref/head/master' - uses: schneegans/dynamic-badges-action@v1.1.0 - with: - auth: ${{ secrets.GIST_BADGES_SECRET }} - gistID: ${{ secrets.GIST_BADGES_ID }} - filename: crowdsec_scenarios_badge.json - label: Hub Scenarios - message: ${{ env.SCENARIOS_COV }} - color: ${{ env.SCENARIO_BADGE_COLOR }} + coverage: + runs-on: ubuntu-latest + if: ${{ github.ref == 'ref/head/master' }} + steps: + - name: Create Parsers badge + uses: schneegans/dynamic-badges-action@v1.1.0 + with: + auth: ${{ secrets.GIST_BADGES_SECRET }} + gistID: ${{ secrets.GIST_BADGES_ID }} + filename: crowdsec_parsers_badge.json + label: Hub Parsers + message: ${{ env.PARSERS_COV }} + color: ${{ env.SCENARIO_BADGE_COLOR }} + - name: Create Scenarios badge + uses: schneegans/dynamic-badges-action@v1.1.0 + with: + auth: ${{ secrets.GIST_BADGES_SECRET }} + gistID: ${{ secrets.GIST_BADGES_ID }} + filename: crowdsec_scenarios_badge.json + label: Hub Scenarios + message: ${{ env.SCENARIOS_COV }} + color: ${{ env.SCENARIO_BADGE_COLOR }} diff --git a/cmd/crowdsec-cli/hubtest.go b/cmd/crowdsec-cli/hubtest.go index ba9bc7b4a..5e7fa94d9 100644 --- a/cmd/crowdsec-cli/hubtest.go +++ b/cmd/crowdsec-cli/hubtest.go @@ -58,7 +58,7 @@ func NewHubTestCmd() *cobra.Command { Short: "create [test_name]", Example: `cscli hubtest create my-awesome-test --type syslog cscli hubtest create my-nginx-custom-test --type nginx -cscli hubtest create my-scenario-test --parser crowdsecurity/nginx --scenario crowdsecurity/http-probing`, +cscli hubtest create my-scenario-test --parsers crowdsecurity/nginx --scenarios crowdsecurity/http-probing`, Args: cobra.ExactArgs(1), DisableAutoGenTag: true, Run: func(cmd *cobra.Command, args []string) { diff --git a/scripts/func_tests/tests_post-install_6hubtests.sh b/scripts/func_tests/tests_post-install_6hubtests.sh new file mode 100755 index 000000000..476f0f799 --- /dev/null +++ b/scripts/func_tests/tests_post-install_6hubtests.sh @@ -0,0 +1,12 @@ +#! /usr/bin/env bash +# -*- coding: utf-8 -*- + +source tests_base.sh + +CURRENT_DIR=$(pwd) + +git clone https://github.com/crowdsecurity/hub.git +cd hub/ +${CSCLI} hubtest run --all + +cd "${CURRENT_DIR}"