forked from vibe-d/vibe.d
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REST: Adding an unittest for issue vibe-d#1125
- Loading branch information
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1125 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "1125", | ||
"dependencies": { | ||
"vibe-d": { "path": "../../../" } | ||
}, | ||
"versions": ["VibeDefaultMain"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import vibe.d; | ||
import std.datetime; | ||
|
||
shared static this() | ||
{ | ||
auto settings = new HTTPServerSettings; | ||
// 10k + issue number -> Avoid bind errors | ||
settings.port = 11125; | ||
settings.bindAddresses = ["::1", "127.0.0.1"]; | ||
auto router = new URLRouter; | ||
router.registerRestInterface(new Llama); | ||
listenHTTP(settings, router); | ||
|
||
// Client | ||
setTimer(1.seconds, { | ||
scope(exit) exitEventLoop(true); | ||
|
||
auto api = new RestInterfaceClient!ILlama("http://127.0.0.1:11125/"); | ||
auto r = api.updateLlama("llama"); | ||
assert(r == "llama", "[vibe.web.rest.1125.Client] Expected llama, got: " ~ r); | ||
}); | ||
} | ||
|
||
interface ILlama { | ||
@bodyParam("llama", "llama") | ||
string updateLlama(string llama = null); | ||
} | ||
|
||
class Llama : ILlama { | ||
string updateLlama(string llama) { | ||
assert(llama == "llama", "[vibe.web.rest.1125.Server] Expected llama, got: " ~ llama); | ||
return llama; | ||
} | ||
} |