Skip to content
This repository has been archived by the owner on Dec 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4 from brokenpip3/feat_extend_tests
Browse files Browse the repository at this point in the history
feat(tests): update and add more tests
  • Loading branch information
brokenpip3 authored Jul 28, 2023
2 parents 9648000 + 3b7077e commit 94bd4f1
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 71 deletions.
50 changes: 27 additions & 23 deletions .github/workflows/test-local-action-with-conditionals.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
on: [push]

jobs:
local_test:
runs-on: ubuntu-latest
name: Install Bats common libs
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup BATS
uses: mig4/setup-bats@v1
- name: Install Bats-libs
uses: ./
with:
support-clean: "false"
assert-clean: "false"
detik-install: "false"
file-install: "false"
- name: Execute test to check Bats-support
run: |
local_test_options:
runs-on: ubuntu-latest
env:
BATS_LIB_PATH: "/usr/lib"
TERM: xterm
name: local with options
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup BATS
uses: mig4/setup-bats@v1
with:
bats-version: 1.10.0
- name: Setup Bats-libs
uses: ./
with:
support-clean: "false"
assert-clean: "false"
detik-install: "true"
file-install: "true"
- name: Execute test to check Bats-support
run: |
cd /tmp/bats-support/
bats test
- name: Execute test to check Bats-assert
run: |
- name: Execute test to check Bats-assert
run: |
cd /tmp/bats-assert/
sed "s:load \"${BATS_TEST_DIRNAME}.*:load \"/usr/lib/bats-assert\":g" test/test_helper.bash
bats test
- name: Execute test to check the installed library
run: |
ls -l /usr/lib/bats*
- name: Execute example tests
run:
bats -T -p tests
97 changes: 73 additions & 24 deletions .github/workflows/test-local-action.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,84 @@
on: [push]

jobs:
local_test:
runs-on: ubuntu-latest
name: Install Bats common libs
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup BATS
uses: mig4/setup-bats@v1
- name: Install Bats-libs
uses: ./
with:
support-clean: "false"
assert-clean: "false"
detik-clean: "false"
file-clean: "false"
- name: Execute test to check Bats-support
run: |
local_test:
runs-on: ubuntu-latest
env:
BATS_LIB_PATH: "/usr/lib"
TERM: xterm
name: local default
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup BATS
uses: mig4/setup-bats@v1
with:
bats-version: 1.10.0
- name: Setup Bats-libs
uses: ./
with:
support-clean: "false"
assert-clean: "false"
detik-clean: "false"
file-clean: "false"
- name: Execute test to check Bats-support
run: |
cd /tmp/bats-support/
bats test
- name: Execute test to check Bats-assert
run: |
- name: Execute test to check Bats-assert
run: |
cd /tmp/bats-assert/
sed "s:load \"${BATS_TEST_DIRNAME}.*:load \"/usr/lib/bats-assert\":g" test/test_helper.bash
bats test
- name: Execute test to check Bats-detik
run: |
- name: Execute test to check Bats-detik
run: |
cd /tmp/bats-detik/
bats tests
- name: Execute test to check Bats-file
run: |
- name: Execute test to check Bats-file
# Currently the bats-file tests are broken
# in gh runner env
continue-on-error: true
run: |
cd /tmp/bats-file/
bats test
- name: Execute example tests
run:
bats -T -p tests
local_test_trigger_cache:
needs: [local_test]
runs-on: ubuntu-latest
env:
BATS_LIB_PATH: "/usr/lib/bats"
name: local default
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup BATS
uses: mig4/setup-bats@v1
with:
bats-version: 1.9.0
- name: Setup Bats-libs
uses: ./
with:
support-clean: "false"
assert-clean: "false"
detik-clean: "false"
file-clean: "false"
- name: Execute test to check Bats-support
run: |
cd /tmp/bats-support/
bats test
- name: Execute test to check Bats-assert
run: |
cd /tmp/bats-assert/
bats test
- name: Execute test to check Bats-detik
run: |
cd /tmp/bats-detik/
bats tests
- name: Execute test to check Bats-file
# Currently the bats-file tests are broken
# in gh runner env
continue-on-error: true
run: |
cd /tmp/bats-file/
bats test
94 changes: 70 additions & 24 deletions .github/workflows/test-public-action.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,81 @@
on: [push]

