rspec-qbec 0.0.1.beta.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +30 -0
- data/lib/rspec/qbec.rb +1 -1
- data/lib/rspec/qbec/helper.rb +44 -41
- data/lib/rspec/qbec/openstruct.rb +1 -0
- data/lib/rspec/qbec/version.rb +2 -1
- data/rspec-qbec.gemspec +4 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 208cb091bdd5f4fa03f5e59344850c602b0a8a974382cf4e9edb0e6d57e02e6a
|
4
|
+
data.tar.gz: 52d2b0f7f62618c0f1590f0b85148d2bc8b364712c0a8560fad37f5f035e280b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac7d83517a50eac2f2d7bbb394ae11244da1c36af33a181aeeb4f90df35c0dc07238565affe7bf634f5866583e86c66a19aad6dc5c92a2c7e1a617f0e04b1d2a
|
7
|
+
data.tar.gz: cba8c59695b5d8b4ef9dd3efb49d2129a141dcdf547841a694bad6b79196f4eb770704905c483a42067cf16026349f2a1cfc34c318b401e4aeb297bf2c584980
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
RSpec::Qbec
|
2
|
+
|
3
|
+
### Init
|
4
|
+
|
5
|
+
```rb
|
6
|
+
# spec_helper.rb
|
7
|
+
|
8
|
+
# Example:
|
9
|
+
require 'rspec/qbec'
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.qbec_root = 'qbec/project'
|
13
|
+
end
|
14
|
+
```
|
15
|
+
|
16
|
+
|
17
|
+
### Example test
|
18
|
+
|
19
|
+
```rb
|
20
|
+
let!(:cmd) { run_qbec('prod', '-c namespace') }
|
21
|
+
let!(:namespaces) { yaml(cmd[0], 'Namespaces') }
|
22
|
+
|
23
|
+
it 'have size' do
|
24
|
+
expect(namespaces.size).to eq(1)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'have name' do
|
28
|
+
expect(namespaces.metadata.name).to eq('myns')
|
29
|
+
end
|
30
|
+
```
|
data/lib/rspec/qbec.rb
CHANGED
data/lib/rspec/qbec/helper.rb
CHANGED
@@ -6,57 +6,60 @@ require 'tmpdir'
|
|
6
6
|
|
7
7
|
module RSpec
|
8
8
|
module Qbec
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
run("qbec --root #{RSpec.configuration.qbec_root} show #{args} #{env}")
|
15
|
-
end
|
9
|
+
# Helpers for run and parse qbec output
|
10
|
+
module Helpers
|
11
|
+
def run(cmd)
|
12
|
+
Open3.capture3(cmd)
|
13
|
+
end
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
when Hash
|
20
|
-
OpenStruct.new(object.transform_values { |v| to_ostruct(v) })
|
21
|
-
when Array
|
22
|
-
object.map { |x| to_ostruct(x) }
|
23
|
-
else
|
24
|
-
object
|
15
|
+
def run_qbec(env = '', args = '')
|
16
|
+
run("qbec --root #{RSpec.configuration.qbec_root} show #{args} #{env}")
|
25
17
|
end
|
26
|
-
end
|
27
18
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
19
|
+
def to_ostruct(object)
|
20
|
+
case object
|
21
|
+
when Hash
|
22
|
+
OpenStruct.new(object.transform_values { |v| to_ostruct(v) })
|
23
|
+
when Array
|
24
|
+
object.map { |x| to_ostruct(x) }
|
25
|
+
else
|
26
|
+
object
|
27
|
+
end
|
33
28
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
|
30
|
+
def yaml(str, kind = '')
|
31
|
+
matches = str.split(/(?:\n+|\A)---(?:\n+|\Z)/m)
|
32
|
+
res = []
|
33
|
+
matches.each do |v|
|
34
|
+
res << to_ostruct(YAML.safe_load(v)) if v != ''
|
35
|
+
end
|
36
|
+
if kind != ''
|
37
|
+
kind = kind.downcase
|
38
|
+
res = res.select { |v| v.kind.downcase == kind }
|
39
|
+
end
|
40
|
+
res
|
37
41
|
end
|
38
|
-
res
|
39
|
-
end
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
-
|
43
|
+
def yaml_several(str, template)
|
44
|
+
match = str.match(/#{regexp_source(template)}\n(.+?)\n(# Source|\z)/m)
|
45
|
+
return if match.nil?
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
47
|
+
str_ar = match[1].split('---')
|
48
|
+
yamls = str_ar.each_with_object([]) do |el, res|
|
49
|
+
res << to_ostruct(YAML.safe_load(el))
|
50
|
+
end
|
51
|
+
yamls.reject { |el| el == false }.compact
|
48
52
|
end
|
49
|
-
yamls.reject { |el| el == false }.compact
|
50
|
-
end
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
def write_file(str)
|
55
|
+
file_path = ''
|
56
|
+
loop do
|
57
|
+
file_path = Dir.tmpdir + "/qbec_#{DateTime.now.strftime('%Q')}"
|
58
|
+
break unless File.exist?(file_path)
|
59
|
+
end
|
60
|
+
File.open(file_path, 'w') { |file| file.write(str) }
|
61
|
+
file_path
|
57
62
|
end
|
58
|
-
File.open(file_path, 'w') { |file| file.write(str) }
|
59
|
-
file_path
|
60
63
|
end
|
61
64
|
end
|
62
65
|
end
|
data/lib/rspec/qbec/version.rb
CHANGED
data/rspec-qbec.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require 'rspec/qbec/version'
|
@@ -10,13 +12,14 @@ Gem::Specification.new do |spec|
|
|
10
12
|
spec.email = 'stammru@gmail.com'
|
11
13
|
|
12
14
|
spec.summary = 'Helpers for qbec run'
|
13
|
-
spec.description = 'RSpec::
|
15
|
+
spec.description = 'RSpec::Qbec add helpers to run and read from qbec'
|
14
16
|
spec.homepage = 'https://github.com/stamm/rspec-qbec'
|
15
17
|
spec.license = 'MIT'
|
16
18
|
|
17
19
|
spec.files = `git ls-files -z`.split("\x0")
|
18
20
|
spec.test_files = spec.files.grep(/^spec/)
|
19
21
|
|
22
|
+
spec.require_paths = ['lib']
|
20
23
|
|
21
24
|
spec.add_runtime_dependency 'rspec', '~> 3'
|
22
25
|
spec.add_development_dependency 'bundler'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-qbec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rustam Zagirov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -52,13 +52,14 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description: RSpec::
|
55
|
+
description: RSpec::Qbec add helpers to run and read from qbec
|
56
56
|
email: stammru@gmail.com
|
57
57
|
executables: []
|
58
58
|
extensions: []
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
61
|
- ".gitignore"
|
62
|
+
- README.md
|
62
63
|
- lib/rspec/qbec.rb
|
63
64
|
- lib/rspec/qbec/helper.rb
|
64
65
|
- lib/rspec/qbec/openstruct.rb
|
@@ -79,9 +80,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
80
|
version: '0'
|
80
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
82
|
requirements:
|
82
|
-
- - "
|
83
|
+
- - ">="
|
83
84
|
- !ruby/object:Gem::Version
|
84
|
-
version:
|
85
|
+
version: '0'
|
85
86
|
requirements: []
|
86
87
|
rubygems_version: 3.1.2
|
87
88
|
signing_key:
|