require_relative 'base' describe VagrantPlugins::Skytap::API::PublishSet do include_context "unit" include_context "rest_api" let(:json_path) { File.join(File.expand_path('..', __FILE__), 'support', 'api_responses') } let(:vm1_attrs) { read_json(json_path, 'vm1.json') } let(:vm2_attrs) { vm1_attrs.merge("id" => "6981851", "name" => "VM2") } let(:empty_environment_attrs) { read_json(json_path, 'empty_environment.json')} let(:empty_publish_set_attrs) { read_json(json_path, 'empty_publish_set.json')} let(:env_attrs) do empty_environment_attrs.dup.tap do |ret| ret['vms'] = [vm1_attrs, vm2_attrs] end end let(:iso_env) do # We have to create a Vagrantfile so there is a root path env = isolated_environment env.vagrantfile("") env.create_vagrant_env end let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) } let(:env) {{ machine: machine, api_client: api_client }} let(:environment) do VagrantPlugins::Skytap::API::Environment.new(env_attrs, env) end let(:attrs) do empty_publish_set_attrs.dup.tap do |ret| ret['vms'] = [ {"vm_ref" => "http://example.com/vms/#{vm1_attrs['id']}"} ] end end let(:instance) { described_class.new(attrs, environment, env) } let(:api_client) do # By default, all GET requests will return an environment with VM1, VM2, and 1 network double('api_client', get: double('resp', body: JSON.dump(attrs)) ) end # Ensure tests are not affected by Skytap credential environment variables before :each do ENV.stub(:[] => nil) end describe "vms" do subject do instance end it "returns only the vms in the publish_set" do expect(instance.vms.count).to eq(1) expect(instance.vms.first.name).to eq("VM1") end end describe "password_protected?" do subject do instance end it "returns false if not set" do expect(subject.password_protected?).to eq(false) end it "returns true if set" do w_pw = described_class.new(attrs.merge("password" => "*******"), environment, env) expect(w_pw.password_protected?).to eq(true) end end end