jobs:
public_test:
runs-on: ubuntu-latest
name: Install Bats common libs
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup BATS
uses: mig4/setup-bats@v1
- name: Setup Bats libs
uses: brokenpip3/[email protected]
with:
support-clean: "false"
assert-clean: "false"
detik-clean: "false"
file-clean: "false"
- name: Execute test to check Bats-support
run: |
public_test:
runs-on: ubuntu-latest
env:
BATS_LIB_PATH: "/usr/lib"
TERM: xterm
name: Install Bats common libs
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup BATS
uses: mig4/setup-bats@v1
with:
bats-version: 1.10.0
- name: Setup Bats-libs
uses: brokenpip3/setup-bats-libs@main
with:
support-clean: "false"
assert-clean: "false"
detik-clean: "false"
file-clean: "false"
- name: Execute test to check Bats-support
run: |
cd /tmp/bats-support/
bats test
- name: Execute test to check Bats-assert
run: |
- name: Execute test to check Bats-assert
run: |
cd /tmp/bats-assert/
sed "s:load \"${BATS_TEST_DIRNAME}.*:load \"/usr/lib/bats-assert\":g" test/test_helper.bash
bats test
- name: Execute test to check Bats-detik
run: |
- name: Execute test to check Bats-detik
run: |
cd /tmp/bats-detik/
bats tests
- name: Execute test to check Bats-file
run: |
- name: Execute test to check Bats-file
continue-on-error: true
run: |
cd /tmp/bats-file/
bats test
- name: Execute example tests
run:
bats -T -p tests
public_test_trigger_cache:
# Run the test again to eventually trigger the cache in the future
needs: [public_test]
runs-on: ubuntu-latest
env:
BATS_LIB_PATH: "/usr/lib"
name: Install Bats common libs
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup BATS
uses: mig4/setup-bats@v1
with:
bats-version: 1.9.0
- name: Setup Bats-libs
uses: brokenpip3/[email protected]
with:
support-clean: "false"
assert-clean: "false"
detik-clean: "false"
file-clean: "false"
- name: Execute test to check Bats-support
run: |
cd /tmp/bats-support/
bats test
- name: Execute test to check Bats-assert
run: |
cd /tmp/bats-assert/
bats test
- name: Execute test to check Bats-detik
run: |
cd /tmp/bats-detik/
bats tests
- name: Execute test to check Bats-file
continue-on-error: true
run: |
cd /tmp/bats-file/
bats test
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
- repo: https://github.com/sirosen/check-jsonschema
rev: 0.22.0
hooks:
- id: check-github-workflows
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: detect-private-key
- id: trailing-whitespace
- id: end-of-file-fixer
72 changes: 72 additions & 0 deletions tests/1-example-tests.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
setup() {
load 'tests_helper'
_tests_helper
}


@test "0: Pre: Create file and dir" {
run mkdir testing
run touch testing/example
assert_success
}

#bats test_tags=github:true
@test "1: Testing file existence" {
run ls testing/example
assert_success
[ -f "testing/example" ]
assert_success
}

#bats test_tags=github:true
@test "2: Testing file permissions" {
run stat -c "%a" testing/example
assert_success
assert_output 644
assert_file_permission 644 /path/to/permission
assert_success
}

#bats test_tags=github:true
@test "3: Testing file content" {
run cat testing/example
assert_success
refute_output "Expected content"
assert_file_empty testing/example
assert_success
}

#bats test_tags=github:true
@test "4: Testing directory creation" {
run mkdir testing/newdir
[ -d "testing/newdir" ]
assert_success
}

#bats test_tags=github:true
@test "5: Testing file creation inside directory" {
run touch testing/newdir/newfile
[ -f "testing/newdir/newfile" ]
assert_success
}

#bats test_tags=github:true
@test "6: Testing file deletion" {
run rm testing/newdir/newfile
[ ! -f "testing/newdir/newfile" ]
assert_success
}

#bats test_tags=github:true
@test "7: Testing directory deletion" {
run rmdir testing/newdir
[ ! -d "testing/newdir" ]
assert_success
}

#bats test_tags=github:true
@test "8: Testing file deletion" {
run rm testing/example
[ ! -f "testing/example" ]
assert_success
}
7 changes: 7 additions & 0 deletions tests/tests_helper.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
_tests_helper() {
export BATS_LIB_PATH=${BATS_LIB_PATH:-"/usr/lib"}
bats_load_library bats-support
bats_load_library bats-assert
bats_load_library bats-file
bats_load_library bats-detik/detik.bash
}

0 comments on commit 94bd4f1

Please sign in to comment.