From b6d196a4448b4e1c8d38881d3e57ddfe641c9dd2 Mon Sep 17 00:00:00 2001 From: Stanley Phu Date: Mon, 15 Jul 2024 13:15:16 -0700 Subject: [PATCH] Remove single check method and rename CheckMany to Check --- pkg/fga/client.go | 21 +-------------------- pkg/fga/client_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/pkg/fga/client.go b/pkg/fga/client.go index dd1e8bdf..6dfcb223 100644 --- a/pkg/fga/client.go +++ b/pkg/fga/client.go @@ -291,17 +291,6 @@ type WarrantCheck struct { } type CheckOpts struct { - // Warrant to check - Warrant WarrantCheck `json:"warrant_check"` - - // Flag to include debug information in the response. - Debug bool `json:"debug,omitempty"` - - // Optional token to specify desired read consistency - WarrantToken string `json:"-"` -} - -type CheckManyOpts struct { // The operator to use for the given warrants. Op string `json:"op,omitempty"` @@ -783,14 +772,6 @@ func (c *Client) BatchWriteWarrants(ctx context.Context, opts []WriteWarrantOpts } func (c *Client) Check(ctx context.Context, opts CheckOpts) (CheckResponse, error) { - return c.CheckMany(ctx, CheckManyOpts{ - Checks: []WarrantCheck{opts.Warrant}, - Debug: opts.Debug, - WarrantToken: opts.WarrantToken, - }) -} - -func (c *Client) CheckMany(ctx context.Context, opts CheckManyOpts) (CheckResponse, error) { c.once.Do(c.init) data, err := c.JSONEncode(opts) @@ -835,7 +816,7 @@ func (c *Client) CheckMany(ctx context.Context, opts CheckManyOpts) (CheckRespon func (c *Client) CheckBatch(ctx context.Context, opts CheckBatchOpts) ([]CheckResponse, error) { c.once.Do(c.init) - checkOpts := CheckManyOpts{ + checkOpts := CheckOpts{ Op: "batch", Checks: opts.Warrants, Debug: opts.Debug, diff --git a/pkg/fga/client_test.go b/pkg/fga/client_test.go index 0fcffa49..7f509db5 100644 --- a/pkg/fga/client_test.go +++ b/pkg/fga/client_test.go @@ -1012,11 +1012,11 @@ func writeWarrantTestHandler(w http.ResponseWriter, r *http.Request) { w.Write(body) } -func TestCheckMany(t *testing.T) { +func TestCheck(t *testing.T) { tests := []struct { scenario string client *Client - options CheckManyOpts + options CheckOpts expected CheckResponse err bool }{ @@ -1030,7 +1030,7 @@ func TestCheckMany(t *testing.T) { client: &Client{ APIKey: "test", }, - options: CheckManyOpts{ + options: CheckOpts{ Checks: []WarrantCheck{ { ObjectType: "report", @@ -1053,14 +1053,14 @@ func TestCheckMany(t *testing.T) { for _, test := range tests { t.Run(test.scenario, func(t *testing.T) { - server := httptest.NewServer(http.HandlerFunc(checkManyTestHandler)) + server := httptest.NewServer(http.HandlerFunc(checkTestHandler)) defer server.Close() client := test.client client.Endpoint = server.URL client.HTTPClient = server.Client() - checkResult, err := client.CheckMany(context.Background(), test.options) + checkResult, err := client.Check(context.Background(), test.options) if test.err { require.Error(t, err) return @@ -1071,7 +1071,7 @@ func TestCheckMany(t *testing.T) { } } -func checkManyTestHandler(w http.ResponseWriter, r *http.Request) { +func checkTestHandler(w http.ResponseWriter, r *http.Request) { auth := r.Header.Get("Authorization") if auth != "Bearer test" { http.Error(w, "bad auth", http.StatusUnauthorized)