summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/blinktest.rb43
-rw-r--r--test/tc_basic.rb93
-rw-r--r--test/tc_file.rb96
-rw-r--r--test/tc_interpreter.rb34
-rw-r--r--test/tc_lexer.rb87
-rw-r--r--test/tc_oparse.rb111
-rw-r--r--test/tc_package.rb27
-rw-r--r--test/tc_parser.rb29
-rw-r--r--test/tc_selector.rb32
-rw-r--r--test/tc_service.rb73
-rw-r--r--test/tc_symlink.rb59
-rw-r--r--test/text/assignments9
-rw-r--r--test/text/facts9
-rw-r--r--test/text/functions3
-rw-r--r--test/text/groups7
-rw-r--r--test/text/one5
-rw-r--r--test/text/selectors27
-rw-r--r--test/ts_objects.rb6
-rw-r--r--test/ts_other.rb6
-rw-r--r--test/ts_parsing.rb5
20 files changed, 761 insertions, 0 deletions
diff --git a/test/blinktest.rb b/test/blinktest.rb
new file mode 100644
index 000000000..4596eaaf7
--- /dev/null
+++ b/test/blinktest.rb
@@ -0,0 +1,43 @@
+# $Id$
+
+unless defined? TestSuite
+ $VERBOSE = true
+
+ $:.unshift File.join(Dir.getwd, '../lib')
+
+ class TestSuite
+ attr_accessor :subdir
+
+ def initialize(files)
+ files.collect { |file|
+ if file =~ /\.rb/
+ file
+ else
+ "tc_" + file + ".rb"
+ end
+ }.sort { |a,b|
+ File.stat(a) <=> File.stat(b)
+ }.each { |file|
+ require file
+ }
+ end
+ end
+
+ def textfiles
+ files = Dir.entries("text").reject { |file|
+ file =~ %r{\.swp}
+ }.reject { |file|
+ file =~ %r{\.disabled}
+ }.collect { |file|
+ File.join("text",file)
+ }.find_all { |file|
+ FileTest.file?(file)
+ }.each { |file|
+ yield file
+ }
+ end
+end
+
+if __FILE__ == $0 # if we're executing the top-level library...
+ TestSuite.new(Dir.glob("ts_*"))
+end
diff --git a/test/tc_basic.rb b/test/tc_basic.rb
new file mode 100644
index 000000000..f7ffbebfa
--- /dev/null
+++ b/test/tc_basic.rb
@@ -0,0 +1,93 @@
+$:.unshift '../lib' if __FILE__ == $0 # Make this library first!
+
+require 'blink'
+require 'test/unit'
+
+# $Id$
+
+class TestBasic < Test::Unit::TestCase
+ # hmmm
+ # this is complicated, because we store references to the created
+ # objects in a central store
+ def setup
+ @component = nil
+ @configfile = nil
+ @sleeper = nil
+
+ Blink[:debug] = 1
+
+ assert_nothing_raised() {
+ unless Blink::Component.has_key?("sleeper")
+ Blink::Component.new(
+ :name => "sleeper"
+ )
+ end
+ @component = Blink::Component["sleeper"]
+ }
+
+ assert_nothing_raised() {
+ unless Blink::Objects::File.has_key?("../examples/root/etc/configfile")
+ Blink::Objects::File.new(
+ :path => "../examples/root/etc/configfile"
+ )
+ end
+ @configfile = Blink::Objects::File["../examples/root/etc/configfile"]
+ }
+ assert_nothing_raised() {
+ unless Blink::Objects::Service.has_key?("sleeper")
+ Blink::Objects::Service.new(
+ :name => "sleeper",
+ :running => 1
+ )
+ Blink::Objects::Service.addpath(
+ File.expand_path("../examples/root/etc/init.d")
+ )
+ end
+ @sleeper = Blink::Objects::Service["sleeper"]
+ }
+ assert_nothing_raised() {
+ @component.push(
+ @configfile,
+ @sleeper
+ )
+ }
+
+ #puts "Component is %s, id %s" % [@component, @component.object_id]
+ #puts "ConfigFile is %s, id %s" % [@configfile, @configfile.object_id]
+ end
+
+ def test_name_calls
+ [@component,@sleeper,@configfile].each { |obj|
+ assert_nothing_raised(){
+ obj.name
+ }
+ }
+ end
+
+ def test_name_equality
+ #puts "Component is %s, id %s" % [@component, @component.object_id]
+ assert_equal(
+ "sleeper",
+ @component.name
+ )
+
+ assert_equal(
+ "../examples/root/etc/configfile",
+ @configfile.name
+ )
+
+ assert_equal(
+ "sleeper",
+ @sleeper.name
+ )
+ end
+
+ def test_object_retrieval
+ [@component,@sleeper,@configfile].each { |obj|
+ assert_equal(
+ obj.class[obj.name].object_id,
+ obj.object_id
+ )
+ }
+ end
+end
diff --git a/test/tc_file.rb b/test/tc_file.rb
new file mode 100644
index 000000000..97a5d8591
--- /dev/null
+++ b/test/tc_file.rb
@@ -0,0 +1,96 @@
+$:.unshift '../lib' if __FILE__ == $0 # Make this library first!
+
+require 'blink'
+require 'test/unit'
+
+# $Id$
+
+class TestFile < Test::Unit::TestCase
+ # hmmm
+ # this is complicated, because we store references to the created
+ # objects in a central store
+ def setup
+ @file = nil
+ @path = "../examples/root/etc/configfile"
+ Blink[:debug] = 1
+ assert_nothing_raised() {
+ unless Blink::Objects::File.has_key?(@path)
+ Blink::Objects::File.new(
+ :path => @path
+ )
+ end
+ @file = Blink::Objects::File[@path]
+ }
+ end
+
+ def test_owner
+ [Process.uid,%x{whoami}.chomp].each { |user|
+ assert_nothing_raised() {
+ @file[:owner] = user
+ }
+ assert_nothing_raised() {
+ @file.retrieve
+ }
+ assert_nothing_raised() {
+ @file.sync
+ }
+ assert_nothing_raised() {
+ @file.retrieve
+ }
+ assert(@file.insync?())
+ }
+ assert_nothing_raised() {
+ @file[:owner] = "root"
+ }
+ assert_nothing_raised() {
+ @file.retrieve
+ }
+ # we might already be in sync
+ assert(!@file.insync?())
+ assert_nothing_raised() {
+ @file.delete(:owner)
+ }
+ end
+
+ def test_group
+ [%x{groups}.chomp.split(/ /), Process.groups].flatten.each { |group|
+ assert_nothing_raised() {
+ @file[:group] = group
+ }
+ assert_nothing_raised() {
+ @file.retrieve
+ }
+ assert_nothing_raised() {
+ @file.sync
+ }
+ assert_nothing_raised() {
+ @file.retrieve
+ }
+ assert(@file.insync?())
+ assert_nothing_raised() {
+ @file.delete(:group)
+ }
+ }
+ end
+
+ def test_modes
+ [0644,0755,0777,0641].each { |mode|
+ assert_nothing_raised() {
+ @file[:mode] = mode
+ }
+ assert_nothing_raised() {
+ @file.retrieve
+ }
+ assert_nothing_raised() {
+ @file.sync
+ }
+ assert_nothing_raised() {
+ @file.retrieve
+ }
+ assert(@file.insync?())
+ assert_nothing_raised() {
+ @file.delete(:mode)
+ }
+ }
+ end
+end
diff --git a/test/tc_interpreter.rb b/test/tc_interpreter.rb
new file mode 100644
index 000000000..c3c9fc6c9
--- /dev/null
+++ b/test/tc_interpreter.rb
@@ -0,0 +1,34 @@
+$:.unshift '../lib' if __FILE__ == $0 # Make this library first!
+
+require 'blink'
+require 'blink/parser/parser'
+require 'test/unit'
+require 'blinktest.rb'
+
+# $Id$
+
+class TestInterpreter < Test::Unit::TestCase
+ # hmmm
+ # this is complicated, because we store references to the created
+ # objects in a central store
+ def setup
+ Blink.init(:debug => 1)
+ #@lexer = Blink::Parser::Lexer.new()
+ @parser = Blink::Parser::Parser.new()
+ end
+
+ def test_files
+ textfiles { |file|
+ Blink.debug("parsing %s" % file)
+ interpreter = nil
+ assert_nothing_raised() {
+ @parser.file = file
+ interpreter = @parser.parse
+ #p interpreter
+ }
+ assert_nothing_raised() {
+ interpreter.run()
+ }
+ }
+ end
+end
diff --git a/test/tc_lexer.rb b/test/tc_lexer.rb
new file mode 100644
index 000000000..2c1c25dee
--- /dev/null
+++ b/test/tc_lexer.rb
@@ -0,0 +1,87 @@
+$:.unshift '../lib' if __FILE__ == $0 # Make this library first!
+
+require 'blink'
+require 'blink/parser/lexer'
+require 'test/unit'
+require 'blinktest.rb'
+
+# $Id$
+
+#%q{service("telnet") = \{
+# port => "23",
+# protocol => "tcp",
+# name => "telnet",
+#\}
+#} => [[:WORD, "service"], [:LPAREN, "("], [:DQUOTE, "\""], [:WORD, "telnet"], [:DQUOTE, "\""], [:RPAREN, ")"], [:EQUALS, "="], [:lbrace, "{"], [:WORD, "port"], [:FARROW, "=>"], [:DQUOTE, "\""], [:WORD, "23"], [:DQUOTE, "\""], [:COMMA, ","], [:WORD, "protocol"], [:FARROW, "=>"], [:DQUOTE, "\""], [:WORD, "tcp"], [:DQUOTE, "\""], [:COMMA, ","], [:WORD, "name"], [:FARROW, "=>"], [:DQUOTE, "\""], [:WORD, "telnet"], [:DQUOTE, "\""], [:COMMA, ","], [:RBRACE, "}"]]
+
+class TestLexer < Test::Unit::TestCase
+ def setup
+ Blink.init(:debug => 1)
+ @lexer = Blink::Parser::Lexer.new()
+ end
+
+ def test_simple_lex
+ strings = {
+%q{\\} => [[:BACKSLASH,"\\"],[false,false]],
+%q{simplest scanner test} => [[:WORD,"simplest"],[:WORD,"scanner"],[:WORD,"test"],[false,false]],
+%q{returned scanner test
+} => [[:WORD,"returned"],[:WORD,"scanner"],[:WORD,"test"],[false,false]]
+ }
+ strings.each { |str,ary|
+ @lexer.string = str
+ assert_equal(
+ ary,
+ @lexer.fullscan()
+ )
+ }
+ end
+
+ def test_quoted_strings
+ strings = {
+%q{a simple "scanner" test
+} => [[:WORD,"a"],[:WORD,"simple"],[:QTEXT,"scanner"],[:WORD,"test"],[false,false]],
+%q{a harder "scanner test"
+} => [[:WORD,"a"],[:WORD,"harder"],[:QTEXT,"scanner test"],[false,false]],
+%q{a hardest "scanner \"test\""
+} => [[:WORD,"a"],[:WORD,"hardest"],[:QTEXT,'scanner "test"'],[false,false]],
+%q{function("call")} => [[:WORD,"function"],[:LPAREN,"("],[:QTEXT,'call'],[:RPAREN,")"],[false,false]]
+}
+ strings.each { |str,array|
+ @lexer.string = str
+ assert_equal(
+ array,
+ @lexer.fullscan()
+ )
+ }
+ end
+
+ def test_errors
+ strings = %w{
+ ^
+ @
+ <
+ >
+ }
+ strings.each { |str|
+ @lexer.string = str
+ assert_raise(RuntimeError) {
+ @lexer.fullscan()
+ }
+ }
+ end
+
+ def test_more_error
+ assert_raise(TypeError) {
+ @lexer.fullscan()
+ }
+ end
+
+ def test_files
+ textfiles() { |file|
+ @lexer.file = file
+ assert_nothing_raised() {
+ @lexer.fullscan()
+ }
+ }
+ end
+end
diff --git a/test/tc_oparse.rb b/test/tc_oparse.rb
new file mode 100644
index 000000000..e737863b2
--- /dev/null
+++ b/test/tc_oparse.rb
@@ -0,0 +1,111 @@
+$:.unshift '../lib' if __FILE__ == $0 # Make this library first!
+
+require 'blink'
+require 'blink/oparse'
+require 'test/unit'
+
+# $Id$
+
+class TestOParse < Test::Unit::TestCase
+ def setup
+ Blink[:debug] = 1
+
+ @passwdtype = Blink::OParse["passwd"]
+ if @passwdtype.nil?
+ assert_nothing_raised() {
+ @passwdtype = Blink::OParse.newtype(
+ :name => "passwd",
+ :recordsplit => ":",
+ :fields => %w{name password uid gid gcos home shell},
+ :namevar => "name"
+ )
+ }
+ end
+
+ @passwdtype = Blink::OParse["passwd"]
+ if @passwdtype.nil?
+ assert_nothing_raised() {
+ @passwdtype = Blink::OParse.newtype(
+ :name => "passwd",
+ :recordsplit => ":",
+ :fields => %w{name password uid gid gcos home shell},
+ :namevar => "name"
+ )
+ }
+ end
+ end
+
+ def test_passwd1_nochange
+ file = nil
+ type = nil
+ assert_nothing_raised() {
+ file = @passwdtype.new("/etc/passwd")
+ }
+ assert_nothing_raised() {
+ file.retrieve
+ }
+
+ assert(file.insync?)
+
+ contents = ""
+ File.open("/etc/passwd") { |ofile|
+ ofile.each { |line|
+ contents += line
+ }
+ }
+
+ assert_equal(
+ contents,
+ file.to_s
+ )
+
+ end
+
+ def test_passwd2_change
+ file = nil
+ type = nil
+ Kernel.system("cp /etc/passwd /tmp/oparsepasswd")
+ assert_nothing_raised() {
+ file = @passwdtype.new("/tmp/oparsepasswd")
+ }
+ assert_nothing_raised() {
+ file.retrieve
+ }
+
+ assert(file.insync?)
+
+ assert_nothing_raised() {
+ file.add { |obj|
+ obj["name"] = "yaytest"
+ obj["password"] = "x"
+ obj["uid"] = "10000"
+ obj["gid"] = "10000"
+ obj["home"] = "/home/yaytest"
+ obj["gcos"] = "The Yaytest"
+ obj["shell"] = "/bin/sh"
+ }
+ }
+
+ assert(!file.insync?)
+
+ assert_nothing_raised() {
+ file.sync
+ }
+
+ assert(file.insync?)
+
+ assert_nothing_raised() {
+ file.delete("bin")
+ }
+
+ assert(!file.insync?)
+
+ assert_nothing_raised() {
+ file.sync
+ }
+
+ assert(file.insync?)
+
+ #Kernel.system("rm /tmp/oparsepasswd")
+ end
+end
diff --git a/test/tc_package.rb b/test/tc_package.rb
new file mode 100644
index 000000000..ac9973e35
--- /dev/null
+++ b/test/tc_package.rb
@@ -0,0 +1,27 @@
+$:.unshift '../lib' if __FILE__ == $0 # Make this library first!
+
+require 'blink/objects/package'
+require 'test/unit'
+require 'facter'
+
+# $Id$
+
+class TestPackagingType < Test::Unit::TestCase
+ def test_listing
+ platform = Facter["operatingsystem"].value
+ type = nil
+ case platform
+ when "SunOS"
+ type = "sunpkg"
+ when "Linux"
+ type = "dpkg"
+ else
+ type = :invalid
+ end
+
+ assert_nothing_raised() {
+ Blink::Objects::PackagingType[type].list
+ }
+ end
+end
+
diff --git a/test/tc_parser.rb b/test/tc_parser.rb
new file mode 100644
index 000000000..40fcac3fa
--- /dev/null
+++ b/test/tc_parser.rb
@@ -0,0 +1,29 @@
+$:.unshift '../lib' if __FILE__ == $0 # Make this library first!
+
+require 'blink'
+require 'blink/parser/parser'
+require 'test/unit'
+require 'blinktest.rb'
+
+# $Id$
+
+class TestParser < Test::Unit::TestCase
+ # hmmm
+ # this is complicated, because we store references to the created
+ # objects in a central store
+ def setup
+ Blink.init(:debug => 1, :parseonly => true)
+ #@lexer = Blink::Parser::Lexer.new()
+ @parser = Blink::Parser::Parser.new()
+ end
+
+ def test_each_file
+ textfiles { |file|
+ Blink.debug("parsing %s" % file)
+ assert_nothing_raised() {
+ @parser.file = file
+ @parser.parse
+ }
+ }
+ end
+end
diff --git a/test/tc_selector.rb b/test/tc_selector.rb
new file mode 100644
index 000000000..97d02859f
--- /dev/null
+++ b/test/tc_selector.rb
@@ -0,0 +1,32 @@
+$:.unshift '../lib' if __FILE__ == $0 # Make this library first!
+
+require 'blink/selector'
+require 'test/unit'
+
+# $Id$
+
+class TestSelector < Test::Unit::TestCase
+ def setup
+ @os = Blink::Fact["operatingsystem"]
+ @hostname = Blink::Fact["hostname"]
+ end
+
+ def test_values
+ Blink[:debug] = 1
+
+ selector = nil
+ assert_nothing_raised() {
+ selector = Blink::Selector.new { |select|
+ select.add("value1") {
+ Blink::Fact["hostname"] == @hostname
+ }
+ }
+ }
+
+ assert_equal(
+ "value1",
+ selector.evaluate()
+ )
+
+ end
+end
diff --git a/test/tc_service.rb b/test/tc_service.rb
new file mode 100644
index 000000000..4967f3a01
--- /dev/null
+++ b/test/tc_service.rb
@@ -0,0 +1,73 @@
+$:.unshift '../lib' if __FILE__ == $0 # Make this library first!
+
+require 'blink'
+require 'test/unit'
+
+# $Id$
+
+class TestService < Test::Unit::TestCase
+ # hmmm
+ # this is complicated, because we store references to the created
+ # objects in a central store
+ def setup
+ @sleeper = nil
+
+ Blink[:debug] = 1
+ assert_nothing_raised() {
+ unless Blink::Objects::Service.has_key?("sleeper")
+ Blink::Objects::Service.new(
+ :name => "sleeper",
+ :running => 1
+ )
+ Blink::Objects::Service.addpath(
+ File.expand_path("../examples/root/etc/init.d")
+ )
+ end
+ @sleeper = Blink::Objects::Service["sleeper"]
+ }
+ end
+
+ def test_process_start
+ assert_nothing_raised() {
+ @sleeper[:running] = 1
+ }
+ assert_nothing_raised() {
+ @sleeper.retrieve
+ }
+ assert_equal(
+ Kernel.system("../examples/root/etc/init.d/sleeper status"),
+ @sleeper.insync?()
+ )
+ assert_nothing_raised() {
+ @sleeper.sync
+ }
+ assert_nothing_raised() {
+ @sleeper.retrieve
+ }
+ assert_equal(
+ Kernel.system("../examples/root/etc/init.d/sleeper status"),
+ @sleeper.insync?
+ )
+ end
+
+ def test_process_evaluate
+ assert_nothing_raised() {
+ @sleeper[:running] = 1
+ }
+ assert_nothing_raised() {
+ @sleeper.evaluate
+ }
+ # it really feels like this should be implicit...
+ assert_nothing_raised() {
+ @sleeper.retrieve
+ }
+ assert_equal(
+ Kernel.system("../examples/root/etc/init.d/sleeper status"),
+ @sleeper.insync?()
+ )
+ assert_equal(
+ true,
+ @sleeper.insync?()
+ )
+ end
+end
diff --git a/test/tc_symlink.rb b/test/tc_symlink.rb
new file mode 100644
index 000000000..4dd2bd864
--- /dev/null
+++ b/test/tc_symlink.rb
@@ -0,0 +1,59 @@
+$:.unshift '../lib' if __FILE__ == $0 # Make this library first!
+
+require 'blink'
+require 'test/unit'
+
+# $Id$
+
+class TestSymlink < Test::Unit::TestCase
+ # hmmm
+ # this is complicated, because we store references to the created
+ # objects in a central store
+ def setup
+ @symlink = nil
+ @path = "../examples/root/etc/symlink"
+
+ Kernel.system("rm -f %s" % @path)
+ Blink[:debug] = 1
+ assert_nothing_raised() {
+ unless Blink::Objects::Symlink.has_key?(@path)
+ Blink::Objects::Symlink.new(
+ :path => @path
+ )
+ end
+ @symlink = Blink::Objects::Symlink[@path]
+ }
+ end
+
+ def test_target
+ assert_nothing_raised() {
+ @symlink[:target] = "configfile"
+ }
+ assert_nothing_raised() {
+ @symlink.retrieve
+ }
+ # we might already be in sync
+ assert(!@symlink.insync?())
+ assert_nothing_raised() {
+ @symlink.sync
+ }
+ assert_nothing_raised() {
+ @symlink.retrieve
+ }
+ assert(@symlink.insync?())
+ assert_nothing_raised() {
+ @symlink[:target] = nil
+ }
+ assert_nothing_raised() {
+ @symlink.retrieve
+ }
+ assert(!@symlink.insync?())
+ assert_nothing_raised() {
+ @symlink.sync
+ }
+ assert_nothing_raised() {
+ @symlink.retrieve
+ }
+ assert(@symlink.insync?())
+ end
+end
diff --git a/test/text/assignments b/test/text/assignments
new file mode 100644
index 000000000..f45b83392
--- /dev/null
+++ b/test/text/assignments
@@ -0,0 +1,9 @@
+# $Id$
+
+platform = :sunos
+
+platform = "this is a string of text"
+
+apache = service["apache"] {
+ :running => "1"
+}
diff --git a/test/text/facts b/test/text/facts
new file mode 100644
index 000000000..a1562dc82
--- /dev/null
+++ b/test/text/facts
@@ -0,0 +1,9 @@
+# $Id$
+
+fact["videocard"] {
+ :interpreter => "/bin/sh",
+ :code => "lspci | grep VGA",
+ :os => "Linux"
+}
+platform = retrieve("platform")
+card = retrieve("videocard")
diff --git a/test/text/functions b/test/text/functions
new file mode 100644
index 000000000..6d295bdb1
--- /dev/null
+++ b/test/text/functions
@@ -0,0 +1,3 @@
+# $Id$
+
+platform = retrieve("platform")
diff --git a/test/text/groups b/test/text/groups
new file mode 100644
index 000000000..56690eefb
--- /dev/null
+++ b/test/text/groups
@@ -0,0 +1,7 @@
+# $Id$
+
+# there need to be two forms of adding to groups:
+# add the current host to a group, and add a list of hosts to a
+# group by name
+
+group = "crap"
diff --git a/test/text/one b/test/text/one
new file mode 100644
index 000000000..12394b72d
--- /dev/null
+++ b/test/text/one
@@ -0,0 +1,5 @@
+# $Id$
+
+service["sleeper"] {
+ :running => "1",
+}
diff --git a/test/text/selectors b/test/text/selectors
new file mode 100644
index 000000000..7a2b26357
--- /dev/null
+++ b/test/text/selectors
@@ -0,0 +1,27 @@
+# $Id$
+
+platform = :sunos
+
+funtest = platform ? {
+ :sunos => "yayness"
+ :aix => :goodness
+ :default => "badness"
+}
+
+# this is a comment
+
+sleeper = service["sleeper"] {
+ :owner => platform ? {
+ :sunos => "luke"
+ :default => "root"
+ },
+ # this is a bit retarded, because we'll get a null value if we're not on sunos
+ # but we don't currently allow selectors as parameter statements...
+ :group => platform ? :sunos => :luke
+}
+
+# i guess it has to be solved this way...
+
+platform ? :sunos => service["sleeper"] {
+ :group => :luke
+}
diff --git a/test/ts_objects.rb b/test/ts_objects.rb
new file mode 100644
index 000000000..3cada1731
--- /dev/null
+++ b/test/ts_objects.rb
@@ -0,0 +1,6 @@
+# $Id$
+
+require "blinktest.rb"
+
+TestSuite.new(%w{basic file symlink service package})
+
diff --git a/test/ts_other.rb b/test/ts_other.rb
new file mode 100644
index 000000000..f1076e6d1
--- /dev/null
+++ b/test/ts_other.rb
@@ -0,0 +1,6 @@
+# $Id$
+
+require "blinktest.rb"
+
+TestSuite.new(%w{oparse selector})
+
diff --git a/test/ts_parsing.rb b/test/ts_parsing.rb
new file mode 100644
index 000000000..b0a49e4a1
--- /dev/null
+++ b/test/ts_parsing.rb
@@ -0,0 +1,5 @@
+# $Id$
+
+require "blinktest.rb"
+
+suite = TestSuite.new(%w{interpreter lexer parser})