Class: Pact::V2::Consumer::MockServer
- Inherits:
-
Object
- Object
- Pact::V2::Consumer::MockServer
show all
- Defined in:
- lib/pact/v2/consumer/mock_server.rb
Defined Under Namespace
Classes: MockServerCreateError, WritePactsError
Constant Summary
collapse
- TRANSPORT_HTTP =
"http"
- TRANSPORT_GRPC =
"grpc"
- CREATE_TRANSPORT_ERRORS =
{
-1 => {reason: :invalid_handle, status: -1, description: "An invalid handle was received. Handles should be created with pactffi_new_pact"},
-2 => {reason: :invalid_transport_json, status: -2, description: "Transport_config is not valid JSON"},
-3 => {reason: :mock_server_not_started, status: -3, description: "The mock server could not be started"},
-4 => {reason: :internal_error, status: -4, description: "The method panicked"},
-5 => {reason: :invalid_host, status: -5, description: "The address is not valid"}
}.freeze
- WRITE_PACT_FILE_ERRORS =
{
1 => {reason: :internal_error, status: 1, description: "A general panic was caught"},
2 => {reason: :file_not_accessible, status: 2, description: "The pact file was not able to be written"},
3 => {reason: :mock_server_not_found, status: 3, description: "A mock server with the provided port was not found"}
}.freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(pact:, transport:, host:, port:) ⇒ MockServer
Returns a new instance of MockServer.
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/pact/v2/consumer/mock_server.rb', line 46
def initialize(pact:, transport:, host:, port:)
@pact = pact
@transport = transport
@host = host
@port = port
@handle = init_transport!
@port = @handle
@url = "#{transport}://#{host}:#{@handle}"
end
|
Instance Attribute Details
#handle ⇒ Object
Returns the value of attribute handle.
9
10
11
|
# File 'lib/pact/v2/consumer/mock_server.rb', line 9
def handle
@handle
end
|
#host ⇒ Object
Returns the value of attribute host.
9
10
11
|
# File 'lib/pact/v2/consumer/mock_server.rb', line 9
def host
@host
end
|
#port ⇒ Object
Returns the value of attribute port.
9
10
11
|
# File 'lib/pact/v2/consumer/mock_server.rb', line 9
def port
@port
end
|
#transport ⇒ Object
Returns the value of attribute transport.
9
10
11
|
# File 'lib/pact/v2/consumer/mock_server.rb', line 9
def transport
@transport
end
|
#url ⇒ Object
Returns the value of attribute url.
9
10
11
|
# File 'lib/pact/v2/consumer/mock_server.rb', line 9
def url
@url
end
|
Class Method Details
.create_for_grpc!(pact:, host: "127.0.0.1", port: 0) ⇒ Object
34
35
36
|
# File 'lib/pact/v2/consumer/mock_server.rb', line 34
def self.create_for_grpc!(pact:, host: "127.0.0.1", port: 0)
new(pact: pact, transport: TRANSPORT_GRPC, host: host, port: port)
end
|
.create_for_http!(pact:, host: "127.0.0.1", port: 0) ⇒ Object
38
39
40
|
# File 'lib/pact/v2/consumer/mock_server.rb', line 38
def self.create_for_http!(pact:, host: "127.0.0.1", port: 0)
new(pact: pact, transport: TRANSPORT_HTTP, host: host, port: port)
end
|
.create_for_transport!(pact:, transport:, host: "127.0.0.1", port: 0) ⇒ Object
42
43
44
|
# File 'lib/pact/v2/consumer/mock_server.rb', line 42
def self.create_for_transport!(pact:, transport:, host: "127.0.0.1", port: 0)
new(pact: pact, transport: transport, host: host, port: port)
end
|
Instance Method Details
#cleanup ⇒ Object
83
84
85
|
# File 'lib/pact/v2/consumer/mock_server.rb', line 83
def cleanup
PactFfi::MockServer.cleanup(@handle)
end
|
#cleanup_plugins ⇒ Object
87
88
89
|
# File 'lib/pact/v2/consumer/mock_server.rb', line 87
def cleanup_plugins
PactFfi::PluginConsumer.cleanup_plugins(@handle)
end
|
#free_pact_handle ⇒ Object
91
92
93
|
# File 'lib/pact/v2/consumer/mock_server.rb', line 91
def free_pact_handle
PactFfi.free_pact_handle(@handle)
end
|
#matched? ⇒ Boolean
75
76
77
|
# File 'lib/pact/v2/consumer/mock_server.rb', line 75
def matched?
PactFfi::MockServer.matched(@handle)
end
|
#mismatches ⇒ Object
79
80
81
|
# File 'lib/pact/v2/consumer/mock_server.rb', line 79
def mismatches
PactFfi::MockServer.mismatches(@handle)
end
|
#write_pacts!(dir) ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/pact/v2/consumer/mock_server.rb', line 67
def write_pacts!(dir)
result = PactFfi::MockServer.write_pact_file(@handle, dir, false)
return result if WRITE_PACT_FILE_ERRORS[result].blank?
error = WRITE_PACT_FILE_ERRORS[result]
raise WritePactsError.new("There was an error while trying to write pact file to #{dir}", error[:reason], error[:status])
end
|