Skip to content

Commit

Permalink
feat: add binding testing and multiple bindings test data to complian…
Browse files Browse the repository at this point in the history
…ce service (#1150)
  • Loading branch information
viacheslav-rostovtsev committed Jul 27, 2022
1 parent e78e58e commit 9d43ed0
Show file tree
Hide file tree
Showing 27 changed files with 728 additions and 294 deletions.
15 changes: 15 additions & 0 deletions client/compliance_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions cmd/gapic-showcase/compliance_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ func prepRepeatDataPathResourceTest(request *genproto.RepeatRequest) (verb strin
name = "Compliance.RepeatDataPathResource"
info := request.GetInfo()

if strings.HasPrefix(info.GetFString(), "first/") {
return prepRepeatDataPathResourceTestFirstBinding(request)
} else {
return prepRepeatDataPathResourceTestSecondBinding(request)
}
}

func prepRepeatDataPathResourceTestFirstBinding(request *genproto.RepeatRequest) (verb string, name string, path string, body string, err error) {
name = "Compliance.RepeatDataPathResource"
info := request.GetInfo()
pathParts := []string{}
nonQueryParamNames := map[string]bool{}

Expand All @@ -243,6 +253,35 @@ func prepRepeatDataPathResourceTest(request *genproto.RepeatRequest) (verb strin
return "GET", name, path + queryString, body, err
}

func prepRepeatDataPathResourceTestSecondBinding(request *genproto.RepeatRequest) (verb string, name string, path string, body string, err error) {
name = "Compliance.RepeatDataPathResource"
info := request.GetInfo()
pathParts := []string{}
nonQueryParamNames := map[string]bool{}

for _, part := range []struct {
name string
format string
value interface{}
requiredPrefix string
}{
{"f_child.f_string", "%s", info.GetFChild().GetFString(), "first/"},
{"f_string", "%s", info.GetFString(), "second/"},
{"f_bool", "bool/%t", info.GetFBool(), ""},
} {
if len(part.requiredPrefix) > 0 && !strings.HasPrefix(part.value.(string), part.requiredPrefix) {
err = fmt.Errorf("expected value of %q to begin with %q; got %q", part.name, part.requiredPrefix, part.value)
return
}
pathParts = append(pathParts, url.PathEscape(fmt.Sprintf(part.format, part.value)))
nonQueryParamNames["info."+part.name] = true
}
path = fmt.Sprintf("/v1beta1/repeat/%s:childfirstpathresource", strings.Join(pathParts, "/"))

queryString := prepRepeatDataTestsQueryString(request, nonQueryParamNames)
return "GET", name, path + queryString, body, err
}

func prepRepeatDataPathTrailingResourceTest(request *genproto.RepeatRequest) (verb string, name string, path string, body string, err error) {
name = "Compliance.RepeatDataPathTrailingResource"
info := request.GetInfo()
Expand Down Expand Up @@ -294,6 +333,7 @@ func prepRepeatDataTestsQueryParams(request *genproto.RepeatRequest, exclude map
// Top-level fields
addParam("server_verify", request.GetServerVerify(), "true")
addParam("name", len(request.GetName()) > 0, url.QueryEscape(request.GetName()))
addParam("intended_binding_uri", request.IntendedBindingUri != nil, url.QueryEscape(request.GetIntendedBindingUri()))

addParam("f_int32", request.GetFInt32() != 0, fmt.Sprintf("%d", request.GetFInt32()))
addParam("f_int64", request.GetFInt64() != 0, fmt.Sprintf("%d", request.GetFInt64()))
Expand Down
11 changes: 6 additions & 5 deletions cmd/gapic-showcase/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ func TestRESTCalls(t *testing.T) {
verb: "POST",
path: "/v1beta1/repeat:body",
body: `{"info":{"fString":"jonas^ mila"}}`,
want: `{"request":{"info":{"fString":"jonas^ mila"}}}`,
want: `{"request":{"info":{"fString":"jonas^ mila"}}, "bindingUri":"/v1beta1/repeat:body"}`,
},
{
verb: "GET",
path: "/v1beta1/repeat:query?info.fString=jonas+mila",
want: `{"request":{"info":{"fString":"jonas mila"}}}`,
want: `{"request":{"info":{"fString":"jonas mila"}}, "bindingUri":"/v1beta1/repeat:query"}`,
},
{
verb: "GET",
path: "/v1beta1/repeat:query?info.fString=jonas^mila",

// TODO: Fix so that this returns an error, because `^` is not URL-escaped
statusCode: 200,
want: `{"request":{"info":{"fString":"jonas^mila"}}}`,
want: `{"request":{"info":{"fString":"jonas^mila"}}, "bindingUri":"/v1beta1/repeat:query"}`,
},
{
verb: "GET",
Expand Down Expand Up @@ -127,7 +127,8 @@ func TestRESTCalls(t *testing.T) {
"fInt32": 0,
"fInt64": "0",
"fDouble": 0
}
},
"bindingUri":"/v1beta1/repeat:body"
}
`,
},
Expand Down Expand Up @@ -174,7 +175,7 @@ func TestRESTCalls(t *testing.T) {
log.Fatal(err)
}
if got, want := string(body), testCase.want; noSpace(got) != noSpace(want) {
t.Errorf("testcase %2d: body: got `%s`, want %s", idx, got, want)
t.Errorf("testcase %2d: body: got %q, want %q", idx, noSpace(got), noSpace(want))
t.Errorf(" request: %v", request)
}
jsonOptions.Restore()
Expand Down
8 changes: 8 additions & 0 deletions cmd/gapic-showcase/repeat-data-body-info.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ var repeatDataBodyInfoInputInfoPChildPBool bool

var RepeatDataBodyInfoInputInfoPChildPContinent string

var repeatDataBodyInfoInputIntendedBindingUri string

var repeatDataBodyInfoInputPInt32 int32

var repeatDataBodyInfoInputPInt64 int64
Expand Down Expand Up @@ -189,6 +191,8 @@ func init() {

RepeatDataBodyInfoCmd.Flags().BoolVar(&RepeatDataBodyInfoInput.ServerVerify, "server_verify", false, "If true, the server will verify that the received...")

RepeatDataBodyInfoCmd.Flags().StringVar(&repeatDataBodyInfoInputIntendedBindingUri, "intended_binding_uri", "", "The URI template this request is expected to be...")

RepeatDataBodyInfoCmd.Flags().Int32Var(&RepeatDataBodyInfoInput.FInt32, "f_int32", 0, "Some top level fields, to test that these are...")

RepeatDataBodyInfoCmd.Flags().Int64Var(&RepeatDataBodyInfoInput.FInt64, "f_int64", 0, "")
Expand Down Expand Up @@ -296,6 +300,10 @@ var RepeatDataBodyInfoCmd = &cobra.Command{
RepeatDataBodyInfoInput.Info.PChild.PBool = &repeatDataBodyInfoInputInfoPChildPBool
}

if cmd.Flags().Changed("intended_binding_uri") {
RepeatDataBodyInfoInput.IntendedBindingUri = &repeatDataBodyInfoInputIntendedBindingUri
}

if cmd.Flags().Changed("p_int32") {
RepeatDataBodyInfoInput.PInt32 = &repeatDataBodyInfoInputPInt32
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/gapic-showcase/repeat-data-body-patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ var repeatDataBodyPatchInputInfoPChildPBool bool

var RepeatDataBodyPatchInputInfoPChildPContinent string

var repeatDataBodyPatchInputIntendedBindingUri string

var repeatDataBodyPatchInputPInt32 int32

var repeatDataBodyPatchInputPInt64 int64
Expand Down Expand Up @@ -189,6 +191,8 @@ func init() {

RepeatDataBodyPatchCmd.Flags().BoolVar(&RepeatDataBodyPatchInput.ServerVerify, "server_verify", false, "If true, the server will verify that the received...")

RepeatDataBodyPatchCmd.Flags().StringVar(&repeatDataBodyPatchInputIntendedBindingUri, "intended_binding_uri", "", "The URI template this request is expected to be...")

RepeatDataBodyPatchCmd.Flags().Int32Var(&RepeatDataBodyPatchInput.FInt32, "f_int32", 0, "Some top level fields, to test that these are...")

RepeatDataBodyPatchCmd.Flags().Int64Var(&RepeatDataBodyPatchInput.FInt64, "f_int64", 0, "")
Expand Down Expand Up @@ -296,6 +300,10 @@ var RepeatDataBodyPatchCmd = &cobra.Command{
RepeatDataBodyPatchInput.Info.PChild.PBool = &repeatDataBodyPatchInputInfoPChildPBool
}

if cmd.Flags().Changed("intended_binding_uri") {
RepeatDataBodyPatchInput.IntendedBindingUri = &repeatDataBodyPatchInputIntendedBindingUri
}

if cmd.Flags().Changed("p_int32") {
RepeatDataBodyPatchInput.PInt32 = &repeatDataBodyPatchInputPInt32
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/gapic-showcase/repeat-data-body-put.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ var repeatDataBodyPutInputInfoPChildPBool bool

var RepeatDataBodyPutInputInfoPChildPContinent string

var repeatDataBodyPutInputIntendedBindingUri string

var repeatDataBodyPutInputPInt32 int32

var repeatDataBodyPutInputPInt64 int64
Expand Down Expand Up @@ -189,6 +191,8 @@ func init() {

RepeatDataBodyPutCmd.Flags().BoolVar(&RepeatDataBodyPutInput.ServerVerify, "server_verify", false, "If true, the server will verify that the received...")

RepeatDataBodyPutCmd.Flags().StringVar(&repeatDataBodyPutInputIntendedBindingUri, "intended_binding_uri", "", "The URI template this request is expected to be...")

RepeatDataBodyPutCmd.Flags().Int32Var(&RepeatDataBodyPutInput.FInt32, "f_int32", 0, "Some top level fields, to test that these are...")

RepeatDataBodyPutCmd.Flags().Int64Var(&RepeatDataBodyPutInput.FInt64, "f_int64", 0, "")
Expand Down Expand Up @@ -296,6 +300,10 @@ var RepeatDataBodyPutCmd = &cobra.Command{
RepeatDataBodyPutInput.Info.PChild.PBool = &repeatDataBodyPutInputInfoPChildPBool
}

if cmd.Flags().Changed("intended_binding_uri") {
RepeatDataBodyPutInput.IntendedBindingUri = &repeatDataBodyPutInputIntendedBindingUri
}

if cmd.Flags().Changed("p_int32") {
RepeatDataBodyPutInput.PInt32 = &repeatDataBodyPutInputPInt32
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/gapic-showcase/repeat-data-body.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ var repeatDataBodyInputInfoPChildPBool bool

var RepeatDataBodyInputInfoPChildPContinent string

var repeatDataBodyInputIntendedBindingUri string

var repeatDataBodyInputPInt32 int32

var repeatDataBodyInputPInt64 int64
Expand Down Expand Up @@ -189,6 +191,8 @@ func init() {

RepeatDataBodyCmd.Flags().BoolVar(&RepeatDataBodyInput.ServerVerify, "server_verify", false, "If true, the server will verify that the received...")

RepeatDataBodyCmd.Flags().StringVar(&repeatDataBodyInputIntendedBindingUri, "intended_binding_uri", "", "The URI template this request is expected to be...")

RepeatDataBodyCmd.Flags().Int32Var(&RepeatDataBodyInput.FInt32, "f_int32", 0, "Some top level fields, to test that these are...")

RepeatDataBodyCmd.Flags().Int64Var(&RepeatDataBodyInput.FInt64, "f_int64", 0, "")
Expand Down Expand Up @@ -296,6 +300,10 @@ var RepeatDataBodyCmd = &cobra.Command{
RepeatDataBodyInput.Info.PChild.PBool = &repeatDataBodyInputInfoPChildPBool
}

if cmd.Flags().Changed("intended_binding_uri") {
RepeatDataBodyInput.IntendedBindingUri = &repeatDataBodyInputIntendedBindingUri
}

if cmd.Flags().Changed("p_int32") {
RepeatDataBodyInput.PInt32 = &repeatDataBodyInputPInt32
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/gapic-showcase/repeat-data-path-resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ var repeatDataPathResourceInputInfoPChildPBool bool

var RepeatDataPathResourceInputInfoPChildPContinent string

var repeatDataPathResourceInputIntendedBindingUri string

var repeatDataPathResourceInputPInt32 int32

var repeatDataPathResourceInputPInt64 int64
Expand Down Expand Up @@ -189,6 +191,8 @@ func init() {

RepeatDataPathResourceCmd.Flags().BoolVar(&RepeatDataPathResourceInput.ServerVerify, "server_verify", false, "If true, the server will verify that the received...")

RepeatDataPathResourceCmd.Flags().StringVar(&repeatDataPathResourceInputIntendedBindingUri, "intended_binding_uri", "", "The URI template this request is expected to be...")

RepeatDataPathResourceCmd.Flags().Int32Var(&RepeatDataPathResourceInput.FInt32, "f_int32", 0, "Some top level fields, to test that these are...")

RepeatDataPathResourceCmd.Flags().Int64Var(&RepeatDataPathResourceInput.FInt64, "f_int64", 0, "")
Expand Down Expand Up @@ -296,6 +300,10 @@ var RepeatDataPathResourceCmd = &cobra.Command{
RepeatDataPathResourceInput.Info.PChild.PBool = &repeatDataPathResourceInputInfoPChildPBool
}

if cmd.Flags().Changed("intended_binding_uri") {
RepeatDataPathResourceInput.IntendedBindingUri = &repeatDataPathResourceInputIntendedBindingUri
}

if cmd.Flags().Changed("p_int32") {
RepeatDataPathResourceInput.PInt32 = &repeatDataPathResourceInputPInt32
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/gapic-showcase/repeat-data-path-trailing-resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ var repeatDataPathTrailingResourceInputInfoPChildPBool bool

var RepeatDataPathTrailingResourceInputInfoPChildPContinent string

var repeatDataPathTrailingResourceInputIntendedBindingUri string

var repeatDataPathTrailingResourceInputPInt32 int32

var repeatDataPathTrailingResourceInputPInt64 int64
Expand Down Expand Up @@ -189,6 +191,8 @@ func init() {

RepeatDataPathTrailingResourceCmd.Flags().BoolVar(&RepeatDataPathTrailingResourceInput.ServerVerify, "server_verify", false, "If true, the server will verify that the received...")

RepeatDataPathTrailingResourceCmd.Flags().StringVar(&repeatDataPathTrailingResourceInputIntendedBindingUri, "intended_binding_uri", "", "The URI template this request is expected to be...")

RepeatDataPathTrailingResourceCmd.Flags().Int32Var(&RepeatDataPathTrailingResourceInput.FInt32, "f_int32", 0, "Some top level fields, to test that these are...")

RepeatDataPathTrailingResourceCmd.Flags().Int64Var(&RepeatDataPathTrailingResourceInput.FInt64, "f_int64", 0, "")
Expand Down Expand Up @@ -296,6 +300,10 @@ var RepeatDataPathTrailingResourceCmd = &cobra.Command{
RepeatDataPathTrailingResourceInput.Info.PChild.PBool = &repeatDataPathTrailingResourceInputInfoPChildPBool
}

if cmd.Flags().Changed("intended_binding_uri") {
RepeatDataPathTrailingResourceInput.IntendedBindingUri = &repeatDataPathTrailingResourceInputIntendedBindingUri
}

if cmd.Flags().Changed("p_int32") {
RepeatDataPathTrailingResourceInput.PInt32 = &repeatDataPathTrailingResourceInputPInt32
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/gapic-showcase/repeat-data-query.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ var repeatDataQueryInputInfoPChildPBool bool

var RepeatDataQueryInputInfoPChildPContinent string

var repeatDataQueryInputIntendedBindingUri string

var repeatDataQueryInputPInt32 int32

var repeatDataQueryInputPInt64 int64
Expand Down Expand Up @@ -189,6 +191,8 @@ func init() {

RepeatDataQueryCmd.Flags().BoolVar(&RepeatDataQueryInput.ServerVerify, "server_verify", false, "If true, the server will verify that the received...")

RepeatDataQueryCmd.Flags().StringVar(&repeatDataQueryInputIntendedBindingUri, "intended_binding_uri", "", "The URI template this request is expected to be...")

RepeatDataQueryCmd.Flags().Int32Var(&RepeatDataQueryInput.FInt32, "f_int32", 0, "Some top level fields, to test that these are...")

RepeatDataQueryCmd.Flags().Int64Var(&RepeatDataQueryInput.FInt64, "f_int64", 0, "")
Expand Down Expand Up @@ -296,6 +300,10 @@ var RepeatDataQueryCmd = &cobra.Command{
RepeatDataQueryInput.Info.PChild.PBool = &repeatDataQueryInputInfoPChildPBool
}

if cmd.Flags().Changed("intended_binding_uri") {
RepeatDataQueryInput.IntendedBindingUri = &repeatDataQueryInputIntendedBindingUri
}

if cmd.Flags().Changed("p_int32") {
RepeatDataQueryInput.PInt32 = &repeatDataQueryInputPInt32
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/gapic-showcase/repeat-data-simple-path.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ var repeatDataSimplePathInputInfoPChildPBool bool

var RepeatDataSimplePathInputInfoPChildPContinent string

var repeatDataSimplePathInputIntendedBindingUri string

var repeatDataSimplePathInputPInt32 int32

var repeatDataSimplePathInputPInt64 int64
Expand Down Expand Up @@ -189,6 +191,8 @@ func init() {

RepeatDataSimplePathCmd.Flags().BoolVar(&RepeatDataSimplePathInput.ServerVerify, "server_verify", false, "If true, the server will verify that the received...")

RepeatDataSimplePathCmd.Flags().StringVar(&repeatDataSimplePathInputIntendedBindingUri, "intended_binding_uri", "", "The URI template this request is expected to be...")

RepeatDataSimplePathCmd.Flags().Int32Var(&RepeatDataSimplePathInput.FInt32, "f_int32", 0, "Some top level fields, to test that these are...")

RepeatDataSimplePathCmd.Flags().Int64Var(&RepeatDataSimplePathInput.FInt64, "f_int64", 0, "")
Expand Down Expand Up @@ -296,6 +300,10 @@ var RepeatDataSimplePathCmd = &cobra.Command{
RepeatDataSimplePathInput.Info.PChild.PBool = &repeatDataSimplePathInputInfoPChildPBool
}

if cmd.Flags().Changed("intended_binding_uri") {
RepeatDataSimplePathInput.IntendedBindingUri = &repeatDataSimplePathInputIntendedBindingUri
}

if cmd.Flags().Changed("p_int32") {
RepeatDataSimplePathInput.PInt32 = &repeatDataSimplePathInputPInt32
}
Expand Down
Loading

0 comments on commit 9d43ed0

Please sign in to comment.