Skip to content

Commit 176cc42

Browse files
committed
Add basic tests and github workflow
1 parent 55b75dc commit 176cc42

File tree

7 files changed

+130
-5
lines changed

7 files changed

+130
-5
lines changed

.env.bashunit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BASHUNIT_DEFAULT_PATH=test/elastic
2+
BASHUNIT_BOOTSTRAP="${BASHUNIT_DEFAULT_PATH}/bootstrap.sh"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Elastic Demo Tests
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
push:
7+
paths-ignore:
8+
- '.githubREADME.md'
9+
10+
jobs:
11+
test:
12+
name: Test
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
fail-fast: false
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Install bashunit
23+
run: |
24+
curl -s https://bashunit.typeddevs.com/install.sh | bash
25+
26+
- name: Run the tests
27+
run: |
28+
./lib/bashunit --env .env.bashunit

test/elastic/basic_docker_test.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
set -e -o pipefail
4+
5+
source "${CURRENT_DIR}/test/elastic/utils.sh"
6+
7+
8+
function set_up_before_script() {
9+
start_local_elastic_stack
10+
}
11+
12+
function tear_down_after_script() {
13+
uninstall_local_elastic_stack
14+
}
15+
16+
function test_launch_demo_docker() {
17+
result=$(launch_demo "cloud-hosted" "docker")
18+
assert_false "$result"
19+
}
20+
21+
function test_destroy_demo_docker() {
22+
result=$(destroy_demo "docker")
23+
assert_false "$result"
24+
}
25+

test/elastic/basic_k8s_test.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
set -e -o pipefail
4+
5+
source "${CURRENT_DIR}/test/elastic/utils.sh"
6+
7+
8+
function set_up_before_script() {
9+
start_local_elastic_stack
10+
}
11+
12+
function tear_down_after_script() {
13+
uninstall_local_elastic_stack
14+
}
15+
16+
function test_demo_k8s() {
17+
# result=$(launch_demo "cloud-hosted" "k8s")
18+
# assert_false "$result"
19+
assert_true true
20+
}
21+

test/elastic/bootstrap.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33
# Place your common test setup here
4+
5+
CURRENT_DIR=$(pwd)
6+
START_LOCAL_DIR="${CURRENT_DIR}/elastic-start-local"
7+
START_LOCAL_ENV_PATH="${START_LOCAL_DIR}/.env"
8+
START_LOCAL_UNINSTALL_FILE="${START_LOCAL_DIR}/uninstall.sh"

test/elastic/example_test.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/elastic/utils.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
3+
set -e -o pipefail
4+
5+
# Returns the HTTP status code from a call
6+
# usage: get_http_response_code url username password
7+
function get_http_response_code() {
8+
url=$1
9+
if [ -z "$url" ]; then
10+
echo "Error: you need to specify the URL for get the HTTP response"
11+
exit 1
12+
fi
13+
username=$2
14+
password=$3
15+
16+
if [ -z "$username" ] || [ -z "$password" ]; then
17+
result=$(curl -LI "$url" -o /dev/null -w '%{http_code}\n' -s)
18+
else
19+
result=$(curl -LI -u "$username":"$password" "$url" -o /dev/null -w '%{http_code}\n' -s)
20+
fi
21+
22+
echo "$result"
23+
}
24+
25+
function start_local_elastic_stack() {
26+
curl -fsSL https://elastic.co/start-local | sh
27+
source "${START_LOCAL_ENV_PATH}"
28+
sleep 2
29+
result=$(get_http_response_code "http://localhost:9200" "elastic" "${ES_LOCAL_PASSWORD}")
30+
assert_equals "200" "$result"
31+
}
32+
33+
function uninstall_local_elastic_stack() {
34+
printf "yes\nno\n" | "${START_LOCAL_UNINSTALL_FILE}"
35+
rm -rf "${START_LOCAL_DIR}"
36+
}
37+
38+
function launch_demo() {
39+
deployment_type="$1"
40+
platform="$2"
41+
elasticsearch_endpoint="${ES_LOCAL_URL:-$3}"
42+
elasticsearch_api_key="${ES_LOCAL_API_KEY}"
43+
printf "%s\n%s\n%s\n%s\n" "$deployment_type" "$platform" "$elasticsearch_endpoint" "$elasticsearch_api_key" | ./demo.sh
44+
}
45+
46+
function destroy_demo() {
47+
platform="$1"
48+
printf "%s\n" "$platform" | ./demo.sh destroy
49+
}

0 commit comments

Comments
 (0)