Skip to content

AcceptanceIsolatedEnvironment - add attr_accessor for :env to allow setting custom env vars#17

Open
jantman wants to merge 1 commit intohashicorp:mainfrom
jantman:additional_env
Open

AcceptanceIsolatedEnvironment - add attr_accessor for :env to allow setting custom env vars#17
jantman wants to merge 1 commit intohashicorp:mainfrom
jantman:additional_env

Conversation

@jantman
Copy link

@jantman jantman commented May 11, 2015

As I mentioned in #15, I was having serious issues with specs that actually run vagrant add and vagrant up and spin up a VirtualBox VM. It seems that VirtualBox was storing state between spec runs, which caused failures (VBox was dying with errors trying to read a VirtualBox.xml-tmp under a tmpdir from a previous spec).

This just adds an attr_accessor for env in AcceptanceIsolatedEnvironment, which allows setting environment variables after creation. These could be things like API credentials, or in my case (to solve the VirtualBox issue), environment.env['VBOX_USER_HOME'] = environment.homedir.to_s.

Essentially, this allows setting environment variables to values not known until after the IsolatedEnvironment is instantiated, such as values which include or are based on the tempdir path.

…etting custom env vars that may include homedir or workdir
jantman added a commit to jantman/vagrant-r10k that referenced this pull request May 15, 2015
@fnordfish
Copy link

I had a similar issue when upgrading vagrant-spec for vagrant-dns. Here is what I did:

# vagrant-spec.config.rb
Vagrant::Spec::Acceptance.configure do |c|
  # ...
  c.instance_variable_set(:@env, c.env.merge('VBOX_USER_HOME' => "{{homedir}}"))
end

The Vagrant::Spec::Acceptance::Configuration instance is passed into the AcceptanceIsolatedEnvironment and it's env is merged. However, there is no way of setting it (the nice way), hence the hacky instance_variable_set.

It would nice to convert the attr_reader :env into attr_accessor :env (https://github.com/mitchellh/vagrant-spec/blob/master/lib/vagrant-spec/acceptance/configuration.rb#L20)

@hashicorp-cla
Copy link

hashicorp-cla commented Dec 6, 2019

CLA assistant check
All committers have signed the CLA.

@soapy1 soapy1 changed the base branch from master to main October 16, 2020 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants