| #!/bin/bash |
| |
| # Copyright 2021 Google LLC |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| # This is a fake implementation of systemctl service |
| |
| main() { |
| # perform the following action when the command is |
| # systemctl is-active <service.name> |
| if [[ $1 == "is-active" ]]; then |
| IFS=',' read -r -a array <<< $2 |
| # exit with status code 1 when expected error is not nil |
| if [[ "${array[2]}" != "<nil>" ]]; then |
| exit 1 |
| # if the expected state of systemd service is active, |
| # echo active |
| elif [[ "${array[1]}" == "true" ]]; then |
| echo "active" |
| # if no error is expected and status is not active, return success |
| else |
| return 0 |
| fi |
| # perform the following action when the command is |
| # systemctl start/stop <service.name> |
| elif [[ $1 == "start" || $1 == "stop" ]]; then |
| IFS=',' read -r -a array <<< $2 |
| # exit with status code 1 when expected error is not nil |
| if [[ "${array[2]}" != "<nil>" ]]; then |
| exit 1 |
| # if no error is expected, return success |
| else |
| return 0 |
| fi |
| # exit with status code 1 when any other command is used |
| else |
| exit 1 |
| fi |
| } |
| |
| main $@ |