teststrap 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fdbb070b114cfadef42ca796008d143a0291e318
4
+ data.tar.gz: b2d02a4af4fec2ba0af8f34995408f27774d1e33
5
+ SHA512:
6
+ metadata.gz: 028a4f47780bcf7ea54b638b6fc68dc96520a039034c2abce391b3128fa3db6d7fe97b444b8631d0936172dbfef903d99fe9634dccb80748e8bbfaa87c6e91c2
7
+ data.tar.gz: d4797a0324d4dbc7e685f7807e1c392368754129772739353e061d6c282c8ae2ebea289b130ff5d6f3a20d944c34cdcc98235cfee05ceb255068f01d48288d65
data/bin/teststrap ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ $:.push File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'teststrap'
5
+
6
+ Teststrap::Teststrap.start(ARGV)
@@ -0,0 +1,18 @@
1
+ .vagrant
2
+ Berksfile.lock
3
+ *~
4
+ *#
5
+ .#*
6
+ \#*#
7
+ .*.sw[a-z]
8
+ *.un~
9
+ /cookbooks
10
+
11
+ # Bundler
12
+ Gemfile.lock
13
+ bin/*
14
+ .bundle/*
15
+
16
+ .kitchen/
17
+ .kitchen.local.yml
18
+ vendor
@@ -0,0 +1,16 @@
1
+ ---
2
+ driver_plugin: vagrant
3
+ driver_config:
4
+ require_chef_omnibus: true
5
+
6
+ platforms:
7
+ - name: sl6-box
8
+ driver_config:
9
+ box: sl6-box
10
+ box_url: http://lyte.id.au/vagrant/sl6-matrix-64-lyte.box
11
+
12
+ suites:
13
+ - name: default
14
+ run_list: [ "recipe[<%= cookbook_name %>::default]" ]
15
+ attributes: {
16
+ }
@@ -0,0 +1,3 @@
1
+ site :opscode
2
+
3
+ metadata
@@ -0,0 +1,18 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'json', '1.7.7'
4
+ gem 'berkshelf', '~> 2.0.10'
5
+ gem 'thor-foodcritic', '~> 1.1.0'
6
+
7
+ gem 'tailor', '~> 1.3.1'
8
+ gem 'strainer', '~> 3.3.0'
9
+ gem 'foodcritic', '~> 3.0.3'
10
+
11
+ gem 'chef', '~> 11.6.0'
12
+ gem 'chefspec', '~> 3.0.2'
13
+
14
+ group :integration do
15
+ gem 'test-kitchen', '~> 1.1.1'
16
+ gem 'kitchen-vagrant', '~> 0.14.0'
17
+ gem 'serverspec', '~> 0.13.2'
18
+ end
@@ -0,0 +1,3 @@
1
+ Copyright (C) 2013 Casecommons
2
+
3
+ All rights reserved - Do Not Redistribute
@@ -0,0 +1,39 @@
1
+ # <%= cookbook_name %> cookbook
2
+
3
+ # Requirements
4
+ Compatable with Scientific linux 6.
5
+
6
+ # Usage
7
+
8
+ # Attributes
9
+
10
+ # Recipes
11
+
12
+ # Running test(unit and integration test)
13
+ + Run chefspec, foodcritic and tailor using strainer:
14
+
15
+ bundle install
16
+ bundle exec strainer test
17
+
18
+ + Start Vagrant using test kitchen:
19
+
20
+ bundle install
21
+ bundle install kitchen create
22
+
23
+ + Set up chef on the vagrant and run the chef:
24
+
25
+ bundle install kitchen converge
26
+
27
+ + Running serverspec on Vagrant
28
+
29
+ bundle exec kitchen verify
30
+
31
+ + Destroy the Vagrant after the test
32
+
33
+ bundle exec kitchen destroy
34
+
35
+ + For CI purpose
36
+
37
+ bundle exec kitchen test
38
+
39
+ # Author
@@ -0,0 +1,3 @@
1
+ foodcritic: bundle exec foodcritic -f any $SANDBOX/$COOKBOOK
2
+ tailor: bundle exec tailor $SANDBOX/$COOKBOOK/**/*.rb
3
+ chefspec: bundle exec rspec $SANDBOX/$COOKBOOK/spec/*.rb --color
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ require 'bundler'
4
+ require 'bundler/setup'
5
+ require 'thor/foodcritic'
6
+ require 'berkshelf/thor'
7
+
8
+ begin
9
+ require 'kitchen/thor_tasks'
10
+ Kitchen::ThorTasks.new
11
+ rescue LoadError
12
+ puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV['CI']
13
+ end
@@ -0,0 +1,96 @@
1
+ # Put files/directories that should be ignored in this file when uploading
2
+ # or sharing to the community site.
3
+ # Lines that start with '# ' are comments.
4
+
5
+ # OS generated files #
6
+ ######################
7
+ .DS_Store
8
+ Icon?
9
+ nohup.out
10
+ ehthumbs.db
11
+ Thumbs.db
12
+
13
+ # SASS #
14
+ ########
15
+ .sass-cache
16
+
17
+ # EDITORS #
18
+ ###########
19
+ \#*
20
+ .#*
21
+ *~
22
+ *.sw[a-z]
23
+ *.bak
24
+ REVISION
25
+ TAGS*
26
+ tmtags
27
+ *_flymake.*
28
+ *_flymake
29
+ *.tmproj
30
+ .project
31
+ .settings
32
+ mkmf.log
33
+
34
+ ## COMPILED ##
35
+ ##############
36
+ a.out
37
+ *.o
38
+ *.pyc
39
+ *.so
40
+ *.com
41
+ *.class
42
+ *.dll
43
+ *.exe
44
+ */rdoc/
45
+
46
+ # Testing #
47
+ ###########
48
+ .watchr
49
+ .rspec
50
+ spec/*
51
+ spec/fixtures/*
52
+ test/*
53
+ features/*
54
+ Guardfile
55
+ Procfile
56
+
57
+ # SCM #
58
+ #######
59
+ .git
60
+ */.git
61
+ .gitignore
62
+ .gitmodules
63
+ .gitconfig
64
+ .gitattributes
65
+ .svn
66
+ */.bzr/*
67
+ */.hg/*
68
+ */.svn/*
69
+
70
+ # Berkshelf #
71
+ #############
72
+ Berksfile
73
+ Berksfile.lock
74
+ cookbooks/*
75
+ tmp
76
+
77
+ # Cookbooks #
78
+ #############
79
+ CONTRIBUTING
80
+ CHANGELOG*
81
+
82
+ # Strainer #
83
+ ############
84
+ Colanderfile
85
+ Strainerfile
86
+ .colander
87
+ .strainer
88
+
89
+ # Vagrant #
90
+ ###########
91
+ .vagrant
92
+ Vagrantfile
93
+
94
+ # Travis #
95
+ ##########
96
+ .travis.yml
@@ -0,0 +1,7 @@
1
+ name '<%= cookbook_name %>'
2
+ maintainer 'Casecommons'
3
+ maintainer_email 'casebook-dev@googlegroups.com'
4
+ license 'All rights reserved'
5
+ description 'Installs/Configures <%= cookbook_name %>'
6
+ long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
7
+ version '0.0.1'
@@ -0,0 +1,8 @@
1
+ require 'chefspec'
2
+
3
+ describe "<%= cookbook_name %>::default" do
4
+ let(:chef_run) do
5
+ ChefSpec::ChefRunner.new do |node|
6
+ end.converge '<%= cookbook_name %>::default'
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+ # http://serverspec.org/ for details
3
+ describe '<%= cookbook_name %>::default' do
4
+ it '' do
5
+ pending
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ require 'serverspec'
2
+
3
+ include SpecInfra::Helper::Exec
4
+ include SpecInfra::Helper::DetectOS
5
+
6
+ RSpec.configure do |c|
7
+ c.sudo_password = ENV['SUDO_PASSWORD']
8
+ end
data/lib/teststrap.rb ADDED
@@ -0,0 +1,68 @@
1
+ require 'thor'
2
+ require 'chef'
3
+
4
+ module Teststrap
5
+ class Teststrap < Thor
6
+ include Thor::Actions
7
+
8
+ attr_accessor :cookbook_name
9
+
10
+ default_task :generate_tests
11
+
12
+ desc "generate_tests", "generate test files"
13
+ def generate_tests
14
+ @cookbook_name = current_directory_name
15
+ puts "generating testfiles::"
16
+ copy_file ".gitignore"
17
+ copy_file "Berksfile"
18
+ copy_file "chefignore"
19
+ copy_file "Gemfile"
20
+ copy_file "LICENSE"
21
+ copy_file "Strainerfile"
22
+ copy_file "Thorfile"
23
+ template "spec/default_spec.rb"
24
+ template "test/integration/default/serverspec/localhost/default_spec.rb"
25
+ template "test/integration/default/serverspec/spec_helper.rb"
26
+ template ".kitchen.yml"
27
+ template "metadata.rb"
28
+ template "README.md"
29
+ end
30
+
31
+ desc "encrypt [data_path] [secret_path]", "encrypt plain databag item to encrypted databag item"
32
+ def encrypt(data_path, secret_path)
33
+ if !File.exist?(data_path)
34
+ puts "file: #{data_path} doesn't exists"
35
+ return nil
36
+ end
37
+
38
+ if !File.exist?(secret_path)
39
+ puts "secret key file: #{secret_path} doesn't exists"
40
+ return nil
41
+ end
42
+
43
+ plain_data = JSON.parse(File.read(data_path))
44
+ secret = Chef::EncryptedDataBagItem.load_secret(secret_path)
45
+ encrypted_data = Chef::EncryptedDataBagItem.encrypt_data_bag_item(plain_data, secret)
46
+ puts JSON.pretty_generate(encrypted_data)
47
+ return encrypted_data
48
+ end
49
+
50
+ no_commands do
51
+ def current_directory_name
52
+ Dir.pwd.split('/').last
53
+ end
54
+
55
+ def run_command(cmd)
56
+ exec(cmd)
57
+ end
58
+
59
+ def self.source_root
60
+ generator_files_path
61
+ end
62
+
63
+ def self.generator_files_path
64
+ File.expand_path('../../generator_files', __FILE__)
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1 @@
1
+ require_relative '../lib/teststrap'
@@ -0,0 +1,4 @@
1
+ {
2
+ "id": "user",
3
+ "password": "1234"
4
+ }
data/spec/test/secret ADDED
@@ -0,0 +1 @@
1
+ secret
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe Teststrap::Teststrap do
4
+ let(:teststrap) { described_class.new }
5
+
6
+ describe "generate_tests" do
7
+ FILES = [ 'Gemfile', 'Berksfile', 'Strainerfile', 'Thorfile', '.gitignore', 'LICENSE']
8
+ TEMPLATES = [
9
+ 'README.md',
10
+ 'metadata.rb',
11
+ '.kitchen.yml',
12
+ 'spec/default_spec.rb',
13
+ 'test/integration/default/serverspec/localhost/default_spec.rb',
14
+ 'test/integration/default/serverspec/spec_helper.rb'
15
+ ]
16
+
17
+ before do
18
+ teststrap.stub(:copy_file)
19
+ teststrap.stub(:template)
20
+ teststrap.stub(:current_directory_name)
21
+ .and_return('test_cookbook')
22
+ end
23
+
24
+ it "should generate files" do
25
+
26
+ FILES.each do |file|
27
+ teststrap.should_receive(:copy_file).with(file)
28
+ end
29
+
30
+ teststrap.generate_tests
31
+ end
32
+
33
+ it "should generate templates" do
34
+
35
+ TEMPLATES.each do |template|
36
+ teststrap.should_receive(:template).with(template)
37
+ end
38
+
39
+ teststrap.generate_tests
40
+ end
41
+ end
42
+
43
+ describe "current_directory_name" do
44
+ it "return current working directory name" do
45
+ Dir.stub('pwd').and_return('test/dir/test_cookbook')
46
+ expect(teststrap.current_directory_name).to eq 'test_cookbook'
47
+ end
48
+ end
49
+
50
+ describe "source_root" do
51
+ it "return generator file path" do
52
+ expect(described_class.source_root)
53
+ .to include 'teststrap/generator_files'
54
+ end
55
+ end
56
+
57
+ describe "encrypt" do
58
+ it "encrypt data file with secret key" do
59
+ directory = File.dirname(__FILE__)
60
+ data_path = File.expand_path('test/data.json', directory)
61
+ secret_path = File.expand_path('test/secret', directory)
62
+ key = teststrap.encrypt(data_path, secret_path)
63
+ expect(key["id"]).to eq "user"
64
+ expect(key["password"]["cipher"]).to eq "aes-256-cbc"
65
+ end
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: teststrap
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.7
5
+ platform: ruby
6
+ authors:
7
+ - Casecommons
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.18.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.18.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: chef
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 11.6.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 11.6.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ description: A test generator for cookbook
56
+ email: casebook-dev@googlegroups.com
57
+ executables:
58
+ - teststrap
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/teststrap.rb
63
+ - generator_files/Berksfile
64
+ - generator_files/chefignore
65
+ - generator_files/Gemfile
66
+ - generator_files/LICENSE
67
+ - generator_files/metadata.rb
68
+ - generator_files/README.md
69
+ - generator_files/spec/default_spec.rb
70
+ - generator_files/Strainerfile
71
+ - generator_files/test/integration/default/serverspec/localhost/default_spec.rb
72
+ - generator_files/test/integration/default/serverspec/spec_helper.rb
73
+ - generator_files/Thorfile
74
+ - generator_files/.kitchen.yml
75
+ - generator_files/.gitignore
76
+ - spec/spec_helper.rb
77
+ - spec/test/data.json
78
+ - spec/test/secret
79
+ - spec/teststrap_spec.rb
80
+ - bin/teststrap
81
+ homepage: https://github.com/CaseCommonsDevOps/teststrap
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.0.14
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: cookbook test framework generator
105
+ test_files:
106
+ - spec/spec_helper.rb
107
+ - spec/test/data.json
108
+ - spec/test/secret
109
+ - spec/teststrap_spec.rb