diff options
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/command_line_test.rb | 7 | ||||
-rw-r--r-- | test/unit/config_object_list_test.rb | 3 | ||||
-rw-r--r-- | test/unit/config_object_test.rb | 2 | ||||
-rw-r--r-- | test/unit/quick_start_test.rb | 127 | ||||
-rw-r--r-- | test/unit/test_helper.rb | 2 |
5 files changed, 134 insertions, 7 deletions
diff --git a/test/unit/command_line_test.rb b/test/unit/command_line_test.rb index 0b57ed0..393bcf2 100644 --- a/test/unit/command_line_test.rb +++ b/test/unit/command_line_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('../test_helper', __FILE__) +require_relative 'test_helper' class CommandLineTest < Minitest::Test @@ -13,7 +13,7 @@ class CommandLineTest < Minitest::Test with_multiple_rubies do output = leap_bin('list') assert_equal 0, $?, "list should exit 0" - assert output =~ /ns1 dns/m + assert output =~ /ns1 dns/m end end @@ -21,7 +21,8 @@ class CommandLineTest < Minitest::Test cleanup_files('nodes/banana.json', 'files/nodes/banana') output = leap_bin("node add banana tags:production "+ "services:openvpn ip_address:1.1.1.1 openvpn.gateway_address:2.2.2.2") - assert_match /created nodes\/banana\.json/, output + assert_match(/created nodes\/banana\.json/, output) + cleanup_files('nodes/banana.json', 'files/nodes/banana') end end diff --git a/test/unit/config_object_list_test.rb b/test/unit/config_object_list_test.rb index 9b6e09f..042a742 100644 --- a/test/unit/config_object_list_test.rb +++ b/test/unit/config_object_list_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('../test_helper', __FILE__) +require_relative 'test_helper' class ConfigObjectListTest < Minitest::Test @@ -9,7 +9,6 @@ class ConfigObjectListTest < Minitest::Test end def test_complex_node_search - domain = provider.domain nodes = manager.nodes['location.country_code' => 'US'] assert nodes.size != manager.nodes.size, 'should not return all nodes' assert_equal 2, nodes.size, 'should be some nodes' diff --git a/test/unit/config_object_test.rb b/test/unit/config_object_test.rb index 54b45d1..88e11e6 100644 --- a/test/unit/config_object_test.rb +++ b/test/unit/config_object_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('../test_helper', __FILE__) +require_relative 'test_helper' class ConfigObjectTest < Minitest::Test diff --git a/test/unit/quick_start_test.rb b/test/unit/quick_start_test.rb new file mode 100644 index 0000000..d26f9c8 --- /dev/null +++ b/test/unit/quick_start_test.rb @@ -0,0 +1,127 @@ +require_relative 'test_helper' + +# +# Runs all the commands in https://leap.se/quick-start +# + +Minitest.after_run { + FileUtils.rm_r(QuickStartTest::TMP_PROVIDER) +} + +class QuickStartTest < Minitest::Test + + # very reasonable to have ordered tests in this case, actually + i_suck_and_my_tests_are_order_dependent! + + TMP_PROVIDER = Dir.mktmpdir("test_leap_provider_") + + # + # use minimal bit sizes for our test. + # + PROVIDER_JSON = <<HERE +{ + "domain": "example.org", + "name": { + "en": "Example" + }, + "description": { + "en": "Example" + }, + "languages": ["en"], + "default_language": "en", + "enrollment_policy": "open", + "contacts": { + "default": "root@localhost" + }, + "ca": { + "bit_size": 1024, + "client_certificates": { + "bit_size": 1024, + "digest": "SHA1", + "life_span": "100 years" + }, + "life_span": "100 years", + "server_certificates": { + "bit_size": 1024, + "digest": "SHA1", + "life_span": "100 years" + } + } +} +HERE + + def provider_path + TMP_PROVIDER + end + + def test_01_new + output = leap_bin! "new --contacts me@example.org --domain example.org --name Example --platform='#{platform_path}' ." + assert_file "Leapfile" + assert_file "provider.json" + assert_dir "nodes" + File.write(File.join(provider_path, 'provider.json'), PROVIDER_JSON) + end + + def test_02_ca + leap_bin! "cert ca" + assert_dir "files/ca" + assert_file "files/ca/ca.crt" + assert_file "files/ca/ca.key" + end + + def test_03_csr + leap_bin! "cert csr" + assert_file "files/cert/example.org.csr" + assert_file "files/cert/example.org.crt" + assert_file "files/cert/example.org.key" + end + + def test_04_nodes + leap_bin! "node add wildebeest ip_address:1.1.1.2 services:webapp,couchdb" + leap_bin! "node add hippo ip_address:1.1.1.3 services:static" + assert_file "nodes/wildebeest.json" + assert_dir "files/nodes/wildebeest" + assert_file "files/nodes/wildebeest/wildebeest.crt" + assert_file "files/nodes/wildebeest/wildebeest.key" + end + + def test_05_compile + user_dir = File.join(provider_path, 'users', 'dummy') + user_key = File.join(user_dir, 'dummy_ssh.pub') + FileUtils.mkdir_p(user_dir) + File.write(user_key, 'ssh-rsa dummydummydummy') + + leap_bin! "compile" + assert_file "hiera/wildebeest.yaml" + assert_file "hiera/hippo.yaml" + end + + def test_06_rename + leap_bin! "node mv hippo hippopotamus" + assert_file "nodes/hippopotamus.json" + assert_dir "files/nodes/hippopotamus" + assert_file "files/nodes/hippopotamus/hippopotamus.key" + end + + def test_07_rm + leap_bin! "node rm hippopotamus" + assert_file_missing "nodes/hippopotamus.json" + assert_file_missing "files/nodes/hippopotamus/hippopotamus.key" + end + + def assert_file(path) + assert File.exist?(File.join(provider_path, path)), "The file `#{path}` should exist in #{provider_path}. Actual: \n#{provider_files}" + end + + def assert_file_missing(path) + assert !File.exist?(File.join(provider_path, path)), "The file `#{path}` should NOT exist in #{provider_path}." + end + + def assert_dir(path) + assert Dir.exist?(File.join(provider_path, path)), "The directory `#{path}` should exist in #{provider_path}. Actual: \n#{provider_files}" + end + + def provider_files + `cd #{provider_path} && find .` + end +end diff --git a/test/unit/test_helper.rb b/test/unit/test_helper.rb index 25a36de..057e4b7 100644 --- a/test/unit/test_helper.rb +++ b/test/unit/test_helper.rb @@ -1 +1 @@ -require File.expand_path('../../test_helper', __FILE__) +require_relative '../test_helper' |