summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-02-19 01:29:01 +0200
committerPaul Buetow <paul@buetow.org>2025-02-19 01:29:01 +0200
commite37f1d7dfeb3ff40ee80c6e097cae30b9ec512c4 (patch)
tree2e9f9a63b799f1e8901fdd6d08f09b7665cd6ab5 /test
parent13657c3c13dc62d6aba6e0633fc7f99e44170c06 (diff)
more on this
Diffstat (limited to 'test')
-rw-r--r--test/lib/dslkeywords/dependency_test.rb68
-rw-r--r--test/lib/dslkeywords/file_test.rb24
-rw-r--r--test/lib/dslkeywords/given_test.rb (renamed from test/lib/dslkeywords/only_when_test.rb)4
-rw-r--r--test/lib/dslkeywords/requires_test.rb66
4 files changed, 80 insertions, 82 deletions
diff --git a/test/lib/dslkeywords/dependency_test.rb b/test/lib/dslkeywords/dependency_test.rb
deleted file mode 100644
index aa1be78..0000000
--- a/test/lib/dslkeywords/dependency_test.rb
+++ /dev/null
@@ -1,68 +0,0 @@
-require 'minitest/autorun'
-require 'fileutils'
-
-require_relative '../../../lib/dsl'
-
-class RCMDependencyTest < Minitest::Test
- def test_requires
- foo = nil
- bar = nil
- baz = nil
-
- configure_from_scratch do
- foo = notify 'foo' do
- requires notify 'bar', 'baz'
- :foo_message
- end
-
- bar = notify 'bar'
-
- baz = notify 'baz' do
- requires notify 'bar'
- :baz_message
- end
- end
-
- assert_equal 2, foo.requires.count
- assert foo.requires?("notify('bar')", "notify('baz')")
-
- assert_equal 0, bar.requires.count
- refute bar.requires?('foo')
-
- assert_equal 1, baz.requires.count
- assert baz.requires?("notify('bar')")
- end
-
- def test_requires_invalid_resource
- assert_raises(RCM::Keyword::KeywordError) do
- configure_from_scratch do
- notify { requires invalid('baz') }
- end
- end
- end
-
- def test_requires_non_existant_dependency
- assert_raises(RCM::Resource::NoSuchResourceObject) do
- configure_from_scratch do
- notify { requires notify('nonexistant') }
- end
- end
- end
-
- def test_dependency_loop
- assert_raises(RCM::DependencyEvaluator::DependencyLoop) do
- configure_from_scratch do
- notify('loop') { requires notify('loop') }
- end
- end
- end
-
- def test_dependency_loop_indirect
- assert_raises(RCM::DependencyEvaluator::DependencyLoop) do
- configure_from_scratch do
- notify('loop') { requires notify('pool') }
- notify('pool') { requires notify('loop') }
- end
- end
- end
-end
diff --git a/test/lib/dslkeywords/file_test.rb b/test/lib/dslkeywords/file_test.rb
index 4353471..150440c 100644
--- a/test/lib/dslkeywords/file_test.rb
+++ b/test/lib/dslkeywords/file_test.rb
@@ -26,13 +26,13 @@ class RCMFileTest < Minitest::Test
def test_file_absent
configure_from_scratch do
- file :create_file do
+ file create do
path FILE_PATH
is present
- :text
+ the text
end
- file :delete_file do
+ file delete do
path FILE_PATH
is absent
end
@@ -45,17 +45,17 @@ class RCMFileTest < Minitest::Test
file_path = "#{DIR_PATH}/test_file_absent_with_empty_directory/bar/baz/foo.txt"
configure_from_scratch do
- file :create_file_empty_directory_test do
+ file create File empty directory do
path file_path
manage directory
- :text
+ the text
end
- file :delete_file_empty_directory_test do
+ file delete File empty directory do
path file_path
is absent
manage directory
- requires file :create_file_empty_directory_test
+ requires file create File empty directory
end
end
@@ -99,7 +99,7 @@ class RCMFileTest < Minitest::Test
def test_line_absent
File.write(FILE_PATH, "Hey there\nWhats up?")
configure_from_scratch do
- file(FILE_PATH) do
+ file FILE_PATH do
line 'Whats up?'
is absent
end
@@ -108,7 +108,7 @@ class RCMFileTest < Minitest::Test
File.write(FILE_PATH, "Hey there\nWhats up?")
configure_from_scratch do
- file(FILE_PATH) do
+ file FILE_PATH do
line 'Hey there'
is absent
end
@@ -135,16 +135,16 @@ class RCMFileTest < Minitest::Test
backup_path = "#{DIR_PATH}/foo/.rcm/backup-me.txt.d4c3af73588ce06c32ed04d1b79801286109ea265712a2bd3fdc3ed01c82bb86"
configure_from_scratch do
- file :original do
+ file original do
path file_path
manage directory
original_content
end
- file :new do
+ file new do
path file_path
manage directory
- requires file(:original)
+ requires file original
:new_content
end
end
diff --git a/test/lib/dslkeywords/only_when_test.rb b/test/lib/dslkeywords/given_test.rb
index 94ebe79..d27baca 100644
--- a/test/lib/dslkeywords/only_when_test.rb
+++ b/test/lib/dslkeywords/given_test.rb
@@ -6,14 +6,14 @@ require_relative '../../../lib/dsl'
class RCMOnlyWhenTest < Minitest::Test
def test_hostname
rcm = configure_from_scratch do
- only_when { hostname Socket.gethostname }
+ given { hostname Socket.gethostname }
end
assert rcm.conds_met
end
def test_hostname_negative
rcm = configure_from_scratch do
- only_when { hostname "#{Socket.gethostname}.invalid" }
+ given { hostname "#{Socket.gethostname}.invalid" }
end
refute rcm.conds_met
end
diff --git a/test/lib/dslkeywords/requires_test.rb b/test/lib/dslkeywords/requires_test.rb
new file mode 100644
index 0000000..f06a3ec
--- /dev/null
+++ b/test/lib/dslkeywords/requires_test.rb
@@ -0,0 +1,66 @@
+require 'minitest/autorun'
+require 'fileutils'
+
+require_relative '../../../lib/dsl'
+
+class RCMRequiresTest < Minitest::Test
+ def test_requires
+ foo_notify = bar_notify = baz_notify = nil
+
+ configure_from_scratch do
+ foo_notify = notify foo do
+ requires notify bar and requires notify baz
+ foo_message
+ end
+
+ bar_notify = notify bar
+
+ baz_notify = notify baz do
+ requires notify bar
+ baz_message
+ end
+ end
+
+ assert_equal 2, foo_notify.requires.count
+ assert foo_notify.requires?("notify('bar')", "notify('baz')")
+
+ assert_equal 0, bar_notify.requires.count
+ refute bar_notify.requires?('foo')
+
+ assert_equal 1, baz_notify.requires.count
+ assert baz_notify.requires?("notify('bar')")
+ end
+
+ def test_requires_invalid_resource
+ assert_raises(NameError) do
+ configure_from_scratch do
+ notify { requires invalid('baz') }
+ end
+ end
+ end
+
+ def test_requires_non_existant_dependency
+ assert_raises(RCM::Resource::NoSuchResourceObject) do
+ configure_from_scratch do
+ notify { requires notify nonexistant }
+ end
+ end
+ end
+
+ def test_dependency_loop
+ assert_raises(RCM::DependencyEvaluator::DependencyLoop) do
+ configure_from_scratch do
+ notify(looper) { requires notify looper }
+ end
+ end
+ end
+
+ def test_dependency_loop_indirect
+ assert_raises(RCM::DependencyEvaluator::DependencyLoop) do
+ configure_from_scratch do
+ notify(looper) { requires notify pooler }
+ notify(pooler) { requires notify looper }
+ end
+ end
+ end
+end