spec/cloud/google_service_spec.rb in knife-google-2.0.0 vs spec/cloud/google_service_spec.rb in knife-google-2.1.0

- old
+ new

@@ -65,14 +65,23 @@ end describe '#connection' do it "returns a properly configured ComputeService" do compute_service = double("compute_service") + client_options = double("client_options") + allow(service).to receive(:connection).and_call_original + + expect(Google::Apis::ClientOptions).to receive(:new).and_return(client_options) + expect(client_options).to receive(:application_name=).with("knife-google") + expect(client_options).to receive(:application_version=).with(Knife::Google::VERSION) + expect(Google::Apis::ComputeV1::ComputeService).to receive(:new).and_return(compute_service) expect(service).to receive(:authorization).and_return("authorization_object") expect(compute_service).to receive(:authorization=).with("authorization_object") + expect(compute_service).to receive(:client_options=).with(client_options) + expect(service.connection).to eq(compute_service) end end describe '#authorization' do @@ -592,15 +601,39 @@ service_account = double("service_account") options = { service_account_name: "account_name", service_account_scopes: %w{scope1 scope2} } expect(Google::Apis::ComputeV1::ServiceAccount).to receive(:new).and_return(service_account) expect(service_account).to receive(:email=).with("account_name") + expect(service).to receive(:service_account_scope_url).with("scope1").and_return("https://www.googleapis.com/auth/scope1") + expect(service).to receive(:service_account_scope_url).with("scope2").and_return("https://www.googleapis.com/auth/scope2") expect(service_account).to receive(:scopes=).with([ "https://www.googleapis.com/auth/scope1", "https://www.googleapis.com/auth/scope2", ]) expect(service.instance_service_accounts_for(options)).to eq([service_account]) + end + end + + describe '#service_account_scope_url' do + it "returns the passed-in scope if it already looks like a scope URL" do + scope = "https://www.googleapis.com/auth/fake_scope" + expect(service.service_account_scope_url(scope)).to eq(scope) + end + + it "returns a properly-formatted scope URL if a short-name or alias is provided" do + expect(service).to receive(:translate_scope_alias).with("scope_alias").and_return("real_scope") + expect(service.service_account_scope_url("scope_alias")).to eq("https://www.googleapis.com/auth/real_scope") + end + end + + describe '#translate_scope_alias' do + it "returns a scope for a given alias" do + expect(service.translate_scope_alias("storage-rw")).to eq("devstorage.read_write") + end + + it "returns the passed-in scope alias if nothing matches in the alias map" do + expect(service.translate_scope_alias("fake_scope")).to eq("fake_scope") end end describe '#instance_tags_for' do it "returns nil if tags is nil" do