redstone-dart / redstone

A metadata driven microframework for Dart.
http://redstone-dart.github.io/redstone
MIT License
342 stars 42 forks source link

Cannot get MockRequest running #198

Closed EasonPai closed 6 years ago

EasonPai commented 6 years ago

I followed wiki and everything is set like:

library system.utils;

@Server.Group("/utils")
class Utils {
    @Server.Route("/echo/get/:input")
    String echoGET(String input) {
        print("echoGET > input: $input");
        return "hi, I get '$input' via GET";
    }
}
import "package:redstone/redstone.dart" as Server;

setUp(() async {
    Server.redstoneSetUp([#system.utils]);
    Server.setupConsoleLog();
    await Server.start(port: 8080);
});

test('echo - mock', () async {
    var complete = expectAsync0(() {});
    new Future.delayed(new Duration(milliseconds: 3000), () {
        //create a mock request
        var req = new Server.MockRequest("/utils/echo/get/test");
        //dispatch the request
        return Server.dispatch(req).then((resp) {
            //verify the response
            print('resp = ${resp}, ${resp.mockContent}');
        });
    });

}); // end

and I get response, and my echoGET is never called,

<head>
  <title>Redstone Server - NOT FOUND</title>
...

I run with environment:

environment: sdk: '>=1.20.1 <2.0.0'

dependencies: redstone: 0.6.8 uuid: 0.5.3 path: 1.4.1 shelf_static: 0.2.4

dev_dependencies: test: ^0.12.0

Can anyone help to find what I missed?

EasonPai commented 6 years ago

Oh no, I figured out that I shouldn't include line:

await Server.start(port: 8080);

so a working setup should be:

setUp(() async {
    Server.redstoneSetUp([#system.utils]);
    Server.setupConsoleLog();
});