#!/usr/bin/env bash

MODULE_NFS_CLIENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$MODULE_NFS_CLIENT_DIR/../../.." && pwd)"

# shellcheck source=lib/ui.sh
source "$PROJECT_ROOT/lib/ui.sh"
# shellcheck source=lib/log.sh
source "$PROJECT_ROOT/lib/log.sh"
# shellcheck source=lib/package.sh
source "$PROJECT_ROOT/lib/package.sh"
# shellcheck source=core/runtime.sh
source "$PROJECT_ROOT/core/runtime.sh"
# shellcheck source=modules/network/nfs-client/module.sh
source "$MODULE_NFS_CLIENT_DIR/module.sh"

runtime_init "$PROJECT_ROOT"
log_init

if ! package_is_installed nfs-common; then
  printf 'nfs-client test SKIPPED: nfs-common not installed\n'
  exit 0
fi

if ! test -f "$PROJECT_ROOT/config/nfs-client.shares.yaml"; then
  printf 'nfs-client test FAILED: missing repository config\n' >&2
  exit 1
fi

if module_nfs_client_test; then
  printf 'nfs-client test OK\n'
else
  printf 'nfs-client test FAILED\n' >&2
  exit 1
fi
