-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from cronitorio/automated-tests
Tests on Actions
- Loading branch information
Showing
20 changed files
with
431 additions
and
548 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
# This is a basic workflow to help you get started with Actions | ||
|
||
name: "CronitorCLI Release" | ||
|
||
on: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: "Run CronitorCLI tests" | ||
|
||
on: | ||
- push | ||
|
||
jobs: | ||
tests: | ||
name: Run tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- uses: actions/setup-go@v3 | ||
|
||
- name: Setup BATS | ||
uses: mig4/setup-bats@v1 | ||
with: | ||
bats-version: 1.7.0 | ||
|
||
- name: Build binary | ||
run: go build -o cronitor main.go | ||
|
||
- name: Run tests | ||
working-directory: tests | ||
env: | ||
CRONITOR_API_KEY: "${{ secrets.CRONITOR_API_KEY }}" | ||
run: | | ||
echo "::add-mask::cb54ac4fd16142469f2d84fc1bbebd84" | ||
echo "::add-mask::$CRONITOR_API_KEY" | ||
export BATS_PATH="$(which bats)" | ||
sudo -E -n -- $BATS_PATH *.bats |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,4 +71,6 @@ cronitor | |
ctab | ||
cronitor-cli | ||
|
||
local.md | ||
local.md | ||
TODO.md | ||
*.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
0,5,10,15,20,25,30,35,40,45,50,55 * * * * true | ||
0,15,30,45 * * * * /usr/bin/true | ||
0 * * * * echo "this is a longer command" | ||
0 * * * * echo "this is a longer command" | ||
0 * * * * bash slave_status.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bats | ||
|
||
setup() { | ||
SCRIPT_DIR="$(dirname $BATS_TEST_FILENAME)" | ||
cd $SCRIPT_DIR | ||
|
||
source $SCRIPT_DIR/setup.sh | ||
rm -f $CLI_LOGFILE | ||
} | ||
|
||
################# | ||
# ACTIVITY TESTS | ||
################# | ||
|
||
@test "Activity integration test without filter" { | ||
../cronitor $CRONITOR_ARGS activity 44oI2n --log $CLI_LOGFILE | grep -q "monitor_name" | ||
} | ||
|
||
@test "Activity integration test with only pings filter" { | ||
../cronitor $CRONITOR_ARGS activity 44oI2n --only pings --log $CLI_LOGFILE | grep -q "monitor_name" | ||
} | ||
|
||
@test "Activity integration test with only alerts filter" { | ||
../cronitor $CRONITOR_ARGS activity 44oI2n --only alerts --log $CLI_LOGFILE | grep -q -v "\"description\": \"ping\"" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
SCRIPT_DIR=$( cd $(dirname $0) ; pwd -P ) | ||
cd $SCRIPT_DIR | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/usr/bin/env bats | ||
|
||
setup() { | ||
SCRIPT_DIR="$(dirname $BATS_TEST_FILENAME)" | ||
cd $SCRIPT_DIR | ||
|
||
source $SCRIPT_DIR/setup.sh | ||
# CLI_CONFIGFILE="$BATS_TMPDIR/cronitor.json" | ||
MSG=`date` | ||
} | ||
|
||
teardown() { | ||
rm -f $CLI_LOGFILE | ||
rm -f $CLI_CONFIGFILE | ||
rm -f $CLI_LOGFILE_ALTERNATE | ||
} | ||
|
||
################# | ||
# CONFIGURE TESTS | ||
################# | ||
|
||
@test "Configure uses log file from env var" { | ||
CRONITOR_LOG=$CLI_LOGFILE ../cronitor $CRONITOR_ARGS ping d3x0c1 --run -k $CRONITOR_API_KEY | ||
grep "d3x0c1" $CLI_LOGFILE | grep -q 'state=run' | ||
} | ||
|
||
@test "Configure uses hostname from env var" { | ||
CRONITOR_HOSTNAME=myHost ../cronitor $CRONITOR_ARGS ping d3x0c1 --run --log $CLI_LOGFILE | ||
grep -q "&host=myHost" $CLI_LOGFILE | ||
} | ||
|
||
@test "Configure uses hostname from arg not env var" { | ||
CRONITOR_HOSTNAME=myHost ../cronitor $CRONITOR_ARGS ping d3x0c1 --run --log $CLI_LOGFILE --hostname otherHost | ||
grep -q "&host=otherHost" $CLI_LOGFILE | ||
} | ||
|
||
@test "Configure uses ping api key from env var" { | ||
CRONITOR_PING_API_KEY=123 ../cronitor $CRONITOR_ARGS ping d3x0c1 --run --log $CLI_LOGFILE -k $CRONITOR_API_KEY | ||
grep -q "ping/123" $CLI_LOGFILE | ||
} | ||
|
||
@test "Configure writes hostname correctly to config file" { | ||
../cronitor $CRONITOR_ARGS configure --hostname "$MSG" >/dev/null | ||
grep "CRONITOR_HOSTNAME" $CLI_CONFIGFILE | grep -q "$MSG" | ||
} | ||
|
||
@test "Configure writes API Key correctly to config file" { | ||
../cronitor $CRONITOR_ARGS configure --api-key "$MSG" >/dev/null | ||
grep "CRONITOR_API_KEY" $CLI_CONFIGFILE | grep -q "$MSG" | ||
} | ||
|
||
@test "Configure writes API Key correctly to new config file" { | ||
../cronitor $CRONITOR_ARGS configure --api-key "$CLI_ACTUAL_API_KEY" >/dev/null # Using actual API key here so it will be avail for later integration tests.. | ||
grep "CRONITOR_API_KEY" $CLI_CONFIGFILE | grep -q "$CLI_ACTUAL_API_KEY" | ||
} | ||
|
||
@test "Configure writes API Key correctly to custom config file set by param" { | ||
../cronitor $CRONITOR_ARGS configure --config $CLI_CONFIGFILE_ALTERNATE --api-key "$MSG" 2>/dev/null | ||
grep "CRONITOR_API_KEY" $CLI_CONFIGFILE_ALTERNATE | grep -q "$MSG" | ||
} | ||
|
||
@test "Configure writes API Key correctly to custom config file set by env var" { | ||
CRONITOR_CONFIG=$CLI_CONFIGFILE_ALTERNATE ../cronitor $CRONITOR_ARGS configure --api-key "$MSG" 2>/dev/null | ||
grep "CRONITOR_API_KEY" $CLI_CONFIGFILE_ALTERNATE | grep -q "$MSG" | ||
} | ||
|
||
@test "Configure writes Ping API Key correctly to config file" { | ||
../cronitor $CRONITOR_ARGS configure --ping-api-key "$MSG" >/dev/null | ||
grep "CRONITOR_PING_API_KEY" $CLI_CONFIGFILE | grep -q "$MSG" | ||
} | ||
|
||
@test "Configure writes log path correctly to config file" { | ||
../cronitor $CRONITOR_ARGS configure --log $CLI_LOGFILE_ALTERNATE 2>/dev/null | ||
grep "CRONITOR_LOG" $CLI_CONFIGFILE | grep -q $CLI_LOGFILE_ALTERNATE | ||
} | ||
|
||
@test "Configure writes exclude text correctly to config file" { | ||
../cronitor $CRONITOR_ARGS configure --exclude-from-name "$MSG" 2>/dev/null | ||
grep -q "CRONITOR_EXCLUDE_TEXT" $CLI_CONFIGFILE && grep -q "$MSG" $CLI_CONFIGFILE | ||
} | ||
|
||
@test "Configure writes multiple exclude text entries correctly to config file" { | ||
../cronitor $CRONITOR_ARGS configure --exclude-from-name "${MSG}A" --exclude-from-name "${MSG}B" 2>/dev/null | ||
grep -q "CRONITOR_EXCLUDE_TEXT" $CLI_CONFIGFILE && grep -q "${MSG}A" $CLI_CONFIGFILE && grep -q "${MSG}B" $CLI_CONFIGFILE | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.