From a8e50cd2cfe55add0b2add4dd022610da09c136d Mon Sep 17 00:00:00 2001 From: Christoph Hartmann Date: Tue, 24 Nov 2015 13:07:25 +0100 Subject: [PATCH] implement integration tests for ini, csv, json and yaml resources --- .../cookbooks/os_prepare/files/example.csv | 7 +++++++ .../cookbooks/os_prepare/files/example.ini | 6 ++++++ .../cookbooks/os_prepare/files/example.json | 12 ++++++++++++ .../cookbooks/os_prepare/files/example.yml | 7 +++++++ .../cookbooks/os_prepare/recipes/default.rb | 1 + .../os_prepare/recipes/json_yaml_csv_ini.rb | 19 +++++++++++++++++++ .../test/integration/default/csv_spec.rb | 5 +++++ .../test/integration/default/ini_spec.rb | 5 +++++ .../test/integration/default/json_spec.rb | 5 +++++ .../test/integration/default/yaml_spec.rb | 5 +++++ 10 files changed, 72 insertions(+) create mode 100644 test/integration/cookbooks/os_prepare/files/example.csv create mode 100644 test/integration/cookbooks/os_prepare/files/example.ini create mode 100644 test/integration/cookbooks/os_prepare/files/example.json create mode 100644 test/integration/cookbooks/os_prepare/files/example.yml create mode 100644 test/integration/cookbooks/os_prepare/recipes/json_yaml_csv_ini.rb create mode 100644 test/integration/test/integration/default/csv_spec.rb create mode 100644 test/integration/test/integration/default/ini_spec.rb create mode 100644 test/integration/test/integration/default/json_spec.rb create mode 100644 test/integration/test/integration/default/yaml_spec.rb diff --git a/test/integration/cookbooks/os_prepare/files/example.csv b/test/integration/cookbooks/os_prepare/files/example.csv new file mode 100644 index 000000000..387f97971 --- /dev/null +++ b/test/integration/cookbooks/os_prepare/files/example.csv @@ -0,0 +1,7 @@ +name,version,license,title,description +addressable,2.3.6,Apache 2.0,URI Implementation,"Addressable is a replacement for the URI implementation that is part of +Ruby's standard library. It more closely conforms to the relevant RFCs and +adds support for IRIs and URI templates." +ast,2.0.0,MIT,A library for working with Abstract Syntax Trees.,A library for working with Abstract Syntax Trees. +astrolabe,1.3.0,MIT,An object-oriented AST extension for Parser,An object-oriented AST extension for Parser +berkshelf,3.2.3,Apache 2.0,"Manages a Cookbook's, or an Application's, Cookbook dependencies","Manages a Cookbook's, or an Application's, Cookbook dependencies" diff --git a/test/integration/cookbooks/os_prepare/files/example.ini b/test/integration/cookbooks/os_prepare/files/example.ini new file mode 100644 index 000000000..6ccd2ab01 --- /dev/null +++ b/test/integration/cookbooks/os_prepare/files/example.ini @@ -0,0 +1,6 @@ +# a comment... +[client] +port = 3306 + +[mysqld] +user = mysql diff --git a/test/integration/cookbooks/os_prepare/files/example.json b/test/integration/cookbooks/os_prepare/files/example.json new file mode 100644 index 000000000..98bd0b73b --- /dev/null +++ b/test/integration/cookbooks/os_prepare/files/example.json @@ -0,0 +1,12 @@ +{ + "name": "demo", + "run_list": [ + "apache2", + "omnibus" + ], + "cookbook_locks": { + "omnibus": { + "version": "2.2.0" + } + } +} diff --git a/test/integration/cookbooks/os_prepare/files/example.yml b/test/integration/cookbooks/os_prepare/files/example.yml new file mode 100644 index 000000000..abb3deada --- /dev/null +++ b/test/integration/cookbooks/os_prepare/files/example.yml @@ -0,0 +1,7 @@ +driver: + name: vagrant + customize: + memory: 1024 +platforms: + - name: centos-5.11 + - name: centos-6.7 diff --git a/test/integration/cookbooks/os_prepare/recipes/default.rb b/test/integration/cookbooks/os_prepare/recipes/default.rb index 9c9dcfcd9..18ffdb723 100644 --- a/test/integration/cookbooks/os_prepare/recipes/default.rb +++ b/test/integration/cookbooks/os_prepare/recipes/default.rb @@ -6,6 +6,7 @@ include_recipe('os_prepare::apt') include_recipe('os_prepare::file') +include_recipe('os_prepare::json_yaml_csv_ini') include_recipe('os_prepare::package') include_recipe('os_prepare::registry_key') include_recipe('os_prepare::service') diff --git a/test/integration/cookbooks/os_prepare/recipes/json_yaml_csv_ini.rb b/test/integration/cookbooks/os_prepare/recipes/json_yaml_csv_ini.rb new file mode 100644 index 000000000..b8a6e4231 --- /dev/null +++ b/test/integration/cookbooks/os_prepare/recipes/json_yaml_csv_ini.rb @@ -0,0 +1,19 @@ +# encoding: utf-8 +# author: Christoph Hartmann +# author: Dominik Richter +# +# adds a yaml file + +gid = 'root' +gid = 'wheel' if node['platform_family'] == 'freebsd' + +['yml', 'json', 'csv', 'ini'].each { |filetype| + + cookbook_file "/tmp/example.#{filetype}" do + source "example.#{filetype}" + owner 'root' + group gid + mode '0755' + action :create + end +} diff --git a/test/integration/test/integration/default/csv_spec.rb b/test/integration/test/integration/default/csv_spec.rb new file mode 100644 index 000000000..2ee3e4548 --- /dev/null +++ b/test/integration/test/integration/default/csv_spec.rb @@ -0,0 +1,5 @@ +# encoding: utf-8 + +describe csv('/tmp/example.csv') do + its('name') { should eq(['addressable', 'ast', 'astrolabe', 'berkshelf']) } +end diff --git a/test/integration/test/integration/default/ini_spec.rb b/test/integration/test/integration/default/ini_spec.rb new file mode 100644 index 000000000..a5f3b61bd --- /dev/null +++ b/test/integration/test/integration/default/ini_spec.rb @@ -0,0 +1,5 @@ +# encoding: utf-8 + +describe ini('/tmp/example.ini') do + its(['client','port']) { should eq('3306') } +end diff --git a/test/integration/test/integration/default/json_spec.rb b/test/integration/test/integration/default/json_spec.rb new file mode 100644 index 000000000..b1634be05 --- /dev/null +++ b/test/integration/test/integration/default/json_spec.rb @@ -0,0 +1,5 @@ +# encoding: utf-8 + +describe json('/tmp/example.json') do + its(['cookbook_locks','omnibus','version']) { should eq('2.2.0') } +end diff --git a/test/integration/test/integration/default/yaml_spec.rb b/test/integration/test/integration/default/yaml_spec.rb new file mode 100644 index 000000000..ff34aa8e1 --- /dev/null +++ b/test/integration/test/integration/default/yaml_spec.rb @@ -0,0 +1,5 @@ +# encoding: utf-8 + +describe yaml('/tmp/example.yml') do + its(['driver','name']) { should eq('vagrant') } +end