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