Skip to content

Add test cases for verifying flags used to tweak behaviour of deploy #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "test/libs/bats"]
path = test/libs/bats
url = https://github.com/sstephenson/bats
[submodule "test/libs/bats-assert"]
path = test/libs/bats-assert
url = https://github.com/ztombol/bats-assert
[submodule "test/libs/bats-support"]
path = test/libs/bats-support
url = https://github.com/ztombol/bats-support
11 changes: 11 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ In general every project requires observability, ci/cd pipelines, environment ma
1. Go the *Actions* tab and open *Deploy Service* Action from the left bar
2. Click on *Run workflow* and provide environment (this should be same as you used while setting up Action) and the service name you want to deploy


## Running tests
1. Before running tests, update the git submodules
```
git submodule init
git submodule update
```
2. Command to run test
```
test/test_file_name.bats
```
## Developer Documentaion

1. [Onboarding a service](./docs/onboarding.md)
Expand Down
14 changes: 14 additions & 0 deletions test/Makefile.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Makefile.mock
FORCE_RECREATE_FLAG := $(if $(filter 1,$(ENABLE_FORCE_RECREATE)),--force-recreate,)
REMOVE_ORPHANS_FLAG := $(if $(or $(services),$(filter 1, $(DISABLE_REMOVE_ORPHANS))),,--remove-orphans)
REMOVE_ANSI_FLAG := $(if $(filter 1,$(DISABLE_ANSI)),,--ansi never)

DOCKER_COMPOSE_COMMAND=echo "Mock Docker Compose Command: docker compose $(REMOVE_ANSI_FLAG) -p bhasai"

deploy: $(if $(filter 1,$(ENABLE_GIT_PULL)),git-pull,) $(if $(filter 1,$(DISABLE_PULL)),,pull build) reload-caddy
$(DOCKER_COMPOSE_COMMAND) up -d $(FORCE_RECREATE_FLAG) $(REMOVE_ORPHANS_FLAG) ${services}

git-pull:
@echo "Mock: git pull"

.PHONY: deploy reload-caddy pull build git-pull
1 change: 1 addition & 0 deletions test/libs/bats
Submodule bats added at 036081
1 change: 1 addition & 0 deletions test/libs/bats-assert
Submodule bats-assert added at 9f88b4
1 change: 1 addition & 0 deletions test/libs/bats-support
Submodule bats-support added at 004e70
19 changes: 19 additions & 0 deletions test/mock_test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env ./test/libs/bats/bin/bats
load 'libs/bats-support/load'
load 'libs/bats-assert/load'

setup() {
export MAKEFILE="./test/Makefile.mock"
}

@test "Deploy with ENABLE_FORCE_RECREATE set to 1" {
run make -f $MAKEFILE deploy ENABLE_FORCE_RECREATE=1
[ "$status" -eq 0 ]
assert_output --partial "--force-recreate"
}

@test "Deploy with ENABLE_FORCE_RECREATE set to 0" {
run make -f $MAKEFILE deploy ENABLE_FORCE_RECREATE=0
[ "$status" -eq 0 ]
refute_output --partial "--force-recreate"
}
77 changes: 77 additions & 0 deletions test/test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env ./test/libs/bats/bin/bats
load 'libs/bats-support/load'
load 'libs/bats-assert/load'

@test "Deploy with ENABLE_FORCE_RECREATE set to 1" {
run make -f Makefile deploy ENABLE_FORCE_RECREATE=1
[ "$status" -eq 0 ] # Check if make deploy command succeeded
echo "status code: $status"
assert_output --partial "--force-recreate"
}

@test "Deploy with ENABLE_FORCE_RECREATE set to 0" {
run make -f Makefile deploy ENABLE_FORCE_RECREATE=0
[ "$status" -eq 0 ] # Check if make deploy command succeeded
echo "status code: $status"
refute_output --partial "--force-recreate"
}


@test "Deploy with DISABLE_ANSI set to 1" {
run make -f Makefile deploy DISABLE_ANSI=1
[ "$status" -eq 0 ]
echo "status code: $status"
refute_output --partial "--ansi"
}

@test "Deploy with DISABLE_ANSI set to 0" {
run make -f Makefile deploy DISABLE_ANSI=0
[ "$status" -eq 0 ]
echo "status code: $status"
assert_output --partial "--ansi"
}


@test "Deploy with DISABLE_REMOVE_ORPHANS set to 1" {
run make -f Makefile deploy DISABLE_REMOVE_ORPHANS=1
[ "$status" -eq 0 ] # Check if make deploy command succeeded
echo "status code: $status"
refute_output --partial "--remove-orphans"
}

@test "Deploy with DISABLE_REMOVE_ORPHANS set to 0" {
run make -f Makefile deploy DISABLE_REMOVE_ORPHANS=0
[ "$status" -eq 0 ] # Check if make deploy command succeeded
echo "status code: $status"
assert_output --partial "--remove-orphans"
}


@test "Deploy with ENABLE_GIT_PULL set to 1" {
run make -f Makefile deploy ENABLE_GIT_PULL=1
[ "$status" -eq 0 ]
echo "status code: $status"
assert_output --partial "git pull"
}

@test "Deploy with ENABLE_GIT_PULL set to 0" {
run make -f Makefile deploy ENABLE_GIT_PULL=0
[ "$status" -eq 0 ]
echo "status code: $status"
refute_output --partial "git pull"
}


@test "Deploy with DISABLE_PULL set to 1" {
run make -f Makefile deploy DISABLE_PULL=1
[ "$status" -eq 0 ] # Check if make deploy command succeeded
echo "status code: $status"
refute_output --partial "docker compose --ansi never -p bhasai pull"
}

@test "Deploy with DISABLE_PULL set to 0" {
run make -f Makefile deploy DISABLE_PULL=0
[ "$status" -eq 0 ] # Check if make deploy command succeeded
echo "status code: $status"
assert_output --partial "docker compose --ansi never -p bhasai pull"
}