Skip to content

Commit

Permalink
more tests for classes/conditionals/virtual resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Bode committed Jul 9, 2010
1 parent 56968c5 commit ab69044
Show file tree
Hide file tree
Showing 23 changed files with 223 additions and 10 deletions.
1 change: 1 addition & 0 deletions get_last.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find spec -mindepth 1 \( -type f -and -not -name '*.swp' \) -print0 | xargs -0 ls -t | head -1
2 changes: 0 additions & 2 deletions local_setup.example.sh
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
cd ~/puppet/lib
BIN=../bin
1 change: 1 addition & 0 deletions run_last.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find spec -mindepth 1 \( -type f -and -not -name '*.swp' \) -print0 | xargs -0 ls -t | head -1 | bash
Empty file.
Empty file modified spec/apply/classes/should_allow_param_class_defaults_spec.sh
100644 → 100755
Empty file.
Empty file.
Empty file modified spec/apply/classes/should_allow_param_classes_spec.sh
100644 → 100755
Empty file.
19 changes: 19 additions & 0 deletions spec/apply/classes/should_allow_param_override_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set -e
#
# we are testing that resources declared in a class
# can be applied with an include statement
. local_setup.sh
OUTFILE=/tmp/class_param_use-$$
$BIN/puppet apply <<PP | tee $OUTFILE
class parent {
notify { 'msg':
message => parent,
}
}
class child inherits parent {
Notify['msg'] {message => 'child'}
}
include parent
include child
PP
grep "defined 'message' as 'child'" $OUTFILE
24 changes: 24 additions & 0 deletions spec/apply/classes/should_allow_param_undef_override.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
set -e
#
# we are testing that resources declared in a class
# can be applied with an include statement
. local_setup.sh
OUTFILE=/tmp/class_undef_override_out-$$
echo 'hello world!' > /tmp/class_undef_override_test-$$
$BIN/puppet apply <<PP | tee $OUTFILE
class parent {
file { 'test':
path => '/tmp/class_undef_file-$$',
source => '/tmp/class_undef_override_test-$$',
}
}
class child inherits parent {
File['test'] {
source => undef,
content => 'hello new world!',
}
}
include parent
include child
PP
grep "hello new world" /tmp/class_undef_file-$$
Empty file modified spec/apply/classes/should_include_resources_from_class_spec.sh
100644 → 100755
Empty file.
Empty file.
8 changes: 6 additions & 2 deletions spec/apply/conditionals/should_evaluate_else_spec.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
set -e

#
# test that else clause will be reached
# if no expressions match
#
. local_setup.sh

