]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_cliargs.ksh
Add 'zfs diff' coverage to the ZFS Test Suite
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_diff / zfs_diff_cliargs.ksh
1 #!/bin/ksh -p
2 #
3 # This file and its contents are supplied under the terms of the
4 # Common Development and Distribution License ("CDDL"), version 1.0.
5 # You may only use this file in accordance with the terms of version
6 # 1.0 of the CDDL.
7 #
8 # A full copy of the text of the CDDL should have accompanied this
9 # source.  A copy of the CDDL is also available via the Internet at
10 # http://www.illumos.org/license/CDDL.
11 #
12
13 #
14 # Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
15 #
16
17 . $STF_SUITE/include/libtest.shlib
18
19 #
20 # DESCRIPTION:
21 # 'zfs diff' should only work with supported options.
22 #
23 # STRATEGY:
24 # 1. Create two snapshots
25 # 2. Verify every supported option is accepted
26 # 3. Verify supported options raise an error with unsupported arguments
27 # 4. Verify other unsupported options raise an error
28 #
29
30 verify_runnable "both"
31
32 function cleanup
33 {
34         for snap in $TESTSNAP1 $TESTSNAP2; do
35                 if snapexists "$snap"; then
36                         log_must zfs destroy "$snap"
37                 fi
38         done
39 }
40
41 log_assert "'zfs diff' should only work with supported options."
42 log_onexit cleanup
43
44 typeset goodopts=("" "-F" "-H" "-t" "-FH" "-Ft" "-Ht" "-FHt")
45 typeset badopts=("-f" "-h" "-h" "-T" "-Fx" "-Ho" "-tT" "-")
46
47 DATASET="$TESTPOOL/$TESTFS"
48 TESTSNAP1="$DATASET@snap1"
49 TESTSNAP2="$DATASET@snap2"
50
51 # 1. Create two snapshots
52 log_must zfs snapshot "$TESTSNAP1"
53 log_must zfs snapshot "$TESTSNAP2"
54
55 # 2. Verify every supported option is accepted
56 for opt in ${goodopts[@]}
57 do
58         log_must zfs diff $opt "$TESTSNAP1"
59         log_must zfs diff $opt "$TESTSNAP1" "$DATASET"
60         log_must zfs diff $opt "$TESTSNAP1" "$TESTSNAP2"
61 done
62
63 # 3. Verify supported options raise an error with unsupported arguments
64 for opt in ${goodopts[@]}
65 do
66         log_mustnot zfs diff $opt
67         log_mustnot zfs diff $opt "$DATASET"
68         log_mustnot zfs diff $opt "$DATASET@noexists"
69         log_mustnot zfs diff $opt "$DATASET" "$TESTSNAP1"
70         log_mustnot zfs diff $opt "$TESTSNAP2" "$TESTSNAP1"
71 done
72
73 # 4. Verify other unsupported options raise an error
74 for opt in ${badopts[@]}
75 do
76         log_mustnot zfs diff $opt "$TESTSNAP1" "$DATASET"
77         log_mustnot zfs diff $opt "$TESTSNAP1" "$TESTSNAP2"
78 done
79
80 log_pass "'zfs diff' only works with supported options."