1#!/usr/local/bin/ksh93 -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23# $FreeBSD$
24
25#
26# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zfs_promote_006_neg.ksh	1.3	07/10/09 SMI"
30#
31. $STF_SUITE/include/libtest.kshlib
32
33################################################################################
34#
35# __stc_assertion_start
36#
37# ID: zfs_promote_006_neg
38#
39# DESCRIPTION:
40#	'zfs promote' will fail with invalid arguments:
41#	(1) NULL arguments
42#	(2) non-existent clone
43#	(3) non-clone datasets:
44#		pool, fs, snapshot,volume
45#	(4) too many arguments.
46#	(5) invalid options
47#
48# STRATEGY:
49#	1. Create an array of invalid arguments
50#	2. For each invalid argument in the array, 'zfs promote' should fail
51#	3. Verify the return code from zfs promote
52#
53# TESTABILITY: explicit
54#
55# TEST_AUTOMATION_LEVEL: automated
56#
57# CODING_STATUS: COMPLETED (2006-05-16)
58#
59# __stc_assertion_end
60#
61################################################################################
62
63verify_runnable "both"
64
65snap=$TESTPOOL/$TESTFS@$TESTSNAP
66set -A args "" \
67	"$TESTPOOL/blah" \
68	"$TESTPOOL" "$TESTPOOL/$TESTFS" "$snap" \
69	"$TESTPOOL/$TESTVOL" "$TESTPOL $TESTPOOL/$TESTFS" \
70	"$clone $TESTPOOL/$TESTFS" "- $clone" "-? $clone"
71
72function cleanup
73{
74	if datasetexists $clone; then
75		log_must $ZFS destroy $clone
76	fi
77
78	if snapexists $snap; then
79		destroy_snapshot  $snap
80	fi
81}
82
83log_assert "'zfs promote' will fail with invalid arguments. "
84log_onexit cleanup
85
86snap=$TESTPOOL/$TESTFS@$TESTSNAP
87clone=$TESTPOOL/$TESTCLONE
88log_must $ZFS snapshot $snap
89log_must $ZFS clone $snap $clone
90
91typeset -i i=0
92while (( i < ${#args[*]} )); do
93	log_mustnot $ZFS promote ${args[i]}
94
95	(( i = i + 1 ))
96done
97
98log_pass "'zfs promote' fails with invalid argument as expected."
99