#!/bin/bash

. $(dirname $0)/functions

BASE=$BASEDIR/$(basename $0)-test
PREFIX=$BUILDDIR/$(basename $0)-test

# currently, we do not properly copy cdp and pdp information, so for
# comparison of RRD dumps, we just filter out those parts we do not
# expect to match anyway...
function xmlfilter {

#-               <last_ds>1010</last_ds>
#-               <value>4.0400000000e+04</value>
#-               <unknown_sec> 0 </unknown_sec>
#+               <last_ds>U</last_ds>
#+               <value>0.0000000000e+00</value>
#+               <unknown_sec> 40 </unknown_sec>


	perl -n -e '$a=join("",<>); $a=~s,<(cdp_prep|last_ds|value|unknown_sec).*?</\1>,,msg ; print $a'
}


ST=1300000000

rm -f ${PREFIX}*.rrd ${PREFIX}*.xml
$RRDTOOL create ${PREFIX}a1.rrd --no-overwrite --start $(($ST-1)) --step 60 DS:a:GAUGE:120:0:U  RRA:AVERAGE:0.5:1:100 RRA:AVERAGE:0.5:5:2 RRA:MIN:0.5:5:2 RRA:MAX:0.5:5:2 RRA:LAST:0.5:5:2
report create-new-RRD


! $RRDTOOL create ${PREFIX}a1.rrd --no-overwrite --start $(($ST-1)) --step 60 DS:a:GAUGE:120:0:U  RRA:AVERAGE:0.5:1:100 RRA:AVERAGE:0.5:5:2 RRA:MIN:0.5:5:2 RRA:MAX:0.5:5:2 RRA:LAST:0.5:5:2 2>/dev/null
report fail-using-no-overwrite-1


rm -f ${PREFIX}a1.rrd
touch ${PREFIX}a1.rrd
! $RRDTOOL create ${PREFIX}a1.rrd --no-overwrite --start $(($ST-1)) --step 60 DS:a:GAUGE:120:0:U  RRA:AVERAGE:0.5:1:100 RRA:AVERAGE:0.5:5:2 RRA:MIN:0.5:5:2 RRA:MAX:0.5:5:2 RRA:LAST:0.5:5:2 2>/dev/null
report fail-using-no-overwrite-2

rm -f ${PREFIX}a1.rrd
touch ${PREFIX}a1.rrd
$RRDTOOL create ${PREFIX}a1.rrd --no-overwrite --start $(($ST-1)) --step 60 DS:a:GAUGE:120:0:U  RRA:AVERAGE:0.5:1:100 RRA:AVERAGE:0.5:5:2 RRA:MIN:0.5:5:2 RRA:MAX:0.5:5:2 RRA:LAST:0.5:5:2 2>/dev/null
[ $? = 1 ] ; report "exit code == 1"

rm -f ${PREFIX}a1.rrd
touch ${PREFIX}a1.rrd
$RRDTOOL create ${PREFIX}a1.rrd --start $(($ST-1)) --step 60 DS:a:GAUGE:120:0:U  RRA:AVERAGE:0.5:1:100 RRA:AVERAGE:0.5:5:2 RRA:MIN:0.5:5:2 RRA:MAX:0.5:5:2 RRA:LAST:0.5:5:2 
report create-using-overwrite

[ -s ${PREFIX}a1.rrd ]
report overwritten-rrd-size-larger-than-0

rm -f ${PREFIX}*.rrd ${PREFIX}*.xml
