Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject router function #5

Merged
merged 16 commits into from
Jan 29, 2019

Conversation

sachaos
Copy link
Contributor

@sachaos sachaos commented Jan 25, 2019

Resolve #4

routerFunc を指定する事によって、テストする router を YAML から指定できるようにする。

  • routerFunc の signature は func () http.Handler である必要がある (validate している)
  • routerFunc では相対パス、絶対パスで package を指定できる。相対パスの場合 template dir が基準となる。

絶対パスでの指定

- name: TestGetPerson
  routerFunc: github.com/aktsk/atgen/example.getRouter
  apiVersions:
    - v1
  tests:
    - path: /{apiVersion}/people/1
      method: get
      res:
        status: 200
        params:
          id: "1"
          firstname: John
          lastname: Doe

相対パスでの指定

- name: TestDummyRouter
  routerFunc: ../handlers.DummyRouter
  apiVersions:
    - v1
  tests:
    - path: /{apiVersion/}
      method: get
      res:
        status: 200

@sachaos sachaos requested a review from mizzy January 25, 2019 04:41
@mizzy
Copy link
Contributor

mizzy commented Jan 25, 2019

ありがとうございます!

試しにexampleを動かしてみたらエラーになりました。

$ cd example
$ go build ..
$ ./atgen gen --templateDir=./template
$ go test 
# github.com/aktsk/atgen/example [github.com/aktsk/atgen/example.test]
./v1_main_test.go:304:7: undefined: github
./v1_main_test.go:304:18: undefined: aktsk
./v1_main_test.go:304:24: undefined: atgen
./v1_main_test.go:304:30: undefined: example
FAIL    github.com/aktsk/atgen/example [build failed]
exit 2

該当行はこうなっていました。

	r := github.com/aktsk/atgen/example/handlers.DummyRouter()

以下のようになるのが正しいですかね?

	r := handlers.DummyRouter()

@sachaos
Copy link
Contributor Author

sachaos commented Jan 29, 2019

試しにexampleを動かしてみたらエラーになりました。

すみません リファクタリングの際に確認が漏れていたようです。

3e082e4
こちらで修正し、ひとまず以下で example のテストが通ることは確認できました。

$ go install && (cd example && atgen gen -t template) && go test ./example

@mizzy
Copy link
Contributor

mizzy commented Jan 29, 2019

exampleが動作することを確認しました!ご対応ありがとうございます〜。
マージしますね。

@mizzy mizzy merged commit 3e639d0 into aktsk:master Jan 29, 2019
@sachaos sachaos deleted the feature/specify-router-func-in-yaml branch January 30, 2019 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants