kubernetes-cli 0.3.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,123 @@
1
+ # typed: false
2
+ require 'rspec/expectations'
3
+
4
+ class TestCommand
5
+ def initialize(env, cmd_s)
6
+ @env = env
7
+ @cmd_s = cmd_s
8
+ @cmd = cmd_s.split(' ')
9
+ end
10
+
11
+ def includes?(args)
12
+ @cmd.each_cons(args.size).any? do |sub_cmd|
13
+ sub_cmd == args
14
+ end
15
+ end
16
+
17
+ def excludes?(args)
18
+ @cmd.each_cons(args.size).all? do |sub_cmd|
19
+ sub_cmd != args
20
+ end
21
+ end
22
+
23
+ def redirects_to?(path)
24
+ @cmd[-2..-1] == ['>', path]
25
+ end
26
+ end
27
+
28
+ module CommandHelpers
29
+ def self.handle_commands(commands)
30
+ @with_args ||= []
31
+ @without_args ||= []
32
+ @missing = []
33
+ @extra = []
34
+ @missing_redirect = false
35
+
36
+ commands.map! { |env, cmd_s| TestCommand.new(env, cmd_s) }
37
+
38
+ @matching_commands = commands.select do |cmd|
39
+ missing_for_cmd = []
40
+
41
+ @with_args.each do |with_args|
42
+ missing_for_cmd << with_args unless cmd.includes?(with_args)
43
+ end
44
+
45
+ @missing << missing_for_cmd unless missing_for_cmd.empty?
46
+ missing_for_cmd.empty?
47
+ end
48
+
49
+ @matching_commands.select! do |cmd|
50
+ extra_for_cmd = []
51
+
52
+ @without_args.each do |without_args|
53
+ extra_for_cmd << without_args unless cmd.excludes?(without_args)
54
+ end
55
+
56
+ @extra << extra_for_cmd unless extra_for_cmd.empty?
57
+ extra_for_cmd.empty?
58
+ end
59
+
60
+ if @redirect_path
61
+ @matching_commands.select! do |cmd|
62
+ cmd.redirects_to?(@redirect_path).tap do |does_redirect|
63
+ @missing_redirect = true unless does_redirect
64
+ end
65
+ end
66
+ end
67
+
68
+ !@matching_commands.empty?
69
+ end
70
+
71
+ def self.failure_message
72
+ message_parts = [].tap do |message_parts|
73
+ if @matching_commands.empty?
74
+ return 'No commands were executed.'
75
+ end
76
+
77
+ unless @missing.empty?
78
+ missing_for_all = @missing[0].intersection(*@missing)
79
+ missing_str = missing_for_all.map { |m| " #{m.join(' ')}" }.join("\n")
80
+ message_parts << "expected at least one command to contain args:\n#{missing_str}"
81
+ end
82
+
83
+ unless @extra.empty?
84
+ extra_for_any = @extra[0].union(*@extra)
85
+ extra_str = extra_for_any.map { |m| " #{m.join(' ')}" }.join("\n")
86
+ message_parts << "at least one viable command contained unexpected args:\n#{extra_str}"
87
+ end
88
+
89
+ if @missing_redirect
90
+ message_parts << "at least one viable command did not redirect to #{@redirect_path}"
91
+ end
92
+ end
93
+
94
+ message_parts.join("\n\n")
95
+ end
96
+ end
97
+
98
+ RSpec::Matchers.define :run_exec do |_expected|
99
+ match do |actual|
100
+ instance_eval do
101
+ CommandHelpers.handle_commands(actual.exec_commands)
102
+ end
103
+ end
104
+
105
+ # args should be an array of arrays
106
+ chain :with_args do |*with_args|
107
+ @with_args = with_args
108
+ end
109
+
110
+ chain :without_args do |*without_args|
111
+ @without_args = without_args
112
+ end
113
+
114
+ chain :and_redirect_to do |path|
115
+ @redirect_path = path
116
+ end
117
+
118
+ failure_message do
119
+ instance_eval do
120
+ CommandHelpers.failure_message
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,31 @@
1
+ # typed: ignore
2
+
3
+ require 'kubectl-rb'
4
+ require 'kubernetes-cli'
5
+ require 'stringio'
6
+
7
+ class FakeStatus
8
+ attr_reader :exitstatus
9
+
10
+ def initialize(exitstatus)
11
+ @exitstatus = exitstatus
12
+ end
13
+
14
+ def success?
15
+ exitstatus == 0
16
+ end
17
+ end
18
+
19
+ class TestCLI < KubernetesCLI
20
+ attr_reader :exec_commands
21
+
22
+ def initialize(kubeconfig_path, executable = KubectlRb.executable)
23
+ @exec_commands = []
24
+
25
+ super
26
+ end
27
+
28
+ def exec(env, cmd)
29
+ @exec_commands << [env, cmd]
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ apiVersion: v1
2
+ kind: ConfigMap
3
+ metadata:
4
+ namespace: test
5
+ name: test-config-external
6
+ data:
7
+ key: external value
@@ -0,0 +1,8 @@
1
+ apiVersion: v1
2
+ kind: ConfigMap
3
+ metadata:
4
+ namespace: test
5
+ name: test-config-external
6
+ data:
7
+ key: external value
8
+ nonExistent: foo
@@ -0,0 +1,22 @@
1
+ # typed: true
2
+ require 'yaml'
3
+
4
+ class TestObject
5
+ def initialize(object)
6
+ @object = object
7
+ end
8
+
9
+ def to_resource
10
+ TestResource.new(@object)
11
+ end
12
+ end
13
+
14
+ class TestResource
15
+ def initialize(object)
16
+ @object = object
17
+ end
18
+
19
+ def to_yaml
20
+ YAML.dump(@object)
21
+ end
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kubernetes-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-06 00:00:00.000000000 Z
11
+ date: 2023-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kubectl-rb
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.1'
19
+ version: '0.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.1'
26
+ version: '0.2'
27
27
  description: Ruby wrapper around the Kubernetes CLI.
28
28
  email:
29
29
  - camertron@gmail.com
@@ -34,10 +34,19 @@ files:
34
34
  - CHANGELOG.md
35
35
  - Gemfile
36
36
  - LICENSE
37
+ - README.md
37
38
  - Rakefile
38
39
  - kubernetes-cli.gemspec
39
40
  - lib/kubernetes-cli.rb
40
41
  - lib/kubernetes-cli/version.rb
42
+ - rbi/kubernetes-cli.rbi
43
+ - spec/cli_spec.rb
44
+ - spec/spec_helper.rb
45
+ - spec/support/matchers.rb
46
+ - spec/support/test_cli.rb
47
+ - spec/support/test_config_map.yaml
48
+ - spec/support/test_config_map_bad.yaml
49
+ - spec/support/test_resource.rb
41
50
  homepage: http://github.com/getkuby/kubernetes-cli
42
51
  licenses:
43
52
  - MIT
@@ -57,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
66
  - !ruby/object:Gem::Version
58
67
  version: '0'
59
68
  requirements: []
60
- rubygems_version: 3.1.4
69
+ rubygems_version: 3.4.5
61
70
  signing_key:
62
71
  specification_version: 4
63
72
  summary: Ruby wrapper around the Kubernetes CLI.