~jontai/openvista-gtm-integration/bug372069

« back to all changes in this revision

Viewing changes to tests/runtests.sh

  • Committer: Jonathan Tai
  • Date: 2009-05-04 23:44:39 UTC
  • Revision ID: jon.tai@medsphere.com-20090504234439-c1pnzljcwrnyf890
add shunit tests for ov* commands

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
testOvinstanceadd()
 
4
{
 
5
    /usr/sbin/ovinstanceadd $newinstance >$stdoutf 2>$stderrf
 
6
    retval=$?
 
7
 
 
8
    assertTrue "[ -d /opt/openvista/$newinstance ]"
 
9
    assertEquals 0 $retval
 
10
    assertNull "`cat ${stdoutf}`"
 
11
    assertNull "`cat ${stderrf}`"
 
12
}
 
13
 
 
14
testOvinstanceaddRequiresRoot()
 
15
{
 
16
    su -c "/usr/sbin/ovinstanceadd $newinstance" openvista >$stdoutf 2>$stderrf
 
17
    retval=$?
 
18
 
 
19
    assertFalse "[ -d /opt/openvista/$newinstance ]"
 
20
    assertEquals 1 $retval
 
21
    assertNull "`cat ${stdoutf}`"
 
22
    assertEquals 'ovinstanceadd: Only root may add an OpenVista instance to the system' "`cat ${stderrf}`"
 
23
}
 
24
 
 
25
testOvinstancedel()
 
26
{
 
27
    /usr/sbin/ovinstancedel -y $instance >$stdoutf 2>$stderrf
 
28
    retval=$?
 
29
 
 
30
    assertFalse "[ -d /opt/openvista/$instance ]"
 
31
    assertEquals 0 $retval
 
32
    assertNull "`cat ${stdoutf}`"
 
33
    assertNull "`cat ${stderrf}`"
 
34
}
 
35
 
 
36
testOvinstancedelRequiresRoot()
 
37
{
 
38
    su -c "/usr/sbin/ovinstancedel $instance" openvista >$stdoutf 2>$stderrf
 
39
    retval=$?
 
40
 
 
41
    assertTrue "[ -d /opt/openvista/$instance ]"
 
42
    assertEquals 1 $retval
 
43
    assertNull "`cat ${stdoutf}`"
 
44
    assertEquals 'ovinstancedel: Only root may delete an OpenVista instance from the system' "`cat ${stderrf}`"
 
45
}
 
46
 
 
47
testOvrestore()
 
48
{
 
49
    # create a backup to restore
 
50
    ovbackup -q "$instance"
 
51
    backup=`find /opt/openvista/$instance/backups -name '*.tar.bz2' | head -n1`
 
52
 
 
53
    # FIXME: create routines and globals and check that they are actually restored
 
54
    md5sum=`md5sum /opt/openvista/$instance/globals/default.dat`
 
55
 
 
56
    /usr/sbin/ovrestore -y $backup $instance >$stdoutf 2>$stderrf
 
57
    retval=$?
 
58
 
 
59
    assertNotEquals "$md5sum" "`md5sum /opt/openvista/$instance/globals/default.dat`"
 
60
    assertEquals 0 $retval
 
61
    assertNull "`cat ${stdoutf}`"
 
62
    assertNotNull "`cat ${stderrf}`"
 
63
}
 
64
 
 
65
testOvrestoreQuiet()
 
66
{
 
67
    # create a backup to restore
 
68
    ovbackup -q "$instance"
 
69
    backup=`find /opt/openvista/$instance/backups -name '*.tar.bz2' | head -n1`
 
70
 
 
71
    # FIXME: create routines and globals and check that they are actually restored
 
72
    md5sum=`md5sum /opt/openvista/$instance/globals/default.dat`
 
73
 
 
74
    /usr/sbin/ovrestore -y -q $backup $instance >$stdoutf 2>$stderrf
 
75
    retval=$?
 
76
 
 
77
    assertNotEquals "$md5sum" "`md5sum /opt/openvista/$instance/globals/default.dat`"
 
78
    assertEquals 0 $retval
 
79
    assertNull "`cat ${stdoutf}`"
 
80
    assertNull "`cat ${stderrf}`"
 
81
}
 
82
 
 
83
testOvrestoreRequiresRoot()
 
84
{
 
85
    # create a backup to restore
 
86
    ovbackup -q "$instance"
 
87
    backup=`find /opt/openvista/$instance/backups -name '*.tar.bz2' | head -n1`
 
88
 
 
89
    md5sum=`md5sum /opt/openvista/$instance/globals/default.dat`
 
90
 
 
91
    su -c "/usr/sbin/ovrestore -y $backup $instance" openvista >$stdoutf 2>$stderrf
 
92
    retval=$?
 
93
 
 
94
    assertEquals "$md5sum" "`md5sum /opt/openvista/$instance/globals/default.dat`"
 
95
    assertEquals 1 $retval
 
96
    assertNull "`cat ${stdoutf}`"
 
97
    assertEquals 'ovrestore: root privileges are required to restore backups' "`cat ${stderrf}`"
 
98
}
 
99
 
 
100
setUp()
 
101
{
 
102
    tempdir=`mktemp -d -t .shunit.XXXXXXXXXX`
 
103
    stdoutf="$tempdir/stdout"
 
104
    stderrf="$tempdir/stderr"
 
105
 
 
106
    instance="shunit"
 
107
    newinstance="shunitnew"
 
108
 
 
109
    /usr/sbin/ovinstanceadd "$instance"
 
110
}
 
111
 
 
112
tearDown()
 
113
{
 
114
    rm -rf "$tempdir"
 
115
 
 
116
    # may have already been deleted by the test, so check before deleting
 
117
    [ -d "/opt/openvista/$instance" ] && /usr/sbin/ovinstancedel -y "$instance"
 
118
 
 
119
    # may have been created by the test, delete if it exists
 
120
    [ -d "/opt/openvista/$newinstance" ] && /usr/sbin/ovinstancedel -y "$newinstance"
 
121
}
 
122
 
 
123
[ `id -u` -eq 0 ] || {
 
124
    echo "runtests.sh: tests must be run as root" >&2
 
125
    exit 1
 
126
}
 
127
 
 
128
# load and run shUnit2
 
129
[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0
 
130
. ./shunit2-2.1.5/src/shell/shunit2
 
131