Skip to content

Instantly share code, notes, and snippets.

@bringhurst
Created February 16, 2011 00:29
Show Gist options
  • Save bringhurst/828600 to your computer and use it in GitHub Desktop.
Save bringhurst/828600 to your computer and use it in GitHub Desktop.
A sample of ingredient's DSL
##
## An ingredient file.
##
#
# Give a basic name and description of the package this ingredient file configures.
#
name 'jdk1.6.0_20'
description 'java for use on service nodes'
#
# Operations needed to configure this ingredient into the current environment
#
add {
@java_level = 'jdk1.6.0_20'
@java_curpath = '/opt/java/' + java_level
prepend_path :PATH, java_curpath + '/bin'
prepend_path :MANPATH, java_curpath + '/man'
## FIXME: how do we deal with clobbered env vars?
set_env :JAVA_PATH, java_curpath
set_env :JAVA_VERSION, java_level
}
##### #####
##### Everything past this line is optional. #####
##### #####
#
# Operations needed to remove this ingredient from the current environment.
#
remove {
# remove it from the environment
## FIXME: what parts of the add{} should be undone automatically?
}
##
## Tasting an ingredient is a simple sanity check to see if the configuration was a success.
## All tasting begins with "taste_".
##
# This taste is a simple test to make sure java returns the correct version.
taste_version_java {
IO.popen('java -version') do |f|
while line = f.gets do
assert_true line.include? '1.6.0_20-b02' or line.include? '16.3-b01'
end
end
}
# This taste is a simple test to make sure javac returns the correct version number
taste_version_javac {
assert_true IO.popen('javac -version').gets.include? 'javac 1.6.0_20'
}
##
## Noming an ingredient is an extended test meant for regression testing.
## All noming begins with "nom_".
##
# This nom compiles a sample program and verifies that the program output is expected.
nom_compile_program {
require 'tmpdir'
random_name = ''
for i in 1..10 do random_name << (65 + rand(26)) end
src_filename = File.join(Dir.tmpdir, random_name + '.java')
class_filename = File.join(Dir.tmpdir, random_name + '.class')
program = %(
class #{random_name} {
public static void main( String args[] ) {
System.out.println("#{random_name}");
}
}
)
File.open(src_filename, 'w') {|f| f.write(program) }
IO.popen('javac #{src_filename}');
assert_true File.exist? class_filename
assert_equals `java #{Dir.tmpdir}#{random_name}`, random_name
}
## EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment