diff --git a/lib/kong.rb b/lib/kong.rb index c92d3fe..eedda39 100644 --- a/lib/kong.rb +++ b/lib/kong.rb @@ -1,5 +1,7 @@ require 'kong/version' require_relative 'kong/base' +require_relative 'kong/rootless' +require_relative 'kong/collection' require_relative 'kong/api' require_relative 'kong/belongs_to_api' require_relative 'kong/client' diff --git a/lib/kong/api.rb b/lib/kong/api.rb index 3cba30a..2c1f69c 100644 --- a/lib/kong/api.rb +++ b/lib/kong/api.rb @@ -13,7 +13,7 @@ class Api ## # @return [Array] def plugins - Plugin.list({ api_id: self.id }) + Plugin.list({ api_id: self.id }, client: self.client) end end end diff --git a/lib/kong/base.rb b/lib/kong/base.rb index 5f89675..d0a2fc0 100644 --- a/lib/kong/base.rb +++ b/lib/kong/base.rb @@ -4,36 +4,46 @@ module ClassMethods # List resources # @return [Array] - def list(params = {}) + def list(params = {}, opts = {}) + opts = {} if opts.nil? + client = opts[:client] ? opts[:client] : Client.instance + collection = opts[:collection] ? opts[:collection] : Collection.new(self, client) + api_end_point = opts[:api_end_point] ? opts[:api_end_point] : self::API_END_POINT result = [] - json_data = Client.instance.get(self::API_END_POINT, params) + json_data = client.get(api_end_point, params) if json_data['data'] json_data['data'].each do |instance| - result << self.new(instance) + result << self.new(instance, { client: client, collection: collection }) end end result end - alias_method :all, :list + def all(params = {}, opts = {}) + self.list({ size: 9999999 }, opts) + end + + def first(opts={}) + self.list({},opts).first + end # Create resource # @param [Hash] attributes - def create(attributes = {}) - self.new(attributes).create + def create(attributes = {}, opts = {}) + self.new(attributes, opts).create end # Find resource # @param [String] id - def find(id) - self.new.get(id) + def find(id, opts = {}) + self.new({}, opts).get(id) end def method_missing(method, *arguments, &block) if method.to_s.start_with?('find_by_') attribute = method.to_s.sub('find_by_', '') if self.attribute_names.include?(attribute) - self.list({ attribute => arguments[0] })[0] + self.list({ attribute => arguments[0] }, arguments[1])[0] else super end @@ -57,6 +67,7 @@ def respond_to?(method, include_private = false) end attr_accessor :attributes, :api_end_point + attr_reader :client, :collection def self.included(base) base.extend(ClassMethods) @@ -72,18 +83,13 @@ def self.included(base) ## # @param [Hash] attributes - def initialize(attributes = {}) + def initialize(attributes = {}, opts = {}) + @client = opts[:client] ? opts[:client] : Client.instance + @collection = opts[:collection] ? opts[:collection] : Collection.new(self.class, @client) init_api_end_point init_attributes(attributes) end - # Get Kong API client - # @return [Kong::Client] - def client - Client.instance - end - - # Get resource # @param [String] key def get(key = nil) @@ -104,13 +110,30 @@ def new? self.id.nil? end + def set(attributes) + self.attributes = attributes + self.attributes + end + + def to_s + self.attributes.to_s + end + + def to_json + self.attributes.to_json + end + + def inspect + self.attributes.inspect + end # Save resource to Kong def save create_or_update end # Create resource - def create + def create(attributes = {}) + attributes = self.attributes.merge(attributes) headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } response = client.post(@api_end_point, nil, attributes, headers) init_attributes(response) @@ -156,8 +179,12 @@ def respond_to?(method, include_private = false) def init_attributes(attributes) @attributes = {} + self.attributes = attributes + end + + def attributes=(attributes) attributes.each do |key, value| - @attributes[key.to_s] = value + @attributes[key.to_s] = value if self.class.attribute_names.include?(key.to_s) end use_consumer_end_point if respond_to?(:use_consumer_end_point) use_api_end_point if respond_to?(:use_api_end_point) diff --git a/lib/kong/belongs_to_api.rb b/lib/kong/belongs_to_api.rb index 76c1228..5fc8ba6 100644 --- a/lib/kong/belongs_to_api.rb +++ b/lib/kong/belongs_to_api.rb @@ -10,7 +10,7 @@ def use_api_end_point # Get Api resource # @return [Kong::Api] def api - @api ||= Api.find(self.api_id) + @api ||= Api.find(self.api_id, client: self.client) end # Set Api resource diff --git a/lib/kong/belongs_to_consumer.rb b/lib/kong/belongs_to_consumer.rb index ec35493..ce724cf 100644 --- a/lib/kong/belongs_to_consumer.rb +++ b/lib/kong/belongs_to_consumer.rb @@ -10,7 +10,7 @@ def use_consumer_end_point # Get Consumer resource # @return [Kong::Consumer] def consumer - @consumer ||= Consumer.find(self.consumer_id) + @consumer ||= Consumer.find(self.consumer_id, client: self.client) end # Set Consumer resource diff --git a/lib/kong/client.rb b/lib/kong/client.rb index e47d74c..1d72b5d 100644 --- a/lib/kong/client.rb +++ b/lib/kong/client.rb @@ -1,25 +1,25 @@ -require 'singleton' + require 'json' require 'excon' require_relative './error' module Kong class Client - class << self - attr_accessor :http_client - end - include Singleton - - attr_accessor :default_headers + attr_accessor :default_headers, :http_client, :api_url # Initialize api client # - def initialize + def initialize(url = nil) Excon.defaults[:ssl_verify_peer] = false if ignore_ssl_errors? - @api_url = api_url - self.class.http_client = Excon.new(@api_url, omit_default_port: true) + if url + @api_url = url + else + @api_url = self.class.api_url + end + @http_client = Excon.new(@api_url, omit_default_port: true) @default_headers = { 'Accept' => 'application/json' } + @collections = {} end def self.api_url @@ -28,22 +28,55 @@ def self.api_url def self.api_url=(url) @api_url = url - @http_client = Excon.new(self.api_url, omit_default_port: true) + @instance = self.new end - def http_client - self.class.http_client + def self.instance + @instance ||= self.new end - # Kong Admin API URL - # - # @return [String] - def api_url - self.class.api_url + def consumers + collection(Consumer) end - def api_url=(url) - @api_url = url + def apis + collection(Api) + end + + def oauth_apps + collection(OAuthApp) + end + + def oauth2_tokens + collection(OAuth2Token) + end + + def plugins + collection(Plugin) + end + + def targets + collection(Target) + end + + def info + get('/') + end + + def status + get('/status') + end + + def cluster + get('/cluster') + end + + def version + self.info['version'] rescue nil + end + + def remove_node(name) + delete("/cluster/nodes/#{name}") end @@ -161,6 +194,10 @@ def delete(path, body = nil, params = {}, headers = {}) private + def collection(klass) + @collections[klass.name] || @collections[klass.name] = Collection.new(klass, self) + end + ## # Get request headers # diff --git a/lib/kong/collection.rb b/lib/kong/collection.rb new file mode 100644 index 0000000..c36670d --- /dev/null +++ b/lib/kong/collection.rb @@ -0,0 +1,31 @@ +module Kong + class Collection + def initialize(klass, client, api_end_point = nil) + @klass = klass + @client = client + @api_end_point = api_end_point + end + + def first + self.list.first + end + + def last + self.all.last + end + + def method_missing(method, *arguments, &block) + opts = { client: @client, collection: self, api_end_point: @api_end_point } + if arguments.size == 0 + arguments = [{}, opts] + else + arguments << opts + end + @klass.send(method, *arguments) + end + + def respond_to?(method, include_private = false) + @klass.respond_to?(method, include_private) + end + end +end \ No newline at end of file diff --git a/lib/kong/consumer.rb b/lib/kong/consumer.rb index f7f0b00..a344c92 100644 --- a/lib/kong/consumer.rb +++ b/lib/kong/consumer.rb @@ -16,49 +16,28 @@ def delete # # @return [Array] def plugins - Plugin.list({ consumer_id: self.id }) + Plugin.list({ consumer_id: self.id }, client: self.client) end # List OAuth applications # # @return [Array] def oauth_apps - apps = [] - response = client.get("#{@api_end_point}#{self.id}/oauth2") rescue nil - if response - response['data'].each do |attributes| - apps << Kong::OAuthApp.new(attributes) - end - end - apps + Collection.new(OAuthApp, self.client, "#{@api_end_point}#{self.id}/oauth2").all end # List KeyAuth credentials # # @return [Array] def oauth2_tokens if self.custom_id - OAuth2Token.list({ authenticated_userid: self.custom_id }) + OAuth2Token.list({ authenticated_userid: self.custom_id }, client: self.client) else [] end @@ -76,28 +55,14 @@ def oauth2_tokens # # @return [Array] def acls - acls = [] - response = client.get("#{@api_end_point}#{self.id}/acls") rescue nil - if response - response['data'].each do |attributes| - acls << Kong::Acl.new(attributes) - end - end - acls + Collection.new(Acl, self.client, "#{@api_end_point}#{self.id}/acls").all end # List JWTs # # @return [Array] def jwts - apps = [] - response = client.get("#{@api_end_point}#{self.id}/jwt") rescue nil - if response - response['data'].each do |attributes| - apps << Kong::JWT.new(attributes) - end - end - apps + Collection.new(JWT, self.client, "#{@api_end_point}#{self.id}/jwt").all end end end diff --git a/lib/kong/oauth2_token.rb b/lib/kong/oauth2_token.rb index 1ab177c..0e6596e 100644 --- a/lib/kong/oauth2_token.rb +++ b/lib/kong/oauth2_token.rb @@ -8,7 +8,7 @@ class OAuth2Token # Get OAuthApp resource # @return [Kong::OAuthApp] def oauth_app - Kong::OAuthApp.find_by_id(self.credential_id) + Kong::OAuthApp.find_by_id(self.credential_id, client: self.client) end end end diff --git a/lib/kong/plugin.rb b/lib/kong/plugin.rb index 66fbb36..d3fff9e 100644 --- a/lib/kong/plugin.rb +++ b/lib/kong/plugin.rb @@ -8,24 +8,24 @@ class Plugin # Create resource def create - if attributes['config'] - attributes['config'].each do |key, value| - attributes["config.#{key}"] = value - end - attributes.delete('config') - end + transform_config_attributes! super end # update resource def update - if attributes['config'] - attributes['config'].each do |key, value| - attributes["config.#{key}"] = value - end - attributes.delete('config') - end + transform_config_attributes! super end + + protected + + def transform_config_attributes! + return unless attributes['config'] + attributes['config'].each do |key, value| + attributes["config.#{key}"] = value + end + attributes.delete('config') + end end end diff --git a/lib/kong/rootless.rb b/lib/kong/rootless.rb new file mode 100644 index 0000000..dd19990 --- /dev/null +++ b/lib/kong/rootless.rb @@ -0,0 +1,20 @@ +module Kong + module Rootless + module ClassMethods + def find(id, opts={}) + raise NotImplementedError, 'Kong does not support direct access to this resource' + end + + def list(params = {}, opts = {}) + raise NotImplementedError, 'Kong does not support direct access to this resource' + end + + def all(params = {}, opts = {}) + raise NotImplementedError, 'Kong does not support direct access to this resource' + end + end + def self.included(base) + base.extend(ClassMethods) + end + end +end \ No newline at end of file diff --git a/lib/kong/server.rb b/lib/kong/server.rb index 0c8e943..0fef4fe 100644 --- a/lib/kong/server.rb +++ b/lib/kong/server.rb @@ -5,19 +5,19 @@ def self.version end def self.info - Client.instance.get('/') + Client.instance.info end def self.status - Client.instance.get('/status') + Client.instance.status end def self.cluster - Client.instance.get('/cluster') + Client.instance.cluster end def self.remove_node(name) - Client.instance.delete("/cluster/nodes/#{name}") + Client.instance.remove_node(name) end end end diff --git a/lib/kong/target.rb b/lib/kong/target.rb index 62d1ef6..9aa4ac9 100644 --- a/lib/kong/target.rb +++ b/lib/kong/target.rb @@ -1,20 +1,14 @@ module Kong class Target include Base + include Rootless ATTRIBUTE_NAMES = %w(id upstream_id target weight).freeze API_END_POINT = '/targets/'.freeze - def self.find(id) - raise NotImplementedError, 'Kong does not support direct access to targets, you must go via an upstream' - end - - def self.list(params = {}) - raise NotImplementedError, 'Kong does not support direct access to targets, you must go via an upstream' - end - def initialize(attributes = {}) - super(attributes) + def initialize(attributes = {}, opts = {}) + super(attributes, opts) raise ArgumentError, 'You must specify an upstream_id' unless self.upstream_id end @@ -41,7 +35,7 @@ def use_upstream_end_point # Get Upstream resource # @return [Kong::Upstream] def upstream - @upstream ||= Upstream.find(self.upstream_id) + @upstream ||= Upstream.find(self.upstream_id, client: self.client) end # Set Upstream resource diff --git a/lib/kong/upstream.rb b/lib/kong/upstream.rb index 70c91cb..8b37848 100644 --- a/lib/kong/upstream.rb +++ b/lib/kong/upstream.rb @@ -9,7 +9,7 @@ class Upstream # @return [Array] def targets targets = [] - json_data = Client.instance.get("#{API_END_POINT}#{self.id}/targets") + json_data = self.client.get("#{API_END_POINT}#{self.id}/targets") if json_data['data'] json_data['data'].each do |target_data| diff --git a/spec/kong/api_spec.rb b/spec/kong/api_spec.rb index e7bfe08..c5161d9 100644 --- a/spec/kong/api_spec.rb +++ b/spec/kong/api_spec.rb @@ -25,7 +25,7 @@ describe '.plugins' do it 'requests plugins attached to Api' do subject.id = '12345' - expect(Kong::Plugin).to receive(:list).with({ api_id: subject.id }) + expect(Kong::Plugin).to receive(:list).with({ api_id: subject.id }, { client: Kong::Client.instance }) subject.plugins end end diff --git a/spec/kong/base_spec.rb b/spec/kong/base_spec.rb index b55abc4..3cca043 100644 --- a/spec/kong/base_spec.rb +++ b/spec/kong/base_spec.rb @@ -34,8 +34,9 @@ end describe '.all' do - it 'is alias of .list' do - expect(Klass.method(:list)).to eq(Klass.method(:all)) + it 'calls .list with size option' do + expect(Kong::Client.instance).to receive(:get).with('/resources/', {size: 9999999}).and_return({ data: [] }) + Klass.all end end @@ -60,6 +61,31 @@ end end + describe '#initialize' do + it 'initializes client object with shared Client' do + instance = Klass.new + expect(instance.client).to eq(Kong::Client.instance) + end + + it 'initializes collection object' do + instance = Klass.new + expect(instance.collection.is_a?(Kong::Collection)).to be_truthy + end + + context 'with opts' do + it 'uses given Client instance' do + instance = Klass.new({}, {client: Kong::Client.new('http://kong-api:8001')}) + expect(instance.client.api_url).to eq('http://kong-api:8001') + end + + it 'uses given Collection instance' do + consumer_collection = Kong::Collection.new(Kong::Consumer, Kong::Client.new('http://kong-api:8001')) + instance = Klass.new({}, {collection: consumer_collection}) + expect(instance.collection).to eq(consumer_collection) + end + end + end + describe '#get' do it 'creates GET /:resource_end_point/:id request' do expect(Kong::Client.instance).to receive(:get).with('/resources/12345').and_return({ data: [] }) diff --git a/spec/kong/client_spec.rb b/spec/kong/client_spec.rb index 638cd17..eab6c85 100644 --- a/spec/kong/client_spec.rb +++ b/spec/kong/client_spec.rb @@ -10,6 +10,24 @@ spy end + describe '.api_url=' do + it 'updates api_url attribute' do + described_class.api_url = 'http://kong-api:8001' + expect(described_class.api_url).to eq('http://kong-api:8001') + end + + it 'updates client instance' do + described_class.api_url = 'http://kong-api:8001' + expect(described_class.instance.api_url).to eq('http://kong-api:8001') + end + end + + describe '.instance' do + it 'returns shared instance' do + expect(described_class.instance.is_a?(described_class)).to be_truthy + end + end + describe '#initialize' do it 'initializes Excon with Kong URI' do described_class.api_url = nil @@ -67,16 +85,74 @@ def client_params end end + describe '#consumers' do + it 'returns Collection object for Kong::Consumer' do + expect(Kong::Collection).to receive(:new).with(Kong::Consumer, subject).and_call_original + subject.consumers + end + end + + describe '#apis' do + it 'returns Collection object for Kong::Api' do + expect(Kong::Collection).to receive(:new).with(Kong::Api, subject).and_call_original + subject.apis + end + end + + describe '#oauth_apps' do + it 'returns Collection object for Kong::OAuthApp' do + expect(Kong::Collection).to receive(:new).with(Kong::OAuthApp, subject).and_call_original + subject.oauth_apps + end + end + + describe '#oauth2_tokens' do + it 'returns Collection object for Kong::OAuth2Token' do + expect(Kong::Collection).to receive(:new).with(Kong::OAuth2Token, subject).and_call_original + subject.oauth2_tokens + end + end + + describe '#plugins' do + it 'returns Collection object for Kong::Plugin' do + expect(Kong::Collection).to receive(:new).with(Kong::Plugin, subject).and_call_original + subject.plugins + end + end + + describe '#targets' do + it 'returns Collection object for Kong::Target' do + expect(Kong::Collection).to receive(:new).with(Kong::Target, subject).and_call_original + subject.targets + end + end + + describe '#info' do + it 'request root endpoint' do + expect(subject).to receive(:get).with('/') + subject.info + end + end + + describe '#status' do + it 'request status endpoint' do + expect(subject).to receive(:get).with('/status') + subject.status + end + end + + describe '#cluster' do + it 'request cluster endpoint' do + expect(subject).to receive(:get).with('/cluster') + subject.cluster + end + end + describe '#get' do before(:each) do allow(subject).to receive(:http_client).and_return(http_client) end it 'creates HTTP GET request with given params' do - http_client_params = { - path: 'path', - query: { key: 'value' }, - headers: {} - } response = spy allow(response).to receive(:status).and_return(200) expect(http_client).to receive(:get).and_return(response) @@ -84,11 +160,6 @@ def client_params end it 'raises Kong::Error if request returns error' do - http_client_params = { - path: 'path', - query: { key: 'value' }, - headers: {} - } response = spy allow(response).to receive(:status).and_return(403) expect(http_client).to receive(:get).and_return(response) @@ -98,11 +169,6 @@ def client_params end it 'parses response JSON' do - http_client_params = { - path: 'path', - query: { key: 'value' }, - headers: {} - } response = spy allow(response).to receive(:status).and_return(200) allow(response).to receive(:body).and_return({ id: '12345' }.to_json) @@ -112,11 +178,6 @@ def client_params end it 'returns response text' do - http_client_params = { - path: 'path', - query: { key: 'value' }, - headers: {} - } response = spy allow(response).to receive(:status).and_return(200) allow(response).to receive(:body).and_return('') @@ -131,11 +192,6 @@ def client_params allow(subject).to receive(:http_client).and_return(http_client) end it 'creates HTTP POST request with given params' do - http_client_params = { - path: 'path', - query: { key: 'value' }, - headers: {} - } response = spy allow(response).to receive(:status).and_return(200) expect(http_client).to receive(:post).and_return(response) @@ -144,11 +200,6 @@ def client_params it 'raises Kong::Error if request returns error' do - http_client_params = { - path: 'path', - query: { key: 'value' }, - headers: {} - } response = spy allow(response).to receive(:status).and_return(403) expect(http_client).to receive(:post).and_return(response) @@ -158,11 +209,6 @@ def client_params end it 'parses response JSON' do - http_client_params = { - path: 'path', - query: { key: 'value' }, - headers: {} - } response = spy allow(response).to receive(:status).and_return(200) allow(response).to receive(:body).and_return({ id: '12345' }.to_json) @@ -176,11 +222,6 @@ def client_params allow(subject).to receive(:http_client).and_return(http_client) end it 'creates HTTP PATCH request with given params' do - http_client_params = { - path: 'path', - query: { key: 'value' }, - headers: {} - } response = spy allow(response).to receive(:status).and_return(200) expect(http_client).to receive(:patch).and_return(response) @@ -189,11 +230,6 @@ def client_params it 'raises Kong::Error if request returns error' do - http_client_params = { - path: 'path', - query: { key: 'value' }, - headers: {} - } response = spy allow(response).to receive(:status).and_return(403) expect(http_client).to receive(:patch).and_return(response) @@ -203,11 +239,6 @@ def client_params end it 'parses response JSON' do - http_client_params = { - path: 'path', - query: { key: 'value' }, - headers: {} - } response = spy allow(response).to receive(:status).and_return(200) allow(response).to receive(:body).and_return({ id: '12345' }.to_json) @@ -222,11 +253,6 @@ def client_params allow(subject).to receive(:http_client).and_return(http_client) end it 'creates HTTP PUT request with given params' do - http_client_params = { - path: 'path', - query: { key: 'value' }, - headers: {} - } response = spy allow(response).to receive(:status).and_return(200) expect(http_client).to receive(:put).and_return(response) @@ -235,11 +261,6 @@ def client_params it 'raises Kong::Error if request returns error' do - http_client_params = { - path: 'path', - query: { key: 'value' }, - headers: {} - } response = spy allow(response).to receive(:status).and_return(403) expect(http_client).to receive(:put).and_return(response) @@ -249,11 +270,6 @@ def client_params end it 'parses response JSON' do - http_client_params = { - path: 'path', - query: { key: 'value' }, - headers: {} - } response = spy allow(response).to receive(:status).and_return(200) allow(response).to receive(:body).and_return({ id: '12345' }.to_json) @@ -268,11 +284,6 @@ def client_params allow(subject).to receive(:http_client).and_return(http_client) end it 'creates HTTP DELETE request with given params' do - http_client_params = { - path: 'path', - query: {}, - headers: {} - } response = spy allow(response).to receive(:status).and_return(204) expect(http_client).to receive(:delete).and_return(response) @@ -281,11 +292,6 @@ def client_params it 'raises Kong::Error if request returns other than 204' do - http_client_params = { - path: 'path', - query: {}, - headers: {} - } response = spy allow(response).to receive(:status).and_return(403) expect(http_client).to receive(:delete).and_return(response) diff --git a/spec/kong/consumer_spec.rb b/spec/kong/consumer_spec.rb index 28d2aa5..235730c 100644 --- a/spec/kong/consumer_spec.rb +++ b/spec/kong/consumer_spec.rb @@ -20,14 +20,14 @@ describe '#oauth_apps' do it 'requests consumer\'s oauth_apps' do subject.id = ':id' - expect(Kong::Client.instance).to receive(:get).with("/consumers/:id/oauth2") + expect(Kong::Client.instance).to receive(:get).with("/consumers/:id/oauth2", { size: 9999999 }) .and_return({ 'data' => [{ 'id' => '123456', 'name' => 'my app' }] }) subject.oauth_apps end it 'returns list of OAuthApp' do subject.id = ':id' - allow(Kong::Client.instance).to receive(:get).with("/consumers/:id/oauth2") + allow(Kong::Client.instance).to receive(:get).with("/consumers/:id/oauth2", { size: 9999999 }) .and_return({ 'data' => [{ 'id' => '123456', 'name' => 'my app' }] }) result = subject.oauth_apps expect(result.first.is_a?(Kong::OAuthApp)).to be_truthy @@ -38,7 +38,7 @@ context 'when custom_id is set' do it 'requests oauth2_tokens assigned to consumer' do subject.custom_id = 'custom_id' - expect(Kong::OAuth2Token).to receive(:list).with({ authenticated_userid: subject.custom_id }) + expect(Kong::OAuth2Token).to receive(:list).with({ authenticated_userid: subject.custom_id }, { client: Kong::Client.instance }) subject.oauth2_tokens end end @@ -56,14 +56,14 @@ describe '#acls' do it 'requests consumer\'s acls' do subject.id = ':id' - expect(Kong::Client.instance).to receive(:get).with("/consumers/:id/acls") + expect(Kong::Client.instance).to receive(:get).with("/consumers/:id/acls", { size: 9999999 }) .and_return({ 'data' => [{ 'id' => '123456', 'group' => 'group1' }] }) subject.acls end it 'returns list of Acls' do subject.id = ':id' - allow(Kong::Client.instance).to receive(:get).with("/consumers/:id/acls") + allow(Kong::Client.instance).to receive(:get).with("/consumers/:id/acls", { size: 9999999 }) .and_return({ 'data' => [{ 'id' => '123456', 'group' => 'group1' }] }) result = subject.acls expect(result.first.is_a?(Kong::Acl)).to be_truthy diff --git a/spec/kong/target_spec.rb b/spec/kong/target_spec.rb index f3eb40f..b9194ad 100644 --- a/spec/kong/target_spec.rb +++ b/spec/kong/target_spec.rb @@ -36,7 +36,7 @@ describe '.upstream' do it 'requests the attached Upstream' do - expect(Kong::Upstream).to receive(:find).with(upstream_id) + expect(Kong::Upstream).to receive(:find).with(upstream_id, { client: Kong::Client.instance }) subject.upstream end end