compose_cucumber 0.0.1

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: 7ce157fd89aede22d6a0e0f59c0e77b8909caede
4
+ data.tar.gz: 70d362d20fa1737d573e0ec6b65c2cb9fea0045e
5
+ SHA512:
6
+ metadata.gz: 134df74f93ed7a819d89742aeb0db15eae760a7f8eedfeff2e1c76a83101ace3383ea7fa8eb8bd54d48983f40f772209d29a5ed902ce41e789a64e1d76d1b855
7
+ data.tar.gz: 0e1f6a7b0a4c836216c785f7018975b3174e97c0ddd959ec50e6deb8ea00f819d433156deeb22a4c1a8f3e19bdd08db8a57e190091c28f28bd96e557e2116e44
data/.rubocop.yml ADDED
@@ -0,0 +1,45 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-03-29 02:41:14 +0200 using RuboCop version 0.38.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ Lint/RescueException:
11
+ Exclude:
12
+ - 'lib/compose_cucumber/world.rb'
13
+
14
+ # Offense count: 1
15
+ Metrics/AbcSize:
16
+ Max: 28
17
+
18
+ # Offense count: 13
19
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
20
+ # URISchemes: http, https
21
+ Metrics/LineLength:
22
+ Max: 130
23
+
24
+ # Offense count: 2
25
+ # Configuration parameters: CountComments.
26
+ Metrics/MethodLength:
27
+ Max: 17
28
+
29
+ # Offense count: 1
30
+ # Cop supports --auto-correct.
31
+ Performance/RedundantBlockCall:
32
+ Exclude:
33
+ - 'lib/compose_cucumber/world.rb'
34
+
35
+ # Offense count: 1
36
+ Style/ClassVars:
37
+ Exclude:
38
+ - 'lib/compose_cucumber/world.rb'
39
+
40
+ # Offense count: 1
41
+ Style/Documentation:
42
+ Exclude:
43
+ - 'spec/**/*'
44
+ - 'test/**/*'
45
+ - 'lib/compose_cucumber/world.rb'
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ gem 'rubocop'
3
+ gem 'docker-api'
4
+ gem 'cucumber'
5
+ gem 'gherkin_format'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Funkwerk AG
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # compose_cucumber
2
+
3
+ [![Build Status](https://travis-ci.org/funkwerk/compose_cucumber.svg)](https://travis-ci.org/funkwerk/compose_cucumber)
4
+
5
+ Test docker-compose applications with cucumber
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ task default: :build
2
+
3
+ desc 'Builds the Gem.'
4
+ task build: :test do
5
+ sh 'gem build compose_cucumber.gemspec'
6
+ end
7
+
8
+ desc 'Publishes the Gem'
9
+ task :push do
10
+ sh 'gem push compose_cucumber-0.0.1.gem'
11
+ end
12
+
13
+ desc 'Tests the application'
14
+ task test: :format
15
+ task test: :rubocop
16
+ task test: :cucumber
17
+
18
+ task :cucumber do
19
+ options = %w()
20
+ options.push '--tags ~@skip' unless ENV['skipped']
21
+ sh "RUBYLIB=lib:$RUBYLIB cucumber #{options * ' '}"
22
+ end
23
+
24
+ desc 'Checks ruby style'
25
+ task :rubocop do
26
+ sh 'rubocop'
27
+ end
28
+
29
+ task :format do
30
+ sh 'gherkin_format features/*.feature'
31
+ end
@@ -0,0 +1,12 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'compose_cucumber'
3
+ s.version = '0.0.1'
4
+ s.date = '2016-03-29'
5
+ s.summary = 'Cucumber Steps for Testing docker-compose applications'
6
+ s.description = 'cucumber/aruba is for testing command line applications like compose_cucumber for docker-compose applications.'
7
+ s.authors = ['Stefan Rohe']
8
+ s.homepage = 'http://github.com/funkwerk/compose_cucumber/'
9
+ s.files = `git ls-files`.split("\n")
10
+ s.executables = s.files.grep(%r{^bin/}) { |file| File.basename(file) }
11
+ s.add_runtime_dependency 'cucumber', ['~> 2.3']
12
+ end
@@ -0,0 +1,6 @@
1
+ version: "2"
2
+
3
+ services:
4
+ service:
5
+ image: ubuntu
6
+ command: /bin/sh -c 'echo "Test" && sleep 1000'
@@ -0,0 +1,35 @@
1
+ Feature: Controlling
2
+ As a DevOps,
3
+ I want to test my docker orchestration
4
+ so that I haven't broken anything once I change something
5
+
6
+ Scenario: Startable
7
+ When I start the application
8
+ Then 1 service is available
9
+
10
+ Scenario: Status
11
+ When I start the application
12
+ Then the exactly following services are available
13
+ | Name | Command | Image | Status | Ports |
14
+ | service | ...Test...sleep... | ubuntu | Up... | |
15
+
16
+ Scenario: Stoppable
17
+ Given I started the application
18
+ When I stop the application
19
+ Then 0 services are available
20
+
21
+ Scenario: Logging
22
+ When I start the application
23
+ Then the logs for service contain
24
+ """
25
+ ...Test...
26
+ """
27
+
28
+ Scenario: Scalable
29
+ Given I started the application
30
+ When I scale the application with
31
+ | Name | Count |
32
+ | service | 10 |
33
+ Then the following services are available
34
+ | Name | Count |
35
+ | service | 10 |
@@ -0,0 +1 @@
1
+ require 'compose_cucumber'
@@ -0,0 +1,2 @@
1
+ require 'compose_cucumber/steps'
2
+ require 'compose_cucumber/world'
@@ -0,0 +1,93 @@
1
+ Given(/^I started the application$/) do
2
+ docker_compose 'up -d'
3
+ end
4
+
5
+ When(/^I start the application$/) do
6
+ docker_compose 'up -d'
7
+ end
8
+
9
+ Given(/^I stopped the application$/) do
10
+ docker_compose 'stop'
11
+ end
12
+
13
+ When(/^I stop the application$/) do
14
+ docker_compose 'stop'
15
+ end
16
+
17
+ When(/^I scale the application with$/) do |table|
18
+ scales = table.hashes.map do |row|
19
+ assert row.key?('Name')
20
+ assert row.key?('Count')
21
+
22
+ "#{row['Name']}=#{row['Count']}"
23
+ end
24
+
25
+ docker_compose "scale #{scales * ' '}"
26
+ end
27
+
28
+ Then(/^the following services are available$/) do |table|
29
+ check_services table
30
+ end
31
+
32
+ Then(/^the exactly following services are available$/) do |table|
33
+ check_services table
34
+ actual = services.map { |service| service.info['Labels']['com.docker.compose.service'] }.uniq.sort
35
+ expected = table.hashes.map { |row| row['Name'] }.sort
36
+ assert_equal(expected, actual, "expected #{expected}, but got #{actual}")
37
+ end
38
+
39
+ Then(/^(\d+) services are available$/) do |count|
40
+ ensure_services count
41
+ end
42
+
43
+ Then(/^(1) service is available$/) do |count|
44
+ ensure_services count
45
+ end
46
+
47
+ def ensure_services(count)
48
+ actual = services.map { |service| service.info['Labels']['com.docker.compose.service'] }.uniq.sort.length
49
+ assert_equal(count.to_i, actual, "expected #{count}, but got #{actual} services")
50
+ end
51
+
52
+ def check_services(table)
53
+ table.hashes.each do |row|
54
+ assert row.key?('Name')
55
+ services = services_by_name row['Name']
56
+ service = services.first
57
+
58
+ row.each do |key, value|
59
+ next if key == 'Name'
60
+
61
+ if key == 'Count'
62
+ assert_equal(value.to_i, services.length, "Expected #{value} services, but got #{services.length}")
63
+ next
64
+ end
65
+ assert(service.info.key?(key), "service #{service.info} should have key #{key}")
66
+ actual = service.info[key]
67
+ actual = actual.map { |port| format_port(port) } if key == 'Ports'
68
+ actual = actual.join ', ' if actual.is_a? Array
69
+ assert actual.match(value), "#{actual} should match #{value}"
70
+ end
71
+ end
72
+ end
73
+
74
+ Then(/^the logs for (.+) contain$/) do |service, string|
75
+ matcher = to_regex string
76
+
77
+ def check(service, matcher, string)
78
+ actual = service_logs service
79
+ assert actual.match(matcher), "#{actual} should contain #{string}"
80
+ end
81
+
82
+ eventually { check(service, matcher, string) }
83
+ end
84
+
85
+ def format_port(actual)
86
+ return "#{actual['IP']}:#{actual['PublicPort']}" if actual.key? 'IP'
87
+
88
+ actual['PublicPort'].to_s
89
+ end
90
+
91
+ def to_regex(matcher)
92
+ "^#{matcher.gsub('.', '\.').gsub('\.\.\.', '.*')}$"
93
+ end
@@ -0,0 +1,67 @@
1
+ require 'test/unit/assertions'
2
+
3
+ module ComposeWorld
4
+ require 'docker'
5
+
6
+ include Test::Unit::Assertions
7
+
8
+ @@project = 'cucumber'
9
+
10
+ def docker_compose(command)
11
+ require 'open3'
12
+
13
+ Open3.popen3("docker-compose --project #{@@project} #{command}") do |_stdin, stdout, stderr, wait_thr|
14
+ exit_status = wait_thr.value
15
+
16
+ assert_equal(exit_status.exitstatus, 0, "stderr: #{stderr}\nstdout: #{stdout}")
17
+ return stdout
18
+ end
19
+ end
20
+
21
+ def services
22
+ candidates = Docker::Container.all
23
+ candidates.select! { |service| service.info.key?('Labels') }
24
+ candidates.select! { |service| service.info['Labels']['com.docker.compose.project'] == @@project }
25
+ candidates
26
+ end
27
+
28
+ def services_by_name(name)
29
+ candidates = services.select { |service| service.info['Labels']['com.docker.compose.service'] == name }
30
+ assert_not_nil candidates
31
+ candidates
32
+ end
33
+
34
+ def services_id(name)
35
+ candidates = services.select { |service| service.info['Labels']['com.docker.compose.service'] == name }
36
+ assert_not_nil candidates
37
+ candidates.map { |service| service[:id] }
38
+ end
39
+
40
+ def service_logs(name)
41
+ candidates = services.select { |service| service.info['Labels']['com.docker.compose.service'] == name }
42
+ assert_not_nil candidates
43
+ # TODO: not just logs for the first service and should use logs since last container start
44
+ candidates.first.logs(stdout: true, stderr: true)
45
+ end
46
+
47
+ def eventually(timeout = 30, &block)
48
+ assert_not_nil block
49
+ error = nil
50
+ start = Time.now
51
+ while (Time.now - start) < timeout
52
+ begin
53
+ return block.call
54
+ rescue Exception => assertion
55
+ error = assertion
56
+ sleep 0.1
57
+ end
58
+ end
59
+ raise error
60
+ end
61
+ end
62
+
63
+ World(Test::Unit::Assertions, ComposeWorld)
64
+
65
+ Before do
66
+ docker_compose 'stop'
67
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: compose_cucumber
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stefan Rohe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cucumber
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.3'
27
+ description: cucumber/aruba is for testing command line applications like compose_cucumber
28
+ for docker-compose applications.
29
+ email:
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rubocop.yml"
35
+ - ".travis.yml"
36
+ - Gemfile
37
+ - LICENSE
38
+ - README.md
39
+ - Rakefile
40
+ - compose_cucumber.gemspec
41
+ - docker-compose.yml
42
+ - features/controlling.feature
43
+ - features/support/env.rb
44
+ - lib/compose_cucumber.rb
45
+ - lib/compose_cucumber/steps.rb
46
+ - lib/compose_cucumber/world.rb
47
+ homepage: http://github.com/funkwerk/compose_cucumber/
48
+ licenses: []
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.2.2
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Cucumber Steps for Testing docker-compose applications
70
+ test_files: []