|
39 | 39 | allow(command_instance).to receive(:omnibus_install?).and_return true |
40 | 40 | allow(command_instance).to receive(:omnibus_embedded_bin_dir).and_return(omnibus_embedded_bin_dir) |
41 | 41 | allow(command_instance).to receive(:omnibus_bin_dir).and_return(omnibus_bin_dir) |
42 | | - allow(command_instance).to receive(:get_product_info).and_return(ChefCLI::Dist::PRODUCT) |
43 | 42 | command_instance.ui = ui |
44 | 43 | end |
45 | 44 |
|
|
82 | 81 | end |
83 | 82 | end |
84 | 83 | end |
85 | | - |
86 | | - describe "when running in a Chef-cli Habitat Standalone package" do |
87 | | - let(:standalone_pkg_base) { "/hab/pkgs/chef/chef-cli" } |
88 | | - let(:standalone_pkg_version) { "1.0.0" } |
89 | | - let(:standalone_pkg_build) { "20240210120000" } |
90 | | - let(:standalone_pkg_path) { "#{standalone_pkg_base}/#{standalone_pkg_version}/#{standalone_pkg_build}" } |
91 | | - |
92 | | - let(:ruby_version) { "3.1.0" } |
93 | | - let(:ruby_base) { "/hab/pkgs/core/ruby/#{ruby_version}/20240101000000/lib/ruby/gems" } |
94 | | - let(:cli_gem_home) { "/hab/pkgs/chef/chef-cli/#{standalone_pkg_version}/20240210121000/vendor/bundle/ruby/#{ruby_version}" } |
95 | | - |
96 | | - before do |
97 | | - allow(command_instance).to receive(:habitat_install?).and_return(true) |
98 | | - allow(command_instance).to receive(:habitat_standalone?).and_return(true) |
99 | | - allow(command_instance).to receive(:habitat_chef_dke?).and_return(false) |
100 | | - allow(command_instance).to receive(:omnibus_install?).and_return(false) |
101 | | - allow(command_instance).to receive(:get_product_info).and_return(ChefCLI::Dist::CHEF_CLI_PACKAGE) |
102 | | - |
103 | | - allow(command_instance).to receive(:get_pkg_install_path).and_return(standalone_pkg_path) |
104 | | - |
105 | | - allow(command_instance).to receive(:habitat_env).and_return({ |
106 | | - "GEM_ROOT" => ruby_base, |
107 | | - "GEM_HOME" => cli_gem_home, |
108 | | - "GEM_PATH" => cli_gem_home, |
109 | | - "PATH" => "#{standalone_pkg_path}/bin:/usr/local/bin:/usr/bin" |
110 | | - }) |
111 | | - |
112 | | - command_instance.ui = ui |
113 | | - end |
114 | | - |
115 | | - describe "and the env command is run" do |
116 | | - let(:yaml) { YAML.load(ui.output) } |
117 | | - |
118 | | - before :each do |
119 | | - run_command |
120 | | - end |
121 | | - |
122 | | - it "should include correct chef-cli hab pkg name" do |
123 | | - expect(yaml).to have_key(ChefCLI::Dist::CHEF_CLI_PACKAGE) |
124 | | - end |
125 | | - |
126 | | - it "should include correct chef-cli hab pkg version info" do |
127 | | - expect(yaml[ChefCLI::Dist::CHEF_CLI_PACKAGE]["Version"]).to eql ChefCLI::VERSION |
128 | | - end |
129 | | - |
130 | | - it "should include correct Habitat installation path" do |
131 | | - expect(yaml[ChefCLI::Dist::CHEF_CLI_PACKAGE]["Install Directory"]).to eql standalone_pkg_path |
132 | | - end |
133 | | - |
134 | | - it "should include correct GEM_ROOT path" do |
135 | | - expect(yaml["Ruby"]["RubyGems"]["Gem Environment"]["GEM ROOT"]).to eql ruby_base |
136 | | - end |
137 | | - |
138 | | - it "should include correct GEM_HOME path" do |
139 | | - expect(yaml["Ruby"]["RubyGems"]["Gem Environment"]["GEM HOME"]).to eql cli_gem_home |
140 | | - end |
141 | | - |
142 | | - it "should include correct GEM_PATH paths" do |
143 | | - expect(yaml["Ruby"]["RubyGems"]["Gem Environment"]["GEM PATHS"]).to eql [cli_gem_home] |
144 | | - end |
145 | | - end |
146 | | - end |
147 | | - |
148 | | - describe "when running chef-cli coming with Chef-DKE Habitat package" do |
149 | | - let(:hab_pkg_base) { "/hab/pkgs/chef/chef-development-kit-enterprise" } |
150 | | - let(:hab_pkg_version) { "1.0.0" } |
151 | | - let(:hab_pkg_build) { "20240210120000" } |
152 | | - let(:hab_pkg_path) { "#{hab_pkg_base}/#{hab_pkg_version}/#{hab_pkg_build}" } |
153 | | - |
154 | | - let(:ruby_version) { "3.1.0" } |
155 | | - let(:ruby_base) { "/hab/pkgs/core/ruby/#{ruby_version}/20240101000000/lib/ruby/gems" } |
156 | | - let(:cli_gem_home) { "/hab/pkgs/chef/chef-cli/#{hab_pkg_version}/20240210121000/vendor/bundle/ruby/#{ruby_version}" } |
157 | | - |
158 | | - before do |
159 | | - # Mock all Habitat-related methods |
160 | | - allow(command_instance).to receive(:habitat_install?).and_return true |
161 | | - allow(command_instance).to receive(:habitat_chef_dke?).and_return true |
162 | | - allow(command_instance).to receive(:habitat_standalone?).and_return false |
163 | | - allow(command_instance).to receive(:omnibus_install?).and_return false |
164 | | - allow(command_instance).to receive(:get_product_info).and_return(ChefCLI::Dist::CHEF_DK_CLI_PACKAGE) |
165 | | - |
166 | | - # Mock Habitat package paths |
167 | | - allow(command_instance).to receive(:get_pkg_install_path).and_return(hab_pkg_path) |
168 | | - |
169 | | - # Mock habitat_env to reflect correct GEM paths |
170 | | - allow(command_instance).to receive(:habitat_env).and_return({ |
171 | | - "GEM_ROOT" => ruby_base, |
172 | | - "GEM_HOME" => cli_gem_home, |
173 | | - "GEM_PATH" => cli_gem_home, |
174 | | - "PATH" => "#{hab_pkg_path}/bin:/usr/local/bin:/usr/bin" |
175 | | - }) |
176 | | - |
177 | | - command_instance.ui = ui |
178 | | - end |
179 | | - |
180 | | - describe "and the env command is run" do |
181 | | - let(:yaml) { YAML.load(ui.output) } |
182 | | - |
183 | | - before :each do |
184 | | - run_command |
185 | | - end |
186 | | - |
187 | | - it "should include correct product name for Chef-DKE Habitat package" do |
188 | | - expect(yaml).to have_key(ChefCLI::Dist::CHEF_DK_CLI_PACKAGE) |
189 | | - end |
190 | | - |
191 | | - it "should include correct version" do |
192 | | - expect(yaml[ChefCLI::Dist::CHEF_DK_CLI_PACKAGE]["Version"]).to eql ChefCLI::VERSION |
193 | | - end |
194 | | - |
195 | | - it "should include correct Habitat installation path" do |
196 | | - expect(yaml[ChefCLI::Dist::CHEF_DK_CLI_PACKAGE]["Install Directory"]).to eql hab_pkg_path |
197 | | - end |
198 | | - |
199 | | - it "should include correct GEM_ROOT path" do |
200 | | - expect(yaml["Ruby"]["RubyGems"]["Gem Environment"]["GEM ROOT"]).to eql ruby_base |
201 | | - end |
202 | | - |
203 | | - it "should include correct GEM_HOME path" do |
204 | | - expect(yaml["Ruby"]["RubyGems"]["Gem Environment"]["GEM HOME"]).to eql cli_gem_home |
205 | | - end |
206 | | - |
207 | | - it "should include correct GEM_PATH paths" do |
208 | | - expect(yaml["Ruby"]["RubyGems"]["Gem Environment"]["GEM PATHS"]).to eql [cli_gem_home] |
209 | | - end |
210 | | - end |
211 | | - end |
212 | | - |
213 | 84 | def run_command |
214 | 85 | command_instance.run_with_default_options(false, command_options) |
215 | 86 | end |
|
0 commit comments