$BIN/puppet apply <<PP | grep notice | grep else
$BIN/puppet apply <<PP | tee $OUTFILE
if( 1 == 2) {
notice('if')
} elsif(2 == 3) {
Expand All @@ -11,3 +14,4 @@ if( 1 == 2) {
notice('else')
}
PP
grep 'else' $OUTFILE
7 changes: 4 additions & 3 deletions spec/apply/conditionals/should_evaluate_elsif_spec.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
set -e
#!/bin/bash

. local_setup.sh
source local_setup.sh

$BIN/puppet apply <<PP | grep notice | grep elsif
$BIN/puppet apply <<PP | tee $OUTFILE
if( 1 == 3) {
notice('if')
} elsif(2 == 2) {
Expand All @@ -11,3 +11,4 @@ if( 1 == 3) {
notice('else')
}
PP
grep 'elsif' $OUTFILE
13 changes: 13 additions & 0 deletions spec/apply/conditionals/should_evaluate_empty_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
#
# ensure that undefined variables evaluate as false
#
. local_setup.sh

$BIN/puppet apply <<PP | tee $OUTFILE
if \$undef_var {
} else {
notice('undef')
}
PP
grep 'undef' $OUTFILE
13 changes: 13 additions & 0 deletions spec/apply/conditionals/should_evaluate_false_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
#
# test that false evaluates to false
#
source local_setup.sh

$BIN/puppet <<PP | tee $OUTFILE
if false {
} else {
notice('false')
}
PP
grep 'false' $OUTFILE
7 changes: 4 additions & 3 deletions spec/apply/conditionals/should_evaluate_if_spec.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
set -e
#!/bin/bash

. local_setup.sh
source local_setup.sh

$BIN/puppet apply <<PP | grep notice | grep if
$BIN/puppet apply <<PP | tee $OUTFILE
if( 1 == 1) {
notice('if')
} elsif(2 == 2) {
Expand All @@ -11,3 +11,4 @@ if( 1 == 1) {
notice('else')
}
PP
grep 'if' $OUTFILE
14 changes: 14 additions & 0 deletions spec/apply/conditionals/should_evaluate_strings_true_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
#
# test that the string 'false' evaluates to true
#
source local_setup.sh

$BIN/puppet <<PP | tee $OUTFILE
if 'false' {
notice('true')
} else {
notice('false')
}
PP
grep 'true' $OUTFILE
9 changes: 9 additions & 0 deletions spec/apply/conditionals/should_evaluate_undef_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
source local_setup.sh
$BIN/puppet apply <<PP | tee $OUTFILE
if '' {
} else {
notice('empty')
}
PP
grep empty $OUTFILE
33 changes: 33 additions & 0 deletions spec/apply/virtual/should_realize_complex_query_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
#
#
#
#
set -e
set -u

. local_setup.sh

HOSTFILE=/tmp/hosts-$$
# precondition:
# /tmp/hosts-$$ should not exist
if [ -e $HOSTFILE ]; then
rm $HOSTFILE
fi

$BIN/puppet apply <<PP
@host { 'test$$1':
ip=>'127.0.0.2',
target=>'$HOSTFILE',
host_aliases => ['one', 'two', 'three'],
ensure=>present,
}
@host { 'test$$2':
ip=>'127.0.0.3',
target=>'$HOSTFILE',
host_aliases => 'two',
ensure=>present,
}
Host<| host_aliases=='two' and ip=='127.0.0.3' |>
PP
grep test$$2 $HOSTFILE
24 changes: 24 additions & 0 deletions spec/apply/virtual/should_realize_many_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
#
# test that realize function takes a list.
#
set -e
set -u

. local_setup.sh

HOSTFILE=/tmp/hosts-$$
# precondition:
# /tmp/hosts-$$ should not exist
if [ -e $HOSTFILE ]; then
rm $HOSTFILE
fi

# puppet code
$BIN/puppet apply <<PP
@host{'test$$1': ip=>'127.0.0.2', target=>'$HOSTFILE', ensure=>present}
@host{'test$$2': ip=>'127.0.0.2', target=>'$HOSTFILE', ensure=>present}
realize(Host['test$$1'], Host['test$$2'])
PP
# validate - validate that our hostifle contains more than one line that matches test$$
[ $(grep test$$ $HOSTFILE | wc -l) == 2 ]
21 changes: 21 additions & 0 deletions spec/apply/virtual/should_realize_query_array_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
set -e

. local_setup.sh

HOSTFILE=/tmp/hosts-$$
# precondition:
# /tmp/hosts-$$ should not exist
if [ -e $HOSTFILE ]; then
rm $HOSTFILE
fi

$BIN/puppet apply <<PP
@host { 'test$$':
ip=>'127.0.0.2',
target=>'$HOSTFILE',
host_aliases => ['one', 'two', 'three'],
ensure=>present,
}
Host<| host_aliases=='two' |>
PP
grep test$$ $HOSTFILE
21 changes: 21 additions & 0 deletions spec/apply/virtual/should_realize_query_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
set -e

. local_setup.sh

HOSTFILE=/tmp/hosts-$$
# precondition:
# /tmp/hosts-$$ should not exist
if [ -e $HOSTFILE ]; then
rm $HOSTFILE
fi

$BIN/puppet apply <<PP
@host { 'test$$':
ip=>'127.0.0.2',
target=>'$HOSTFILE',
host_aliases => 'alias',
ensure=>present,
}
Host<| ip=='127.0.0.2' |>
PP
grep test$$ $HOSTFILE
16 changes: 16 additions & 0 deletions spec/apply/virtual/should_realize_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
set -e

. local_setup.sh

HOSTFILE=/tmp/hosts-$$
# precondition:
# /tmp/hosts-$$ should not exist
if [ -e $HOSTFILE ]; then
rm $HOSTFILE
fi

$BIN/puppet apply <<PP
@host{'test$$': ip=>'127.0.0.2', target=>'$HOSTFILE', ensure=>present}
realize(Host['test$$'])
PP
grep test$$ $HOSTFILE

0 comments on commit ab69044

Please sign in to comment.