envoy / Ambassador

Super lightweight web framework in Swift based on SWSGI
MIT License
184 stars 46 forks source link

Swift 3+ runForever example #17

Open PeaceKeeperOrg opened 7 years ago

PeaceKeeperOrg commented 7 years ago

Do you have an example of running your DefaultHTTPServer asynchronously in the background using Swift 3.0 or greater? I would like to use Ambassador in an XCTest ( i.e. NOT XCUITest) to build a lightweight mock REST server for unit testing an API that I'm building.

Thanks in advance, Rowland

fangpenlin commented 7 years ago

Hi @PeaceKeeperOrg,

You can see our UITestBase example in our blog post

https://envoy.engineering/embedded-web-server-for-ios-ui-testing-8ff3cef513df#.jf4nit18p

You can also see the gist here

https://gist.github.com/fangpenlin/b180cc4a3c7bbe123ee298b03067b6ab

Although it's for UI testing, it won't be any different to just inherit from XCTest instead in your case.

JordiGamez commented 7 years ago

Hi @fangpenlin, I tried to follow those guidelines but I cannot make it work properly.

I have create the files you said in the article but still not working as I expected. I have created the "DefaultRouter" file, UITestBase file and MyUITests file in my UI Test folder. Also I have created an Alamofire requets in my ViewController with is the endpoint I want to mock with Ambassador, but the localhost from Ambassador is always "http://[::1]:8080/api/v2/users" and it never returns the correct information.

What can I do to make it work? Do you have a really working example? Because I never found a real working example mocking an endpoint from a ViewController.

Thanks in advance,

Regards.