#!/bin/sh
# -*- coding: utf-8 -*-
#
# Univention UCS@school
#
# SPDX-FileCopyrightText: 2013-2026 Univention GmbH
# SPDX-License-Identifier: AGPL-3.0-only

if [ -z "$1" -o "$1" = "-h" -o "$1" = "--help" ] ; then
	echo "$0 --run"
	echo "small test script for move_domaincontroller_to_ou"
	echo "WARNING: it creates a lot of OU and does not clean up!"
	exit 1
fi

eval "$(ucr shell)"

./create_ou test1 dctest1

./create_ou test2

./create_ou test4 dctest4
udm computers/domaincontroller_slave create --position "cn=computers,$ldap_base" --set name=dctest4zwo

./create_ou test5 dctest5
./create_ou test6 dctest5

udm computers/domaincontroller_slave create --position "cn=computers,$ldap_base" --set name=dctest7-01
./create_ou test7
udm computers/domaincontroller_slave modify --dn "cn=dctest7-01,cn=computers,$ldap_base" --append groups="cn=OUtest7-DC-Edukativnetz,cn=ucsschool,cn=groups,$ldap_base"

echo "TEST: DC is unknown"
./move_domaincontroller_to_ou --dcname UnKnOwN --ou test1
echo "EXITCODE: $?"

echo "TEST: OU is unknown"
./move_domaincontroller_to_ou --dcname dctest1 --ou KennIchNicht
echo "EXITCODE: $?"

echo "TEST: DC has no read access to OU"
./move_domaincontroller_to_ou --dcname dctest4zwo --ou test4
echo "EXITCODE: $?"

echo "TEST: DC is already in given OU"
./move_domaincontroller_to_ou --dcname dctest2-01 --ou test2
echo "EXITCODE: $?"

echo "TEST: DC is located in another OU"
./move_domaincontroller_to_ou --dcname dctest5 --ou test6
echo "EXITCODE: $?"

echo "TEST: DC is located in another OU --force"
./move_domaincontroller_to_ou --dcname dctest5 --ou test6 --force
echo "EXITCODE: $?"

echo "TEST: successful move"
./move_domaincontroller_to_ou --dcname dctest7-01 --ou test7
echo "EXITCODE: $?"

