spec: separate pact_config files

Seperate pact_config files for Canvas project and Generic Consumer
sub-project.

Change-Id: I9343c9f1137d0b0da6ef0c7880d502a8da85805a
Reviewed-on: https://gerrit.instructure.com/153889
Tested-by: Jenkins
Reviewed-by: Anju Reddy <areddy@instructure.com>
QA-Review: Anju Reddy <areddy@instructure.com>
Product-Review: Robert Lamb <rlamb@instructure.com>
QA-Review: Robert Lamb <rlamb@instructure.com>
This commit is contained in:
Robert Lamb 2018-06-14 14:30:40 -06:00
parent 18877eb7e2
commit 3965dc7781
8 changed files with 89 additions and 68 deletions

View File

@ -17,58 +17,7 @@
#
module PactConfig
# These constants ensure we use the correct strings and thus help avoid our
# accidentally breaking the contract tests
module Providers
CANVAS_LMS_API = 'Canvas LMS API'.freeze
CANVAS_API_VERSION = '0.10'.freeze
CANVAS_LMS_LIVE_EVENTS = 'Canvas LMS Live Events'.freeze
ALL = Providers.constants.map { |c| Providers.const_get(c) }.freeze
end
# Add new API and LiveEvents consumers to this Consumers module
module Consumers
GENERIC_CONSUMER = 'Generic Consumer'.freeze
QUIZ_LTI = 'Quiz LTI'.freeze
ALL = Consumers.constants.map { |c| Consumers.const_get(c) }.freeze
end
class << self
def pact_uri(pact_path:)
URI::HTTP.build(
scheme: protocol,
userinfo: "#{broker_username}:#{broker_password}",
host: broker_host,
path: "/#{pact_path}/#{consumer_tag}"
).to_s
end
def broker_uri
URI::HTTP.build(
scheme: protocol,
userinfo: "#{broker_username}:#{broker_password}",
host: broker_host
).to_s
end
def broker_host
ENV.fetch('PACT_BROKER_HOST', 'pact-broker.docker')
end
def consumer_tag
# jenkins_build? ? 'latest/master' : 'latest'
'latest'
end
def broker_password
ENV.fetch('PACT_BROKER_PASSWORD', 'broker')
end
def broker_username
ENV.fetch('PACT_BROKER_USERNAME', 'pact')
end
def mock_provider_service_base_uri
"localhost:#{mock_provider_service_port}"
end
@ -76,16 +25,5 @@ module PactConfig
def mock_provider_service_port
1234
end
def jenkins_build?
!ENV['JENKINS_URL'].nil?
end
private
def protocol
protocol = jenkins_build? ? 'https' : 'http'
ENV.fetch('PACT_BROKER_PROTOCOL', protocol)
end
end
end

View File

@ -27,8 +27,8 @@ Pact.configure do |config|
config.pactfile_write_order = :chronological
end
Pact.service_consumer PactConfig::Consumers::GENERIC_CONSUMER do
has_pact_with PactConfig::Providers::CANVAS_LMS_API do
Pact.service_consumer 'Generic Consumer' do
has_pact_with 'Canvas LMS API' do
mock_service :canvas_lms_api do
port PactConfig.mock_provider_service_port
pact_specification_version '2.0.0'

View File

@ -18,7 +18,7 @@
ENV["RAILS_ENV"] = ENV["RACK_ENV"]= "test"
require 'pact/provider/rspec'
require_relative '../../../../pact/pact_config'
require_relative '../pact_config'
require_relative '../../../spec_helper'
require_relative 'provider_states_for_consumer'

View File

@ -15,7 +15,7 @@
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
require_relative '../../../../pact/pact_config'
require_relative '../pact_config'
require_relative 'pact_setup'
PactConfig::Consumers::ALL.each do |consumer|
@ -332,4 +332,4 @@ PactConfig::Consumers::ALL.each do |consumer|
end
end
end
end
end

View File

@ -17,7 +17,7 @@
#
require 'pact/messages'
require_relative '../../../../pact/pact_config'
require_relative '../pact_config'
require_relative '../../../spec_helper'
Pact::Messages.pact_broker_url = PactConfig.broker_uri

View File

@ -0,0 +1,83 @@
#
# Copyright (C) 2015 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
module PactConfig
# These constants ensure we use the correct strings and thus help avoid our
# accidentally breaking the contract tests
module Providers
CANVAS_LMS_API = 'Canvas LMS API'.freeze
CANVAS_API_VERSION = '0.10'.freeze
CANVAS_LMS_LIVE_EVENTS = 'Canvas LMS Live Events'.freeze
ALL = Providers.constants.map { |c| Providers.const_get(c) }.freeze
end
# Add new API and LiveEvents consumers to this Consumers module
module Consumers
GENERIC_CONSUMER = 'Generic Consumer'.freeze
QUIZ_LTI = 'Quiz LTI'.freeze
ALL = Consumers.constants.map { |c| Consumers.const_get(c) }.freeze
end
class << self
def pact_uri(pact_path:)
URI::HTTP.build(
scheme: protocol,
userinfo: "#{broker_username}:#{broker_password}",
host: broker_host,
path: "/#{pact_path}/#{consumer_tag}"
).to_s
end
def broker_uri
URI::HTTP.build(
scheme: protocol,
userinfo: "#{broker_username}:#{broker_password}",
host: broker_host
).to_s
end
def broker_host
ENV.fetch('PACT_BROKER_HOST', 'pact-broker.docker')
end
def consumer_tag
# jenkins_build? ? 'latest/master' : 'latest'
'latest'
end
def broker_password
ENV.fetch('PACT_BROKER_PASSWORD', 'broker')
end
def broker_username
ENV.fetch('PACT_BROKER_USERNAME', 'pact')
end
def jenkins_build?
!ENV['JENKINS_URL'].nil?
end
private
def protocol
protocol = jenkins_build? ? 'https' : 'http'
ENV.fetch('PACT_BROKER_PROTOCOL', protocol)
end
end
end