dkdeploy-test_environment 1.0.0

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: a0d8f469b85ed6dba04fd56aca2d53b7440343c1
4
+ data.tar.gz: 266a4fb1848d3ac70e2810a97dfeae6fa9eadf55
5
+ SHA512:
6
+ metadata.gz: 55149a20f81a3d9ced37c7d5fa9f853872fc7f67ed1a5a3c35f2a18f90a0db51a781dc77cce7058e7fb849a205526f50da2478c380db3c4563773c2e0a992f0a
7
+ data.tar.gz: f2394c4be0e3bd7577b48978d8acee73ab01d29b59861adb487f1144b9d2b62e5439258f65d60eca58ed769d97ecfdb9b2ce5f22b9a9067be65221f92f8ca239
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'tmp/**/*'
4
+ - 'spec/fixtures/application/htdocs/stylesheets/**/config.rb'
5
+ - 'Vagrantfile'
6
+ - 'config/**/*'
7
+ GlobalVars:
8
+ AllowedVariables: []
9
+ MethodLength:
10
+ Max: 25
11
+ LineLength:
12
+ Max: 200
13
+ SpecialGlobalVars:
14
+ Enabled: false
15
+ BracesAroundHashParameters:
16
+ Enabled: false
17
+ CyclomaticComplexity:
18
+ Max: 10
data/CONTRIBUTORS.md ADDED
@@ -0,0 +1,16 @@
1
+ # dkdeploy CONTRIBUTORS
2
+
3
+ The dkdeploy core maintainers would like to recognize following contributors (in alphabetic order):
4
+
5
+ - Sascha Egerer
6
+ - Christoph Gerold
7
+ - Johannes Goslar
8
+ - Kieran Hayes
9
+ - Wilfried Irßlinger
10
+ - Thomas Jahnke
11
+ - Gleb Levitin
12
+ - Luka Lüdicke
13
+ - Nicolai Reuschling
14
+ - Lars Tode
15
+ - Timo Webler
16
+ - Mike Zaschka
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dkdeploy-test_environment.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2014-2016 dkd Internet Service GmbH, Frankfurt am Main (Germany), https://dkd.de/
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # Dkdeploy::Test
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/dkdeploy-test_environment.svg)](https://badge.fury.io/rb/dkdeploy-test_environment)
4
+
5
+ ## Description
6
+
7
+ This Rubygem `dkdeploy-test_environment` contains shared testing functionality between other dkdeploy-* gems.
8
+
9
+ ## Contributing
10
+
11
+ 1. Install [git flow](https://github.com/nvie/gitflow)
12
+ 2. Install [Homebrew](http://brew.sh/) and run `brew install mysql-connector-c`
13
+ 3. If project is not checked out already do git clone `git clone https://github.com/dkdeploy/dkdeploy-test_environment.git`
14
+ 4. Checkout origin develop branch (`git checkout --track -b develop origin/develop`)
15
+ 5. Git flow initialze `git flow init -d`
16
+ 6. Installing gems `bundle install`
17
+ 7. Create new feature branch (`git flow feature start my-new-feature`)
18
+ 8. Run tests (README.md Testing)
19
+ 9. Commit your changes (`git commit -am 'Add some feature'`)
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ task default: :spec
2
+ require 'bundler/gem_tasks'
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dkdeploy/test_environment/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'dkdeploy-test_environment'
8
+ spec.version = Dkdeploy::TestEnvironment::Version
9
+ spec.license = 'MIT'
10
+ spec.authors = ['Lars Tode', 'Timo Webler', 'Kieran Hayes', 'Nicolai Reuschling', 'Johannes Goslar']
11
+ spec.email = ['lars.tode@dkd.de', 'timo.webler@dkd.de', 'kieran.hayes@dkd.de', 'nicolai.reuschling@dkd.de', 'johannes.goslar@dkd.de']
12
+ spec.description = 'test infrastructure for dkdeploy'
13
+ spec.summary = 'dkdeploy-test_environment provides a test application for dkdeploy'
14
+ spec.homepage = 'https://github.com/dkdeploy/dkdeploy-test_environment'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin\/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)\/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'bundler', '~> 1.12.5'
22
+ spec.add_dependency 'rake', '~> 11.2'
23
+ spec.add_dependency 'rspec', '~> 3.4'
24
+ spec.add_dependency 'cucumber', '~> 2.3'
25
+ spec.add_dependency 'rubocop', '~> 0.40'
26
+ spec.add_dependency 'aruba', '~> 0.14'
27
+ spec.add_dependency 'mysql2', '~> 0.3.21'
28
+ spec.add_dependency 'pry', '~> 0.10.1'
29
+ spec.add_dependency 'sshkit', '~> 1.10.0'
30
+ end
@@ -0,0 +1 @@
1
+ require 'dkdeploy/test_environment/version'
@@ -0,0 +1,60 @@
1
+ require 'fileutils'
2
+ require 'pathname'
3
+ require_relative 'constants'
4
+ require_relative 'remote'
5
+ require_relative 'steps'
6
+ require_relative 'env'
7
+ require_relative 'mysql'
8
+ require_relative 'path'
9
+
10
+ module Dkdeploy
11
+ module TestEnvironment
12
+ # Test application for capistrano with vagrant
13
+ #
14
+ # @!attribute [r] remote
15
+ # @return [Dkdeploy::TestEnvironment::Remote]
16
+ class Application
17
+ include Dkdeploy::TestEnvironment::Constants
18
+
19
+ attr_reader :remote
20
+ attr_accessor :mysql_connection_settings
21
+
22
+ def initialize(base, hostname, ssh_config = {})
23
+ Dkdeploy::TestEnvironment::Constants.class_variable_set :@@root, base
24
+ @remote = Dkdeploy::TestEnvironment::Remote.new hostname, ssh_config
25
+ @mysql_connection_settings = {}
26
+ end
27
+
28
+ # Install test environment
29
+ #
30
+ def install
31
+ create_clean_test_application
32
+ initialize_environment
33
+ end
34
+
35
+ # Copy test application to temporary dirctory
36
+ #
37
+ def create_clean_test_application
38
+ # Clean old test app path
39
+ FileUtils.rm_rf test_app_path
40
+ # Create test app path parent directory, if not exists
41
+ FileUtils.mkdir_p tmp_path
42
+ # Copy test app to new location
43
+ FileUtils.cp_r template_path, test_app_path
44
+ end
45
+
46
+ # Initialize rvm and bundler environment
47
+ #
48
+ def initialize_environment
49
+ # Call command at test bundler environment. Not with gem bundler environment
50
+ Bundler.with_clean_env do
51
+ cd test_app_path do
52
+ # Install necessary gems
53
+ `bundle check || bundle install`
54
+ raise "Error running 'bundle install'" unless $?.success?
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,118 @@
1
+ require 'fileutils'
2
+
3
+ module Dkdeploy
4
+ module TestEnvironment
5
+ # Dkdeploy test constants.
6
+ #
7
+ module Constants
8
+ include FileUtils
9
+
10
+ @@root = File.expand_path '../..', __FILE__ # rubocop:disable Style/ClassVars
11
+
12
+ # Gem root path
13
+ #
14
+ # @return [String]
15
+ def gem_root
16
+ @@root
17
+ end
18
+
19
+ # Test app template path
20
+ #
21
+ # @return [String]
22
+ def template_path
23
+ File.join gem_root, 'spec', 'fixtures', 'application'
24
+ end
25
+
26
+ # Path to temporary directory
27
+ #
28
+ # @return [String]
29
+ def tmp_path
30
+ File.join gem_root, 'tmp'
31
+ end
32
+
33
+ # Test app path
34
+ #
35
+ # @return [String]
36
+ def test_app_path
37
+ File.join tmp_path, 'aruba'
38
+ end
39
+
40
+ # Capistrano configuration fixtures path
41
+ #
42
+ # @return [String]
43
+ def capistrano_configuration_fixtures_path
44
+ File.join gem_root, 'spec', 'fixtures', 'capistrano', 'configuration'
45
+ end
46
+
47
+ # Capistrano config dev path
48
+ #
49
+ # @return [String]
50
+ def config_dev_path
51
+ File.join test_app_path, 'config', 'deploy', 'dev.rb'
52
+ end
53
+
54
+ # Capistrano stage for tests
55
+ #
56
+ # @return [String]
57
+ def stage
58
+ 'dev'
59
+ end
60
+
61
+ # Url to vagrant server
62
+ #
63
+ # @return [String]
64
+ def server_url
65
+ 'dkdeploy.dev'
66
+ end
67
+
68
+ # Deploy to path
69
+ #
70
+ # @return [String]
71
+ def deploy_to
72
+ File.join('/', 'var', 'www', 'dkdeploy')
73
+ end
74
+
75
+ # Shared path
76
+ #
77
+ # @return [String]
78
+ def shared_path
79
+ File.join deploy_to, 'shared'
80
+ end
81
+
82
+ # Assets path
83
+ #
84
+ # @return [String]
85
+ def assets_path
86
+ File.join shared_path, 'assets'
87
+ end
88
+
89
+ # Current path
90
+ #
91
+ # @return [String]
92
+ def current_path
93
+ File.join deploy_to, 'current'
94
+ end
95
+
96
+ # Release path
97
+ #
98
+ # @return [String]
99
+ def releases_path
100
+ File.join deploy_to, 'releases'
101
+ end
102
+
103
+ # maintenance config file path
104
+ #
105
+ # @return [String]
106
+ def maintenance_config_file_path
107
+ File.join shared_path, 'config', 'maintenance.json'
108
+ end
109
+
110
+ # remote temporary directory path
111
+ #
112
+ # @return [String]
113
+ def remote_tmp_path
114
+ '/tmp'
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1 @@
1
+ require 'aruba/cucumber'
@@ -0,0 +1,13 @@
1
+ require 'mysql2'
2
+
3
+ # helper to connect to DB
4
+ module MySQLClientHelpers
5
+ def instantiate_mysql_client(database = nil)
6
+ connection_settings = TEST_APPLICATION.mysql_connection_settings
7
+ connection_settings[:database] = database if database
8
+
9
+ Mysql2::Client.new(connection_settings)
10
+ end
11
+ end
12
+
13
+ World(MySQLClientHelpers)
@@ -0,0 +1,36 @@
1
+ # Navigation helper module for cucumber steps
2
+ #
3
+ module NavigationHelpers
4
+ # Mapping for path names to real remote path
5
+ #
6
+ # @param path [String]
7
+ # @return [String]
8
+ def path_to(path)
9
+ case path
10
+ when 'deploy_path'
11
+ TEST_APPLICATION.deploy_to
12
+ when 'current_path'
13
+ TEST_APPLICATION.current_path
14
+ when 'config_path'
15
+ TEST_APPLICATION.remote.config_path
16
+ when 'releases_path'
17
+ TEST_APPLICATION.remote.releases_path
18
+ when 'shared_path'
19
+ TEST_APPLICATION.remote.shared_path
20
+ when 'assets_path'
21
+ TEST_APPLICATION.remote.assets_path
22
+ when 'tmp_path'
23
+ TEST_APPLICATION.remote_tmp_path
24
+ else
25
+ path
26
+ end
27
+ end
28
+
29
+ def resolve_path(path)
30
+ splitted = path.split '/'
31
+ splitted[0] = path_to splitted[0]
32
+ splitted.join '/'
33
+ end
34
+ end
35
+
36
+ World(NavigationHelpers)
@@ -0,0 +1,182 @@
1
+ require 'shellwords'
2
+ require 'sshkit'
3
+
4
+ require_relative 'constants'
5
+
6
+ module Dkdeploy
7
+ module TestEnvironment
8
+ # Class for remote actions
9
+ #
10
+ class Remote
11
+ include Dkdeploy::TestEnvironment::Constants
12
+ include SSHKit::DSL
13
+
14
+ attr_accessor :last_command_result, :host, :ssh_config
15
+
16
+ def initialize(hostname, ssh_config = {})
17
+ ssh_config[:compression] = 'none'
18
+ @host = SSHKit::Host.new hostname: hostname, ssh_options: ssh_config
19
+ end
20
+
21
+ # Check if remote directory exists
22
+ #
23
+ # @param path [String] Remote path
24
+ # @return [Boolean]
25
+ def directory_exists?(path)
26
+ exists? 'd', path
27
+ end
28
+
29
+ # Check if remote symlink exists
30
+ #
31
+ # @param path [String] Remote path
32
+ # @return [Boolean]
33
+ def symlink_exists?(path)
34
+ exists? 'L', path
35
+ end
36
+
37
+ # Check if remote file exists
38
+ #
39
+ # @param path [String] Remote path
40
+ # @return [Boolean]
41
+ def file_exists?(path)
42
+ exists? 'f', path
43
+ end
44
+
45
+ # Execute remote if condition
46
+ #
47
+ # @param type [String] Type of if condition
48
+ # @param path [String] Remote path
49
+ # @return [Boolean]
50
+ def exists?(type, path)
51
+ run %([ -#{type} "#{path}" ] && exit 0 || exit 1)
52
+ end
53
+
54
+ # Creates the remote directory
55
+ #
56
+ # @param remote_directory_name [String] the remote directory name
57
+ # @return [Boolean]
58
+ def create_directory(remote_directory_name)
59
+ run %(mkdir -p "#{remote_directory_name}")
60
+ end
61
+
62
+ # Creates the remote file with the given content
63
+ #
64
+ # @param file_path [String] the file path to be created
65
+ # @param content [String] the content to be put into the created file
66
+ # @return [Boolean]
67
+ def create_file(file_path, content)
68
+ run %(echo "#{content}" > "#{file_path}")
69
+ end
70
+
71
+ # Removes the remote file or directory
72
+ #
73
+ # @param resource_path [String] the remote file or directory path
74
+ # @return [Boolean]
75
+ def remove_resource(resource_path)
76
+ run %(rm -rf "#{resource_path}")
77
+ end
78
+
79
+ # Remove the deploy_to path
80
+ #
81
+ # @return [Boolean]
82
+ def remove_deploy_to_path
83
+ run %(sudo rm -rf -R "#{deploy_to}")
84
+ end
85
+
86
+ # Remove the source of a symlink
87
+ #
88
+ # @return [String]
89
+ def source_of_symlink(target_symlink_path)
90
+ run %(readlink "#{target_symlink_path}")
91
+ end
92
+
93
+ # Execute command on server
94
+ #
95
+ # @param command [String]
96
+ # @return [Boolean]
97
+ def run(command)
98
+ success = false
99
+ result = '' # we need a local variable to capture result from sshkit block
100
+ begin
101
+ on @host do
102
+ result = capture command
103
+ end
104
+ @last_command_result = result
105
+ success = true
106
+ rescue SSHKit::Command::Failed, SSHKit::Runner::ExecuteError
107
+ success = false
108
+ end
109
+ success
110
+ end
111
+
112
+ # Gets the remote file content
113
+ #
114
+ # @param file_path [String]
115
+ # @return [Boolean]
116
+ def get_file_content(file_path)
117
+ raise 'Internal server error.' unless run %(less #{file_path})
118
+ last_command_result
119
+ end
120
+
121
+ # Gets one of the properties of resource
122
+ #
123
+ # Examples:
124
+ # get_resource_property('/a/b/c/', 'group') -> www-data
125
+ # get_resource_property('/a/b/c/', 'group') -> -rwxr-xr--
126
+ #
127
+ # @param path [String] path to the remote file or directory to be examined
128
+ # @param property [String] the property to be returned
129
+ # @return [String] resource property
130
+ def get_resource_property(path, property)
131
+ # run the ls command
132
+ raise 'Internal server error.' unless run %(ls -lad "#{path}")
133
+
134
+ # Parses the returned string value and converts it to an array
135
+ # Example: Array[drwxrwxr-x, 3, vagrant, www-data, 4096, Apr, 25, 14:12]
136
+ properties = (last_command_result || '').split(' ')
137
+ # property mapping to the number of the array element
138
+ case property
139
+ when 'permissions'
140
+ property = 0
141
+ when 'owner'
142
+ property = 2
143
+ when 'group'
144
+ property = 3
145
+ else
146
+ raise ArgumentError, 'The given property can not be mapped.'
147
+ end
148
+ properties.at(property) if property.between?(0, properties.count)
149
+ end
150
+
151
+ # Checks, if the actually permissions include the expected user permission
152
+ #
153
+ # @param all_permissions [String] Example: -rwxr-xr--
154
+ # @param examined_user_permission [String] Example: w
155
+ # @return [Boolean]
156
+ def user_has_permission?(all_permissions, examined_user_permission)
157
+ user_permissions = all_permissions[1, 3].delete('-') # Example -rwxr-xr-- -> rwx
158
+ user_permissions.include?(examined_user_permission)
159
+ end
160
+
161
+ # Checks, if the actually permissions include the expected group permission
162
+ #
163
+ # @param all_permissions [String] Example: -rwxr-xr--
164
+ # @param examined_group_permission [String] Example: w
165
+ # @return [Boolean]
166
+ def group_has_permission?(all_permissions, examined_group_permission)
167
+ group_permissions = all_permissions[4, 3].delete('-') # Example -rwxr-xr-- -> rx
168
+ group_permissions.include?(examined_group_permission)
169
+ end
170
+
171
+ # Checks, if the actually permissions include the expected others permission
172
+ #
173
+ # @param all_permissions [String] Example: -rwxr-xr--
174
+ # @param examined_others_permission [String] Example: r
175
+ # @return [Boolean]
176
+ def others_has_permission?(all_permissions, examined_others_permission)
177
+ others_permissions = all_permissions[7, 3].delete('-') # Example -rwxr-xr-- -> r
178
+ others_permissions.include?(examined_others_permission)
179
+ end
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,3 @@
1
+ When(/I wait (.*) seconds?/) do |seconds|
2
+ sleep(seconds.to_i)
3
+ end
@@ -0,0 +1,15 @@
1
+ Given(/^I provoke an exception for testing purposes before symlinking the new release$/) do
2
+ extension_content = "after 'deploy:updating', 'deploy:fail'"
3
+ file_name = TEST_APPLICATION.config_dev_path
4
+
5
+ Aruba.platform.mkdir(File.dirname(file_name))
6
+ File.open(file_name, 'a') { |f| f << "\n#{extension_content}\n" }
7
+ end
8
+
9
+ Given(/^I provoke an exception for testing purposes after symlinking the new release$/) do
10
+ extension_content = "before 'deploy:finishing', 'deploy:fail'"
11
+ file_name = TEST_APPLICATION.config_dev_path
12
+
13
+ Aruba.platform.mkdir(File.dirname(file_name))
14
+ File.open(file_name, 'a') { |f| f << "\n#{extension_content}\n" }
15
+ end
@@ -0,0 +1,30 @@
1
+ Given(/^I want to use the database `(.*)`$/) do |database|
2
+ @database_name = database
3
+ mysql_client = instantiate_mysql_client
4
+ mysql_client.query "DROP DATABASE IF EXISTS #{mysql_client.escape(@database_name)};"
5
+ mysql_client.query "CREATE DATABASE #{mysql_client.escape(@database_name)};"
6
+ end
7
+
8
+ Then(/^the database (should|should not) have a table `(.*)` with column `(.*)`$/) do |should_or_not, table, column|
9
+ mysql_client = instantiate_mysql_client
10
+ query_string = "SELECT COUNT(*) AS number_of_columns
11
+ FROM information_schema.columns
12
+ WHERE table_schema = '#{mysql_client.escape(@database_name)}'
13
+ AND table_name = '#{mysql_client.escape(table)}'
14
+ AND column_name = '#{mysql_client.escape(column)}';"
15
+ result = mysql_client.query query_string
16
+ number_of_columns = result.first.fetch('number_of_columns')
17
+ expectation = should_or_not == 'should' ? 1 : 0
18
+ expect(number_of_columns).to eq expectation
19
+ end
20
+
21
+ Then(/^the database (should|should not) have a value `(.*)` in table `(.*)` for column `(.*)`$/) do |should_or_not, row, table, column|
22
+ mysql_client = instantiate_mysql_client
23
+ query_string = "SELECT COUNT(*) AS number_of_rows
24
+ FROM #{mysql_client.escape(@database_name)}.#{mysql_client.escape(table)}
25
+ WHERE #{mysql_client.escape(column)} = '#{mysql_client.escape(row)}';"
26
+ result = mysql_client.query query_string
27
+ number_of_rows = result.first.fetch('number_of_rows')
28
+ expectation = should_or_not == 'should' ? 1 : 0
29
+ expect(number_of_rows).to eq expectation
30
+ end
@@ -0,0 +1,143 @@
1
+ # Creates a file on the remote server with the pre defined content
2
+ #
3
+ # @yieldparam path [String] the file name
4
+ # @yieldparam file_content [String] the content to be inserted in the file
5
+ Given(/^a remote file named "([^"]*)" with:$/) do |path, file_content|
6
+ path = resolve_path path
7
+ TEST_APPLICATION.remote.create_file path, file_content
8
+ end
9
+
10
+ # Creates an empty file on the remote server
11
+ #
12
+ # @yieldparam path [String] the file name
13
+ Given(/^a remote empty file named "([^"]*)"$/) do |path|
14
+ path = resolve_path path
15
+ TEST_APPLICATION.remote.run("mkdir -p #{File.dirname(path)}")
16
+ TEST_APPLICATION.remote.run("touch #{path}")
17
+ end
18
+
19
+ # Creates a directory on the remote server
20
+ #
21
+ # @yieldparam path [String] the directory to be created
22
+ Given(/^a remote directory named "([^"]*)"$/) do |path|
23
+ path = resolve_path path
24
+ TEST_APPLICATION.remote.create_directory path
25
+ end
26
+
27
+ # Test if the remote directory exists.
28
+ #
29
+ # @yieldparam path [String] the name of the target directory
30
+ # @yieldparam should_or_not [String] decides if it should be tested in a positive or a negative way
31
+ #
32
+ Then(/^a remote directory named "([^"]*)" (should|should not) exist$/) do |path, should_or_not|
33
+ path = resolve_path path
34
+ decision = TEST_APPLICATION.remote.directory_exists?(path)
35
+ if should_or_not == 'should'
36
+ expect(decision).to be true
37
+ else
38
+ expect(decision).to be false
39
+ end
40
+ end
41
+
42
+ # Test if the remote file exists.
43
+ #
44
+ # @yieldparam remote_path [String] the name of the file
45
+ # @yieldparam should_or_not [String] decides if it should be tested in a positive or a negative way
46
+ Then(/^a remote file named "([^"]*)" (should|should not) exist$/) do |path, should_or_not|
47
+ path = resolve_path path
48
+ decision = TEST_APPLICATION.remote.file_exists?(path)
49
+ if should_or_not == 'should'
50
+ expect(decision).to be true
51
+ else
52
+ expect(decision).to be false
53
+ end
54
+ end
55
+
56
+ # Test if the remote symlink exists.
57
+ #
58
+ # @yieldparam remote_path [String] the name of the symlink
59
+ # @yieldparam should_or_not [String] decides if it should be tested in a positive or a negative way
60
+ Then(/^a remote symlink named "([^"]*)" (should|should not) exist$/) do |path, should_or_not|
61
+ path = resolve_path path
62
+ decision = TEST_APPLICATION.remote.symlink_exists?(path)
63
+ if should_or_not == 'should'
64
+ expect(decision).to be true
65
+ else
66
+ expect(decision).to be false
67
+ end
68
+ end
69
+
70
+ # Test if the remote file content matches the test string.
71
+ #
72
+ # @yieldparam path [String] file path on the remote server
73
+ # @yieldparam exact_content [String] the content to be tested with
74
+ Then(/^the remote file "([^"]*)" should contain exactly:$/) do |path, exact_content|
75
+ path = resolve_path path
76
+ content = TEST_APPLICATION.remote.get_file_content(path)
77
+ expect(content).to eq exact_content
78
+ end
79
+
80
+ # Test if the owner of the remote resource matches the expected one
81
+ #
82
+ # @yieldparam resource [String] file or directory on the remote server
83
+ # @yieldparam owner [String] the expected unix owner of the remote resource
84
+ Then(/^remote owner of "([^"]*)" should be "([^"]*)"$/) do |path, owner|
85
+ path = resolve_path path
86
+ expect(TEST_APPLICATION.remote.get_resource_property(path, 'owner')).to eq owner
87
+ end
88
+
89
+ # Test if the group of the remote resource matches the expected one
90
+ #
91
+ # @yieldparam resource [String] file or directory on the remote server
92
+ # @yieldparam group [String] the expected unix group of the remote resource
93
+ Then(/^remote group of "([^"]*)" should be "([^"]*)"$/) do |path, group|
94
+ path = resolve_path path
95
+ expect(TEST_APPLICATION.remote.get_resource_property(path, 'group')).to eq group
96
+ end
97
+
98
+ # Test if the given resource contain the examined permission
99
+ #
100
+ # @yieldparam resource [String] file or directory on the remote server
101
+ # @yieldparam should_or_not [String] decides if it should be tested in a positive or a negative way
102
+ # @yieldparam permission [String] the unix permission. Possible values ['read', 'write', 'execute']
103
+ # @yieldparam permission_section [String] the unix permission section. Possible values ['user', 'group', 'others']
104
+ Then(/^remote permissions of "([^"]*)" (should|should not) contain "(user|group|others)" "(read|write|execute)"$/) do |path, should_or_not, permission_section, permission|
105
+ path = resolve_path path
106
+ all_permissions = TEST_APPLICATION.remote.get_resource_property(path, 'permissions')
107
+
108
+ case permission
109
+ when 'read'
110
+ permission = 'r'
111
+ when 'write'
112
+ permission = 'w'
113
+ when 'execute'
114
+ permission = 'x'
115
+ else
116
+ raise ArgumentError, 'The given permissions can not be mapped'
117
+ end
118
+
119
+ case permission_section
120
+ when 'user'
121
+ decision = TEST_APPLICATION.remote.user_has_permission?(all_permissions, permission)
122
+ when 'group'
123
+ decision = TEST_APPLICATION.remote.group_has_permission?(all_permissions, permission)
124
+ when 'others'
125
+ decision = TEST_APPLICATION.remote.others_has_permission?(all_permissions, permission)
126
+ else
127
+ raise ArgumentError, 'The given permissions can not be mapped'
128
+ end
129
+
130
+ if should_or_not == 'should'
131
+ expect(decision).to be true
132
+ else
133
+ expect(decision).to be false
134
+ end
135
+ end
136
+
137
+ When(/^I store the symlink source of current$/) do
138
+ @symlink_source_of_current = TEST_APPLICATION.remote.source_of_symlink(resolve_path('current_path'))
139
+ end
140
+
141
+ Then(/^the symlink source of current should not have changed$/) do
142
+ expect(TEST_APPLICATION.remote.source_of_symlink(resolve_path('current_path'))).to eq @symlink_source_of_current
143
+ end
@@ -0,0 +1,42 @@
1
+ # Install test application for capistrano
2
+ #
3
+ Given(/^a test app with the default configuration$/) do
4
+ TEST_APPLICATION.install
5
+ end
6
+
7
+ # Remove capistrano application at remote server
8
+ #
9
+ Given(/^the remote server is cleared$/) do
10
+ TEST_APPLICATION.remote.remove_deploy_to_path
11
+ end
12
+
13
+ # Extend the dev capistrano configuration to the given variable/value paar
14
+ #
15
+ # @yieldparam variable [String] the name of the variable to be set
16
+ # @yieldparam value [Object] the value of the variable to be set. Example: 'test' or Array.new
17
+ #
18
+ # Note: We used to call step %(I append to "#{TEST_APPLICATION.config_dev_path}" with "#{extension_content}\n")
19
+ # but this seems to be broken due to a wrong path expansion
20
+ When(/^I extend the development capistrano configuration variable (.+?) with value (.+?)$/) do |variable, value|
21
+ extension_content = "set :#{variable}, #{value}"
22
+ file_name = TEST_APPLICATION.config_dev_path
23
+
24
+ Aruba.platform.mkdir(File.dirname(file_name))
25
+ File.open(file_name, 'a') { |f| f << "\n#{extension_content}\n" }
26
+ end
27
+
28
+ # Extend the dev capistrano configuration to the content from the given fixture file
29
+ #
30
+ # @yieldparam file [String] the fixture file which content should extend capistrano configuration
31
+ When(/^I extend the development capistrano configuration from the fixture file (.+?)$/) do |file|
32
+ extension_content = File.read(File.join(TEST_APPLICATION.capistrano_configuration_fixtures_path, file))
33
+ file_name = TEST_APPLICATION.config_dev_path
34
+
35
+ Aruba.platform.mkdir(File.dirname(file_name))
36
+ File.open(file_name, 'a') { |f| f << "\n#{extension_content}\n" }
37
+ end
38
+
39
+ # Execute the cap deploy task on the dev server
40
+ When(/^the project is deployed$/) do
41
+ step 'I successfully run `cap dev deploy`'
42
+ end
@@ -0,0 +1,2 @@
1
+ # Loads steps from directory `./step_definitions'.
2
+ Dir.glob(File.expand_path('../step_definitions/*.rb', __FILE__)).each { |step_file| require step_file }
@@ -0,0 +1,15 @@
1
+ module Dkdeploy
2
+ module TestEnvironment
3
+ # Class for version number
4
+ #
5
+ class Version
6
+ MAJOR = 1
7
+ MINOR = 0
8
+ PATCH = 0
9
+
10
+ def self.to_s
11
+ [MAJOR, MINOR, PATCH].join('.')
12
+ end
13
+ end
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dkdeploy-test_environment
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Lars Tode
8
+ - Timo Webler
9
+ - Kieran Hayes
10
+ - Nicolai Reuschling
11
+ - Johannes Goslar
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+ date: 2016-06-20 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: bundler
19
+ requirement: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "~>"
22
+ - !ruby/object:Gem::Version
23
+ version: 1.12.5
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - "~>"
29
+ - !ruby/object:Gem::Version
30
+ version: 1.12.5
31
+ - !ruby/object:Gem::Dependency
32
+ name: rake
33
+ requirement: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - "~>"
36
+ - !ruby/object:Gem::Version
37
+ version: '11.2'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - "~>"
43
+ - !ruby/object:Gem::Version
44
+ version: '11.2'
45
+ - !ruby/object:Gem::Dependency
46
+ name: rspec
47
+ requirement: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - "~>"
50
+ - !ruby/object:Gem::Version
51
+ version: '3.4'
52
+ type: :runtime
53
+ prerelease: false
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - "~>"
57
+ - !ruby/object:Gem::Version
58
+ version: '3.4'
59
+ - !ruby/object:Gem::Dependency
60
+ name: cucumber
61
+ requirement: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - "~>"
64
+ - !ruby/object:Gem::Version
65
+ version: '2.3'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '2.3'
73
+ - !ruby/object:Gem::Dependency
74
+ name: rubocop
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '0.40'
80
+ type: :runtime
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: '0.40'
87
+ - !ruby/object:Gem::Dependency
88
+ name: aruba
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '0.14'
94
+ type: :runtime
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '0.14'
101
+ - !ruby/object:Gem::Dependency
102
+ name: mysql2
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: 0.3.21
108
+ type: :runtime
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: 0.3.21
115
+ - !ruby/object:Gem::Dependency
116
+ name: pry
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: 0.10.1
122
+ type: :runtime
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: 0.10.1
129
+ - !ruby/object:Gem::Dependency
130
+ name: sshkit
131
+ requirement: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - "~>"
134
+ - !ruby/object:Gem::Version
135
+ version: 1.10.0
136
+ type: :runtime
137
+ prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - "~>"
141
+ - !ruby/object:Gem::Version
142
+ version: 1.10.0
143
+ description: test infrastructure for dkdeploy
144
+ email:
145
+ - lars.tode@dkd.de
146
+ - timo.webler@dkd.de
147
+ - kieran.hayes@dkd.de
148
+ - nicolai.reuschling@dkd.de
149
+ - johannes.goslar@dkd.de
150
+ executables: []
151
+ extensions: []
152
+ extra_rdoc_files: []
153
+ files:
154
+ - ".gitignore"
155
+ - ".rubocop.yml"
156
+ - CONTRIBUTORS.md
157
+ - Gemfile
158
+ - LICENSE
159
+ - README.md
160
+ - Rakefile
161
+ - dkdeploy-test_enviroment.gemspec
162
+ - lib/dkdeploy/test_environment.rb
163
+ - lib/dkdeploy/test_environment/application.rb
164
+ - lib/dkdeploy/test_environment/constants.rb
165
+ - lib/dkdeploy/test_environment/env.rb
166
+ - lib/dkdeploy/test_environment/mysql.rb
167
+ - lib/dkdeploy/test_environment/path.rb
168
+ - lib/dkdeploy/test_environment/remote.rb
169
+ - lib/dkdeploy/test_environment/step_definitions/common.rb
170
+ - lib/dkdeploy/test_environment/step_definitions/failing_on_purpose.rb
171
+ - lib/dkdeploy/test_environment/step_definitions/mysql.rb
172
+ - lib/dkdeploy/test_environment/step_definitions/remote_commands.rb
173
+ - lib/dkdeploy/test_environment/step_definitions/setup.rb
174
+ - lib/dkdeploy/test_environment/steps.rb
175
+ - lib/dkdeploy/test_environment/version.rb
176
+ homepage: https://github.com/dkdeploy/dkdeploy-test_environment
177
+ licenses:
178
+ - MIT
179
+ metadata: {}
180
+ post_install_message:
181
+ rdoc_options: []
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubyforge_project:
196
+ rubygems_version: 2.6.4
197
+ signing_key:
198
+ specification_version: 4
199
+ summary: dkdeploy-test_environment provides a test application for dkdeploy
200
+ test_files: []