surpher / PactSwift

A Swift version of Pact. Implements Pact Specification Version 3.
https://pact.io
MIT License
50 stars 16 forks source link

Unable to run real device -- Pactconsumer #90

Closed vivekthambikannu closed 2 years ago

vivekthambikannu commented 2 years ago

Hi, I am using pact consumer in my project, real time device only able to run my project unable to run in simulator. Initially I use pactswift, after facing this issue i changed pact consumer

my local ip address is = 120.138.12.180, iam getting this error failed - Error setting up pact: The request timed out. failed - Verification error (check build log for mismatches): The request timed out. My code let verificationService = PactVerificationService(url: "http://120.138.12.180/", port: 1234) mockService = MockService(provider: "Provider", consumer: "iOS", pactVerificationService: verificationService)

func testConsumerMaintenance() {
    let apiService = ApiService()
    let urL = mockService.baseUrl
    print("localUrl",urL)
    guard let url = URL(string: "\(urL)/banner") else {
        XCTFail("Failed to prepare url!")
        return
    }
    mockService.given("an alligator exists")
                      .uponReceiving("a request for all alligators")
                      .withRequest(method:.GET, path: "/banner",headers: ["Authorization": "Bearer a.b.c"])
                      .willRespondWith(status: 200,
                                       body: userResponse)

    //Run the tests
    mockService.run(timeout: 10000) { (testComplete) -> Void in
        apiService.apiPostMethod(url: url, withHttpMethod: .GET) { (alligators) in
            XCTAssertNotNil(alligators)
            XCTAssertEqual(2, alligators?.data?[0].id)
          testComplete()
        }
      }
    }
surpher commented 2 years ago

Wrong framework. If you're using pact-consumer-swift then you should share the environment set up and what you've tried already here.

PactSwift will not work with an external Pact Mock Service. The PactSwift.MockService.run's completion block will give you the url String to point your API client to.