-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👸 Add proto file input to jig (#41)
Add proto source file (.proto) input to jig serve and jig bones, so that the user doesn't have to pre-compile FileDescriptorSets. Extend tests run httprule serve via proto files end-to-end. This merges the following commits: * Upgrade to go 1.18 * Narrow up-to-date check to *.pb and go.* files * Read input from --proto flags * Add proto file input to jig bones Makefile | 2 +- bin/{.go-1.17.3.pkg => .go-1.18.pkg} | 0 ...t-1.43.0.pkg => .golangci-lint-1.45.2.pkg} | 0 bin/go | 2 +- bin/gofmt | 2 +- bin/golangci-lint | 2 +- bones/generate.go | 22 +------ bones/generate_test.go | 17 ++++- go.mod | 10 +-- go.sum | 22 ++++--- main.go | 62 ++++++++++++++--- main_test.go | 51 ++++++++++++++ serve/httprule/server.go | 10 +-- serve/httprule/server_test.go | 3 +- serve/server.go | 66 +++++++++++++------ .../httpgreet.HttpGreeter.GetHello.jsonnet | 15 +++++ .../httpgreet.HttpGreeter.PostHello.jsonnet | 15 +++++ ...httpgreet.HttpGreeter.PostHelloURL.jsonnet | 15 +++++ 18 files changed, 241 insertions(+), 75 deletions(-) Pull-Request: #41
- Loading branch information
Showing
18 changed files
with
241 additions
and
75 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
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -1 +1 @@ | ||
.go-1.17.3.pkg | ||
.go-1.18.pkg |
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 |
---|---|---|
@@ -1 +1 @@ | ||
.go-1.17.3.pkg | ||
.go-1.18.pkg |
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 |
---|---|---|
@@ -1 +1 @@ | ||
.golangci-lint-1.43.0.pkg | ||
.golangci-lint-1.45.2.pkg |
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
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
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
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
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
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,51 @@ | ||
package main | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"foxygo.at/jig/log" | ||
"foxygo.at/jig/serve" | ||
"foxygo.at/jig/serve/httprule" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestHTTPRuleServer(t *testing.T) { | ||
c := cmdServe{ | ||
Proto: []string{"httpgreet/httpgreet.proto"}, | ||
ProtoPath: []string{"proto"}, | ||
} | ||
logger := log.NewLogger(io.Discard, log.LogLevelError) | ||
opts, err := c.getServerOptions(logger) | ||
require.NoError(t, err) | ||
|
||
ts := serve.NewUnstartedTestServer(serve.JsonnetEvaluator(), os.DirFS("serve/testdata/httpgreet"), opts...) | ||
ts.SetHTTPHandler(httprule.NewServer(ts.Files, ts.UnknownHandler, logger)) | ||
ts.Start() | ||
defer ts.Stop() | ||
|
||
baseURL := "http://" + ts.Addr() | ||
resp, err := http.Get(baseURL + "/api/greet/hello/Dolly") | ||
require.NoError(t, err) | ||
defer resp.Body.Close() | ||
b, err := io.ReadAll(resp.Body) | ||
require.NoError(t, err) | ||
require.JSONEq(t, `{"greeting":"httpgreet: Hello, Dolly"}`, string(b)) | ||
|
||
resp, err = http.Post(baseURL+"/api/greet/hello", "application/json", strings.NewReader(`{"firstName": "Kitty"}`)) | ||
require.NoError(t, err) | ||
defer resp.Body.Close() | ||
b, err = io.ReadAll(resp.Body) | ||
require.NoError(t, err) | ||
require.JSONEq(t, `{"greeting":"Thanks for the post, Kitty"}`, string(b)) | ||
|
||
resp, err = http.Post(baseURL+"/api/greet/world", "application/json", strings.NewReader(`{}`)) | ||
require.NoError(t, err) | ||
defer resp.Body.Close() | ||
b, err = io.ReadAll(resp.Body) | ||
require.NoError(t, err) | ||
require.JSONEq(t, `{"greeting":"Thanks for the post and the path, world"}`, string(b)) | ||
} |
Oops, something went wrong.